Skip to content

Instantly share code, notes, and snippets.

@yocontra
Forked from wulftone/backbone-rivets.config.js
Created February 11, 2013 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yocontra/4752653 to your computer and use it in GitHub Desktop.
Save yocontra/4752653 to your computer and use it in GitHub Desktop.
rivets.configure({
adapter: {
subscribe: function(obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.on('add remove reset', function () {
callback(obj[keypath])
});
} else {
obj.on('change:' + keypath, function (m, v) { callback(v) });
};
},
unsubscribe: function(obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.off('add remove reset', function () {
callback();
});
} else {
obj.off('change:' + keypath, callback);
};
},
read: function(obj, keypath) {
if (obj instanceof Backbone.Collection) {
return obj[keypath];
} else {
return obj.get(keypath);
};
},
publish: function(obj, keypath, value) {
if (obj instanceof Backbone.Collection) {
obj[keypath] = value;
} else {
obj.set(keypath, value);
};
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment