mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #1327 from TheBits/silent-merge
Merge model with silent flag
This commit is contained in:
13
backbone.js
13
backbone.js
@@ -613,12 +613,6 @@
|
||||
index = options.at != null ? options.at : this.models.length;
|
||||
splice.apply(this.models, [index, 0].concat(models));
|
||||
if (this.comparator && options.at == null) this.sort({silent: true});
|
||||
if (options.silent) return this;
|
||||
for (i = 0, length = this.models.length; i < length; i++) {
|
||||
if (!cids[(model = this.models[i]).cid]) continue;
|
||||
options.index = i;
|
||||
model.trigger('add', model, this, options);
|
||||
}
|
||||
|
||||
// Merge in duplicate models.
|
||||
if (options.merge) {
|
||||
@@ -629,6 +623,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (options.silent) return this;
|
||||
for (i = 0, length = this.models.length; i < length; i++) {
|
||||
if (!cids[(model = this.models[i]).cid]) continue;
|
||||
options.index = i;
|
||||
model.trigger('add', model, this, options);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
@@ -158,6 +158,8 @@ $(document).ready(function() {
|
||||
equal(col.first().get('name'), 'Moe');
|
||||
col.add({id: 1, name: 'Moses'}, {merge: true});
|
||||
equal(col.first().get('name'), 'Moses');
|
||||
col.add({id: 1, name: 'Tim'}, {merge: true, silent: true});
|
||||
equal(col.first().get('name'), 'Tim');
|
||||
});
|
||||
|
||||
test("Collection: add model to multiple collections", 10, function() {
|
||||
|
||||
Reference in New Issue
Block a user