Skip to content

Instantly share code, notes, and snippets.

@thegrubbsian
Created June 24, 2011 16:10
Show Gist options
  • Save thegrubbsian/1045107 to your computer and use it in GitHub Desktop.
Save thegrubbsian/1045107 to your computer and use it in GitHub Desktop.
Adding an "update" event to Backbone.Collection instances when a model is saved
Backbone.Model.prototype.save = (function(original) {
return function(attrs, options) {
var me = this;
options = options || {};
var origSuccess = options.success;
var wasNew = this.isNew();
options.success = function(model, response) {
if (me.collection && !wasNew) { me.collection.trigger("update", me); }
if (origSuccess) { origSuccess(model, response); }
};
original.call(this, attrs, options);
};
})(Backbone.Model.prototype.save);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment