jashkenas / jashkenas/backbone

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

Open
#3,253 22 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
28.1k
Forks
5.3k
PR merge metrics
No merged PRs in 30d

Description

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:

``` coffeescript
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`?

Contributor guide

Open the contributing guide

Research direction

Start with Backbone.Model.set and compare the requested behavior with Backbone.Collection.reset. Read the 22-comment discussion to determine whether the API should be a replace option or a Model.reset method, then define the behavior and add coverage showing that views update without recording changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.