[Pkg-javascript-commits] [backbone] 139/173: optimize collection get and account for edge case

Jonas Smedegaard dr at jones.dk
Wed Aug 31 07:44:13 UTC 2016


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

js pushed a commit to branch master
in repository backbone.

commit 8932ae4bc3d9bb98c4cb8819904dd1873b7ec668
Author: Craig Martin <cmartin at onshift.com>
Date:   Sun Jan 24 09:21:15 2016 -0500

    optimize collection get and account for edge case
---
 backbone.js        | 8 +++++---
 test/collection.js | 5 -----
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/backbone.js b/backbone.js
index 7999e98..66aa483 100644
--- a/backbone.js
+++ b/backbone.js
@@ -980,11 +980,13 @@
       return slice.apply(this.models, arguments);
     },
 
-    // Get a model from the set by id.
+    // Get a model from the set by id, cid, model object with id or cid
+    // properties, or an attributes object that is transformed through modelId.
     get: function(obj) {
       if (obj == null) return void 0;
-      var id = this.modelId(this._isModel(obj) ? obj.attributes : obj);
-      return this._byId[obj] || this._byId[id] || this._byId[obj.cid];
+      return this._byId[obj] ||
+        this._byId[this.modelId(obj.attributes || obj)] ||
+        obj.cid && this._byId[obj.cid];
     },
 
     // Returns `true` if the model is in the collection.
diff --git a/test/collection.js b/test/collection.js
index d8591a1..d1f0a95 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -101,11 +101,6 @@
     assert.equal(collection2.get(model.clone()), collection2.first());
   });
 
-  QUnit.test('get with "undefined" id', function(assert) {
-    var collection = new Backbone.Collection([{id: 1}, {id: 'undefined'}]);
-    assert.equal(collection.get(1).id, 1);
-  });
-
   QUnit.test('has', function(assert) {
     assert.expect(15);
     assert.ok(col.has(a));

-- 
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