Skip to content

Commit

Permalink
Support merging of updated object state on collection add.
Browse files Browse the repository at this point in the history
  • Loading branch information
folded committed Apr 13, 2012
1 parent a88efef commit 7dbab65
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@
// Remove duplicates.
i = dups.length;
while (i--) {
models.splice(dups[i], 1);
dups[i] = models.splice(dups[i], 1)[0];
}

// Listen to added models' events, and index models for lookup by
Expand All @@ -630,6 +630,14 @@
options.index = i;
model.trigger('add', model, this, options);
}

if (options.merge) {
for (i = 0, length = dups.length; i < length; i++) {
model = this._byId[dups[i].id] || this._byCid[dups[i].cid];
model.set(dups[i], options);
}
}

return this;
},

Expand Down

0 comments on commit 7dbab65

Please sign in to comment.