Last active
December 19, 2015 01:48
-
-
Save edjafarov/5878075 to your computer and use it in GitHub Desktop.
mve - rivets + watch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rivets.configure({ | |
| adapter: { | |
| subscribe: function(obj, keypath, callback) { | |
| watch(obj, keypath, callback) | |
| }, | |
| read: function(obj, keypath) { | |
| return obj[keypath] | |
| }, | |
| publish: function(obj, keypath, value) { | |
| obj[keypath] = value | |
| } | |
| } | |
| }) | |
| // LIVE INPUT CUSTOM BINDER | |
| rivets.binders.input = { | |
| bind: function(el) { | |
| el.addEventListener('input', this.publish) | |
| }, | |
| } | |
| // BINDING PLAIN JAVASCRIPT OBJECTS TO THE VIEW | |
| var item = { | |
| title: "Rivets.js + Watch.js!", | |
| text: "change me", | |
| } | |
| var el = document.getElementById('view'); | |
| rivets.bind(el, {item: item}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div id="view"> | |
| <section> | |
| <h1 data-text="item.title"></h1> | |
| <p>Binding text using data-text <code data-text="item.text"></code>.</p> | |
| <p>Text Value: <input data-input="item.text"></p> | |
| </section> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment