Skip to content

Instantly share code, notes, and snippets.

@tizmagik
Last active October 10, 2016 00:50
Show Gist options
  • Save tizmagik/3823156 to your computer and use it in GitHub Desktop.
Save tizmagik/3823156 to your computer and use it in GitHub Desktop.
Backbone Collection Updater
Backbone.Collection.prototype.update = function(col_in){
var self = this,
new_models = [];
_(col_in).each(function(mod_in) {
var new_model = self._prepareModel(mod_in),
mod = self.get(new_model.id);
if (mod) {
new_models.push(mod.set(mod_in, {silent:true}));
} else {
new_models.push(mod_in);
}
});
this.reset(new_models);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment