[Pkg-javascript-commits] [backbone] 19/173: Add `findIndex` and `findLastIndex` underscore methods to Collection.

Jonas Smedegaard dr at jones.dk
Wed Aug 31 07:43:57 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 6cff9419fb528e7087f241169a9e58d01d22a62b
Author: Jacob Buck <buck.jacob at gmail.com>
Date:   Tue Sep 29 12:25:36 2015 +1300

    Add `findIndex` and `findLastIndex` underscore methods to Collection.
---
 backbone.js        | 2 +-
 test/collection.js | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/backbone.js b/backbone.js
index 1353670..bbc63fd 100644
--- a/backbone.js
+++ b/backbone.js
@@ -1173,7 +1173,7 @@
       head: 3, take: 3, initial: 3, rest: 3, tail: 3, drop: 3, last: 3,
       without: 0, difference: 0, indexOf: 3, shuffle: 1, lastIndexOf: 3,
       isEmpty: 1, chain: 1, sample: 3, partition: 3, groupBy: 3, countBy: 3,
-      sortBy: 3, indexBy: 3};
+      sortBy: 3, indexBy: 3, findIndex: 3, findLastIndex: 3};
 
   // Mix in each Underscore method as a proxy to `Collection#models`.
   addUnderscoreMethods(Collection, collectionMethods, 'models');
diff --git a/test/collection.js b/test/collection.js
index a366ca4..b753e07 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -660,7 +660,7 @@
     ok(col.indexBy('id')[first.id] === first);
   });
 
-  test("Underscore methods with object-style and property-style iteratee", 22, function () {
+  test("Underscore methods with object-style and property-style iteratee", 26, function () {
     var model = new Backbone.Model({a: 4, b: 1, e: 3});
     var coll = new Backbone.Collection([
       {a: 1, b: 1},
@@ -690,6 +690,10 @@
     deepEqual(coll.sortBy('e')[0], model);
     deepEqual(coll.countBy({a: 4}), {'false': 3, 'true': 1});
     deepEqual(coll.countBy('d'), {'undefined': 4});
+    equal(coll.findIndex({b: 1}), 0);
+    equal(coll.findIndex({b: 9}), -1);
+    equal(coll.findLastIndex({b: 1}), 3);
+    equal(coll.findLastIndex({b: 9}), -1);
   });
 
   test("reset", 16, function() {

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