Spraypaint the isomorphic, framework-agnostic Graphiti ORM
State Syncing
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 person
.
But if the server returns an updated name
attribute, person.name
will be automatically updated. This is true even if person.name
is bound in 17 different nested components.
Instances can still update their attributes independently - we only sync when the server returns updated data:
Gotchas
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 #unlisten()
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.