Skip to content

Commit

Permalink
Merge pull request #3820 from jridgewell/reduce-deopt
Browse files Browse the repository at this point in the history
Deopt Underscore methods that change on arguments
  • Loading branch information
jridgewell committed Oct 28, 2015
2 parents d1880dd + 7ed8582 commit 569f07e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions backbone.js
Expand Up @@ -1168,8 +1168,8 @@
// Underscore methods that we want to implement on the Collection.
// 90% of the core usefulness of Backbone Collections is actually implemented
// right here:
var collectionMethods = { forEach: 3, each: 3, map: 3, collect: 3, reduce: 4,
foldl: 4, inject: 4, reduceRight: 4, foldr: 4, find: 3, detect: 3, filter: 3,
var collectionMethods = { forEach: 3, each: 3, map: 3, collect: 3, reduce: 0,
foldl: 0, inject: 0, reduceRight: 0, foldr: 0, find: 3, detect: 3, filter: 3,
select: 3, reject: 3, every: 3, all: 3, some: 3, any: 3, include: 3, includes: 3,
contains: 3, invoke: 0, max: 3, min: 3, toArray: 1, size: 1, first: 3,
head: 3, take: 3, initial: 3, rest: 3, tail: 3, drop: 3, last: 3,
Expand Down
4 changes: 3 additions & 1 deletion test/collection.js
Expand Up @@ -672,10 +672,12 @@
});

QUnit.test("Underscore methods", function(assert) {
assert.expect(19);
assert.expect(21);
assert.equal(col.map(function(model){ return model.get('label'); }).join(' '), 'a b c d');
assert.equal(col.some(function(model){ return model.id === 100; }), false);
assert.equal(col.some(function(model){ return model.id === 0; }), true);
assert.equal(col.reduce(function(a, b) {return a.id > b.id ? a : b}).id, 3);
assert.equal(col.reduceRight(function(a, b) {return a.id > b.id ? a : b}).id, 3);
assert.equal(col.indexOf(b), 1);
assert.equal(col.size(), 4);
assert.equal(col.rest().length, 3);
Expand Down

0 comments on commit 569f07e

Please sign in to comment.