[Pkg-javascript-commits] [backbone] 15/34: Adding chain() to the Collection prototype

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:58:53 UTC 2014


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

js pushed a commit to tag 0.2.0
in repository backbone.

commit 8d7eff8cd28d1d5960bfdf4257a6ee0401849414
Author: Nick Fitzgerald <fitzgen at gmail.com>
Date:   Tue Oct 19 12:28:05 2010 -0700

    Adding chain() to the Collection prototype
---
 backbone.js        | 7 +++++++
 test/collection.js | 5 +++++
 2 files changed, 12 insertions(+)

diff --git a/backbone.js b/backbone.js
index 638cc91..d53e3f5 100644
--- a/backbone.js
+++ b/backbone.js
@@ -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;
diff --git a/test/collection.js b/test/collection.js
index de5c974..ae0cd3c 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -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() {

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