Skip to content

Instantly share code, notes, and snippets.

@elentok
Created April 21, 2013 13:29
Show Gist options
  • Select an option

  • Save elentok/5429584 to your computer and use it in GitHub Desktop.

Select an option

Save elentok/5429584 to your computer and use it in GitHub Desktop.
For future reference
//= require components/rivets/lib/rivets
// ----------------------------------
attributes: {},
set: function (key, value) {
if (this.attributes[key] !== value) {
this.attributes[key] = value;
this.events.triggerEvent("change:" + key, {key: key, value: value});
}
},
get: function (key) {
return this.attributes[key];
},
// ----------------------------------
rivets.formatters.t = function(key) {
return I18n.t(key);
};
rivets.configure({
adapter: {
subscribe: function(obj, keypath, callback) {
var events = {};
events['change:' + keypath] = callback;
obj.events.on(events);
},
unsubscribe: function(obj, keypath, callback) {
var events = {};
events['change:' + keypath] = callback;
obj.events.off(events);
},
read: function(obj, keypath) {
return obj.get(keypath);
},
publish: function(obj, keypath, value) {
obj.set(keypath, value);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment