From 9f6dc4d575fd7bd85c158528d21c958459ad8530 Mon Sep 17 00:00:00 2001 From: Jeff deBeer Date: Mon, 8 Feb 2016 17:53:27 -0500 Subject: [PATCH 1/4] #3961 Fix and test for issue #3961 - Collection#set - add events sends options.index that correspond to wrong index --- backbone.js | 1 + test/collection.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/backbone.js b/backbone.js index d0cad3eb6..822d3126c 100644 --- a/backbone.js +++ b/backbone.js @@ -1140,6 +1140,7 @@ removed.push(model); this._removeReference(model, options); } + if(models.length > 0 && !options.silent) delete options.index; return removed; }, diff --git a/test/collection.js b/test/collection.js index a0f6bf662..e6d88f51d 100644 --- a/test/collection.js +++ b/test/collection.js @@ -1995,4 +1995,22 @@ assert.equal(fired, false); }); + + QUnit.test("#3961 - aadd events sends options.index that correspond to wrong index", function(assert) { + var numModels = 4; + var models = _.each(['a','b','c','d'], function(val) { + return new Backbone.Model({id:val}); + }); + + var collection = new Backbone.Collection(models); + + models.shift(); // remove first element; + models.push(new Backbone.Model({id:'e'})); + + collection.on('add', function(model, coll, options){ + assert.equal(options.index, undefined); + }); + collection.set(models); + }); + })(); From 4cd41161ca6be3826a9a6bbdbd169da7458011ea Mon Sep 17 00:00:00 2001 From: Jeff deBeer Date: Mon, 8 Feb 2016 18:05:56 -0500 Subject: [PATCH 2/4] #3961 Collection#set - add events sends options.index that Fix and test for issue #3961 - Collection#set - add events sends options.index that correspond to wrong index --- backbone.js | 2 +- test/collection.js | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backbone.js b/backbone.js index 822d3126c..cd376a485 100644 --- a/backbone.js +++ b/backbone.js @@ -1140,7 +1140,7 @@ removed.push(model); this._removeReference(model, options); } - if(models.length > 0 && !options.silent) delete options.index; + if (models.length > 0 && !options.silent) delete options.index; return removed; }, diff --git a/test/collection.js b/test/collection.js index e6d88f51d..9485b797b 100644 --- a/test/collection.js +++ b/test/collection.js @@ -1996,21 +1996,21 @@ }); - QUnit.test("#3961 - aadd events sends options.index that correspond to wrong index", function(assert) { - var numModels = 4; - var models = _.each(['a','b','c','d'], function(val) { - return new Backbone.Model({id:val}); - }); + QUnit.test('#3961 - add events sends options.index that correspond to wrong index', function(assert) { + var numModels = 4; + var models = _.each(['a', 'b', 'c', 'd'], function(val) { + return new Backbone.Model({id:val}); + }); - var collection = new Backbone.Collection(models); + var collection = new Backbone.Collection(models); - models.shift(); // remove first element; - models.push(new Backbone.Model({id:'e'})); + models.shift(); // remove first element; + models.push(new Backbone.Model({id:'e'})); - collection.on('add', function(model, coll, options){ - assert.equal(options.index, undefined); - }); - collection.set(models); + collection.on('add', function(model, coll, options){ + assert.equal(options.index, undefined); + }); + collection.set(models); }); })(); From e81b4ad2eaef05c9d4dd72aecd6f636d542f32af Mon Sep 17 00:00:00 2001 From: Jeff deBeer Date: Mon, 8 Feb 2016 18:14:59 -0500 Subject: [PATCH 3/4] #3961 - add events sends options.index that correspond to wrong index fix and test for #3961 - add events sends options.index that correspond to wrong index --- test/collection.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/collection.js b/test/collection.js index 9485b797b..81c61d7ae 100644 --- a/test/collection.js +++ b/test/collection.js @@ -2001,12 +2001,9 @@ var models = _.each(['a', 'b', 'c', 'd'], function(val) { return new Backbone.Model({id:val}); }); - var collection = new Backbone.Collection(models); - models.shift(); // remove first element; models.push(new Backbone.Model({id:'e'})); - collection.on('add', function(model, coll, options){ assert.equal(options.index, undefined); }); From ffdaa7142aca8a7d9d892e2ec45237a31127ee25 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Tue, 18 Jul 2023 14:44:56 +0200 Subject: [PATCH 4/4] Adress linter warnings (#3964) --- test/collection.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/collection.js b/test/collection.js index 9258a318d..d0890f81f 100644 --- a/test/collection.js +++ b/test/collection.js @@ -2119,11 +2119,11 @@ QUnit.test('#3961 - add events sends options.index that correspond to wrong index', function(assert) { var numModels = 4; var models = _.each(['a', 'b', 'c', 'd'], function(val) { - return new Backbone.Model({id:val}); + return new Backbone.Model({id: val}); }); var collection = new Backbone.Collection(models); models.shift(); // remove first element; - models.push(new Backbone.Model({id:'e'})); + models.push(new Backbone.Model({id: 'e'})); collection.on('add', function(model, coll, options){ assert.equal(options.index, undefined); });