Skip to content

Add a "replace" option to Backbone.Model.set #3253

Open
@thesmart

Description

@thesmart

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions