Skip to content

Instantly share code, notes, and snippets.

@lightman76
lightman76 / backbone-rivets.config.js
Last active December 13, 2015 19:49 — forked from wulftone/backbone-rivets.config.js
New to backbone and rivets - but in my initial experiments I noticed problems around collections and models with collection attributes. Think this version of the adapter better handles those than the original. I did see where someone posted that beyond trivial examples one should bind to the collection directly versus handling it directly under …
rivets.configure({
adapter:{
subscribe:function (obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.on('add remove reset', function () {callback(obj);});
} else if(obj.get(keypath) instanceof Backbone.Collection) {
obj.get(keypath).on('add remove reset', function (m,v) {callback(obj.get(keypath));});
} else {
obj.on('change:' + keypath, function (m, v) {callback(v)});
}