Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Rivetsjs adapter for backbonejs

View backbone-rivets.config.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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);
};
}
}
});

Not sure if obj.off will unbind the callback (line 18), since the second parameter is a newly created function, not the same from line 9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.