mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-22 21:38:00 -05:00
Adding chain() to the Collection prototype
This commit is contained in:
committed by
Jeremy Ashkenas
parent
c98cfeb4f2
commit
8d7eff8cd2
@@ -425,6 +425,13 @@
|
||||
return model.save(null, {success : success, error : options.error});
|
||||
},
|
||||
|
||||
// Proxy to _'s chain. Can't be proxied the same way the rest of the
|
||||
// underscore methods are proxied because it relies on the underscore
|
||||
// constructor.
|
||||
chain: function () {
|
||||
return _(this.models).chain();
|
||||
},
|
||||
|
||||
// Reset all internal state. Called when the collection is refreshed.
|
||||
_reset : function(options) {
|
||||
this.length = 0;
|
||||
|
||||
@@ -95,6 +95,11 @@ $(document).ready(function() {
|
||||
ok(!_.include(col.without(d)), d);
|
||||
equals(col.max(function(model){ return model.id; }).id, 4);
|
||||
equals(col.min(function(model){ return model.id; }).id, 1);
|
||||
same(col.chain()
|
||||
.filter(function(o){ return o.id % 2 === 0; })
|
||||
.map(function(o){ return o.id * 2; })
|
||||
.value(),
|
||||
[8, 4]);
|
||||
});
|
||||
|
||||
test("Collection: refresh", function() {
|
||||
|
||||
Reference in New Issue
Block a user