[Pkg-javascript-commits] [backbone] 30/34: Switching from assumed 'model' and 'models' namespacing to an overridable 'parse' method on models and collections.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:58:54 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 a9de05eb44bff05bfb12b59cacb826b2a9f283e3
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Mon Oct 25 10:28:10 2010 -0400

    Switching from assumed 'model' and 'models' namespacing to an overridable 'parse' method on models and collections.
---
 backbone.js | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/backbone.js b/backbone.js
index cc84a9b..0d8871f 100644
--- a/backbone.js
+++ b/backbone.js
@@ -198,7 +198,7 @@
       options || (options = {});
       var model = this;
       var success = function(resp) {
-        if (!model.set(resp.model, options)) return false;
+        if (!model.set(model.parse(resp), options)) return false;
         if (options.success) options.success(model, resp);
       };
       var error = options.error && _.bind(options.error, null, model);
@@ -215,7 +215,7 @@
       if (!this.set(attrs, options)) return false;
       var model = this;
       var success = function(resp) {
-        if (!model.set(resp.model, options)) return false;
+        if (!model.set(model.parse(resp), options)) return false;
         if (options.success) options.success(model, resp);
       };
       var error = options.error && _.bind(options.error, null, model);
@@ -247,6 +247,12 @@
       return base + '/' + this.id;
     },
 
+    // **parse** converts a response into the hash of attributes to be `set` on
+    // the model. The default implementation is just to pass the response along.
+    parse : function(resp) {
+      return resp;
+    },
+
     // Create a new model with identical attributes to this one.
     clone : function() {
       return new this.constructor(this);
@@ -410,7 +416,7 @@
       options || (options = {});
       var collection = this;
       var success = function(resp) {
-        collection.refresh(resp.models);
+        collection.refresh(collection.parse(resp));
         if (options.success) options.success(collection, resp);
       };
       var error = options.error && _.bind(options.error, null, collection);
@@ -431,6 +437,12 @@
       return model.save(null, {success : success, error : options.error});
     },
 
+    // **parse** converts a response into a list of models to be added to the
+    // collection. The default implementation is just to pass it through.
+    parse : function(resp) {
+      return resp;
+    },
+
     // 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.

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