Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally merging updated model state on collection add. #1220

Merged
merged 1 commit into from
Apr 23, 2012
Merged

Optionally merging updated model state on collection add. #1220

merged 1 commit into from
Apr 23, 2012

Conversation

folded
Copy link
Contributor

@folded folded commented Apr 13, 2012

The current behaviour of Backbone.Collection.add is to discard models that have matching ids. This makes it difficult to fetch and insert a set of models that may contain both new and updated models. Maybe there's a different way to perform this task, but it wasn't obvious to me.

This patch adds a merge flag to Backbone.Collection.add, which causes models with identical ids be passed as arguments to Backbone.Model.set instead of being discarded. In the case of true duplicates, the current behaviour is preserved (no change to the collection, no additional events fired), but updates to models retain the object in the collection, but update its attributes (firing the corresponding change events, unless silent).

jashkenas added a commit that referenced this pull request Apr 23, 2012
Optionally merging updated model state on collection add.
@jashkenas jashkenas merged commit 9ee0358 into jashkenas:master Apr 23, 2012
@jashkenas
Copy link
Owner

Thanks -- lovely implementation.

@halfbaked
Copy link

Nice. Just what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants