Last active
October 10, 2016 00:50
-
-
Save tizmagik/3823156 to your computer and use it in GitHub Desktop.
Backbone Collection Updater
This file contains 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 characters
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