I needed to update some of a Model's data that came in from the server. Currently, there are two options: call Model.set, or set Model.attributes directly. I didn't want changes to be recorded, but I also couldn't use silent because I needed the respective views to update. So, I wrote a monkey patch:
Backbone.Model.prototype.reset = (attributes, options) ->
attrs = attributes || {};
if options.parse
attrs = this.parse(attrs, options) || {}
@set(attrs, options);
@changed = {};
Wondered why Backbone.Model doesn't have a reset method like Backbone.Collection?
I needed to update some of a Model's data that came in from the server. Currently, there are two options: call
Model.set, or setModel.attributesdirectly. I didn't want changes to be recorded, but I also couldn't usesilentbecause I needed the respective views to update. So, I wrote a monkey patch:Wondered why
Backbone.Modeldoesn't have a reset method likeBackbone.Collection?