Skip to content

Instantly share code, notes, and snippets.

@vicneanschi
Created August 4, 2015 15:47
Show Gist options
  • Save vicneanschi/66c90ef1c63fe3d8cce3 to your computer and use it in GitHub Desktop.
Save vicneanschi/66c90ef1c63fe3d8cce3 to your computer and use it in GitHub Desktop.
// Collection save
Backbone.Collection.prototype.save = function (options) {
// create a tmp collection, with the changed models, and the url
var tmpCollection = new Backbone.Collection( this.changed() );
tmpCollection.url = this.url;
// sync
Backbone.sync("create", tmpCollection, options);
};
Backbone.Collection.prototype.changed = function (options) {
// return only the changed models.
return this.models.filter( function(m){
return m.hasChanged()
});
};
// and sync the diffs.
self.userCollection.save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment