Forked from wulftone/backbone-rivets.config.js
Last active
December 13, 2015 19:49
Revisions
-
lightman76 revised this gist
Feb 16, 2013 . 1 changed file with 42 additions and 36 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,36 +1,42 @@ 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)}); } }, unsubscribe:function (obj, keypath, callback) { if (obj instanceof Backbone.Collection) { obj.off('add remove reset', function () {callback(obj);}); } else if(obj.get(keypath) instanceof Backbone.Collection) { obj.off('add remove reset', function () {callback(obj[keypath]);}); } else { obj.off('change:' + keypath, function (m, v) {callback(v)}); } }, read:function (obj, keypath) { if (obj instanceof Backbone.Collection) { //need to bind to events on the collection as well if we haven't if (keypath == "") return obj.models; return obj[keypath]; } else { var ret = obj.get(keypath); if (ret instanceof Backbone.Collection) { ret = ret.models; } return ret; } }, publish:function (obj, keypath, value) { if (obj instanceof Backbone.Collection) { obj[keypath] = value; } else { obj.set(keypath, value); } } } }); -
wulftone renamed this gist
Feb 11, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
wulftone created this gist
Feb 11, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ 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(obj[keypath]) }); } else { obj.off('change:' + keypath, function (m, v) { callback(v) }); }; }, 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); }; } } });