Spraypaint the isomorphic, framework-agnostic Graphiti ORM
- State Syncing
- Data Down, Actions Up
You may have encountered state management libraries like Flux, Redux or Vuex. These are fantastic libraries, but their usefulness is lessened with Spraypaint. As a full-fledged model layer, Spraypaint manages state for you, automatically.
If you opt-in to this feature:
Instances will sync up whenever the server tells us about updated state. Consider the scenario where an instance is initially loaded, then separately polled in the background:
Note that our
poll() function never assigns or updates
But if the server returns an updated
will be automatically updated. This is true even if
is bound in 17 different nested components.
Instances can still update their attributes independently - we only sync when the server returns updated data:
Under the hood, instances are listening for updates from a central data store. This means that you’ll want to remove listeners whenever you no longer need the instance - otherwise it will never be garbage collected properly. To remove a listener:
In practice, when developing in a SPA, you’ll want to
whenever a view is destroyed and model instances no longer need to be referenced. If
you are using VueJS, this is done automatically by adding spraypaint-vue
to your application.