[Pkg-javascript-commits] [backbone] 209/281: Fixes #574, clone 'models' before removing, so as to allow collection.remove(collection.models)

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:13 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.9.0
in repository backbone.

commit 7ba0275613f2fabf0f40b96694e54b88de582406
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Tue Jan 17 10:29:01 2012 -0500

    Fixes #574, clone 'models' before removing, so as to allow collection.remove(collection.models)
---
 backbone.js        |  2 +-
 test/collection.js | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/backbone.js b/backbone.js
index db86523..f7d3b8d 100644
--- a/backbone.js
+++ b/backbone.js
@@ -482,7 +482,7 @@
     remove : function(models, options) {
       var i, index, model;
       options || (options = {});
-      if (!_.isArray(models)) models = [models];
+      models = _.isArray(models) ? slice.call(models) : [models];
       for (i = 0, l = models.length; i < l; i++) {
         model = this.getByCid(models[i]) || this.get(models[i]);
         if (!model) continue;
diff --git a/test/collection.js b/test/collection.js
index 691ada1..33e2d76 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -450,7 +450,7 @@ $(document).ready(function() {
     var attrs = {};
     var models = [attrs];
     new Backbone.Collection().add(models);
-    equal(models.length, 1);
+    equals(models.length, 1);
     ok(attrs === models[0]);
   });
 
@@ -466,4 +466,13 @@ $(document).ready(function() {
     col.create({prop: 'value'});
   });
 
+  test("#574, remove its own reference to the .models array.", function() {
+    var col = new Backbone.Collection([
+      {id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}
+    ]);
+    equals(col.length, 6);
+    col.remove(col.models);
+    equals(col.length, 0);
+  });
+
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list