Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Spine.js doesn't emit events when you change attributes on the model, it only fires an event when you call <code>save()</code> on the model. It also doesn't perform any sort of dirty tracking, so you don't get <code>update:keypath</code> style events out-of-the-box, it just fires a single <code>update</code> event.</p> <p>Here's a standard adapter for using Spine.js models with Rivets.js.</p> <pre><code>rivets.configure adapter: subscribe: (obj, keypath, callback) -&gt; obj.bind "update", callback unsubscribe: (obj, keypath, callback) -&gt; obj.unbind "update", callback read: (obj, keypath) -&gt; obj[keypath] publish: (obj, keypath, value) -&gt; obj[keypath] = value </code></pre> <p>Using the above adapter, Rivets.js will update the in-memory attributes on your models when going from view-to-model (using a two-way binder such as <code>value</code> or <code>checked</code>) and will update the view (going from model-to-view) only when you call <code>save()</code> on the model. This is just part of how Spine.js events work.</p> <p>Unfortunately the above adapter will update every binding for that model, including bindings for properties that did not change. Alternatively, you can use something like <a href="https://github.com/mitchlloyd/Spine-Attribute-Events" rel="nofollow">Spine-Attribute-Events</a> which does basic dirty tracking and fires an additional <code>update:keypath</code> style event for the attributes that changed. This will be far more performant in terms of DOM operations as we're only updating what needs to be updated.</p> <pre><code>rivets.configure adapter: subscribe: (obj, keypath, callback) -&gt; obj.bind "update:" + keypath, callback unsubscribe: (obj, keypath, callback) -&gt; obj.unbind "update:" + keypath, callback read: (obj, keypath) -&gt; obj[keypath] publish: (obj, keypath, value) -&gt; obj[keypath] = value </code></pre> <p>As you can see, this gives Rivets.js a more granular way to subscribe to individual attribute changes. The basic idea here is that Rivets.js will now update only the parts of the DOM for attributes that have changed.</p> <p>Again all of this happens only when you call <code>save()</code>, which is actually a nice feature because you can make as many intermediate changes to the model as you want, and then call <code>save()</code> at the very end to have those changes reflected in the UI.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload