Skip to content

Instantly share code, notes, and snippets.

@edjafarov
Last active December 19, 2015 01:48
Show Gist options
  • Select an option

  • Save edjafarov/5878075 to your computer and use it in GitHub Desktop.

Select an option

Save edjafarov/5878075 to your computer and use it in GitHub Desktop.
mve - rivets + watch
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})
<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