[Pkg-javascript-commits] [backbone] 04/15: Allowing collections to remove models by either Cid or Id (prefering cid).
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 16:59:29 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.3.2
in repository backbone.
commit 52c460bc12d2127f1c76d6052b71f7f272acbc82
Author: Samuel Clay <samuel at ofbrooklyn.com>
Date: Wed Nov 17 14:50:39 2010 -0500
Allowing collections to remove models by either Cid or Id (prefering cid).
---
backbone.js | 2 +-
test/collection.js | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/backbone.js b/backbone.js
index 12f8b84..eb758ae 100644
--- a/backbone.js
+++ b/backbone.js
@@ -536,7 +536,7 @@
// hash indexes for `id` and `cid` lookups.
_remove : function(model, options) {
options || (options = {});
- model = this.getByCid(model);
+ model = this.getByCid(model) || this.get(model);
if (!model) return null;
delete this._byId[model.id];
delete this._byCid[model.cid];
diff --git a/test/collection.js b/test/collection.js
index 59d0f22..c08d07a 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -70,6 +70,30 @@ $(document).ready(function() {
equals(col.length, 4);
equals(col.first(), d);
});
+
+ test("Collection: remove in multiple collections", function() {
+ var modelData = {
+ id : 5,
+ title : 'Othello'
+ };
+ var passed = false;
+ var e = new Backbone.Model(modelData);
+ var f = new Backbone.Model(modelData);
+ f.bind('remove', function() {
+ passed = true;
+ });
+ var colE = new Backbone.Collection([e]);
+ var colF = new Backbone.Collection([f]);
+ ok(e != f);
+ ok(colE.length == 1);
+ ok(colF.length == 1);
+ colE.remove(e);
+ equals(passed, false);
+ ok(colE.length == 0);
+ colF.remove(e);
+ ok(colF.length == 0);
+ equals(passed, true);
+ });
test("Collection: fetch", function() {
col.fetch();
--
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