[Pkg-javascript-commits] [backbone] 175/281: Fixes #826 -- expose Backbone.wrapError.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:09 UTC 2014


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

js pushed a commit to tag 0.9.0
in repository backbone.

commit cee62e6541d744628ca74df857a5a1e54ad21608
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Thu Jan 12 16:05:53 2012 -0500

    Fixes #826 -- expose Backbone.wrapError.
---
 backbone.js | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/backbone.js b/backbone.js
index beadedc..6e9099b 100644
--- a/backbone.js
+++ b/backbone.js
@@ -257,7 +257,7 @@
         if (!model.set(model.parse(resp, xhr), options)) return false;
         if (success) success(model, resp);
       };
-      options.error = wrapError(options.error, model, options);
+      options.error = Backbone.wrapError(options.error, model, options);
       return (this.sync || Backbone.sync).call(this, 'read', this, options);
     },
 
@@ -273,7 +273,7 @@
         if (!model.set(model.parse(resp, xhr), options)) return false;
         if (success) success(model, resp, xhr);
       };
-      options.error = wrapError(options.error, model, options);
+      options.error = Backbone.wrapError(options.error, model, options);
       var method = this.isNew() ? 'create' : 'update';
       return (this.sync || Backbone.sync).call(this, method, this, options);
     },
@@ -289,7 +289,7 @@
         model.trigger('destroy', model, model.collection, options);
         if (success) success(model, resp);
       };
-      options.error = wrapError(options.error, model, options);
+      options.error = Backbone.wrapError(options.error, model, options);
       return (this.sync || Backbone.sync).call(this, 'delete', this, options);
     },
 
@@ -523,7 +523,7 @@
         collection[options.add ? 'add' : 'reset'](collection.parse(resp, xhr), options);
         if (success) success(collection, resp);
       };
-      options.error = wrapError(options.error, collection, options);
+      options.error = Backbone.wrapError(options.error, collection, options);
       return (this.sync || Backbone.sync).call(this, 'read', this, options);
     },
 
@@ -1062,6 +1062,18 @@
     return $.ajax(_.extend(params, options));
   };
 
+  // Wrap an optional error callback with a fallback error event.
+  Backbone.wrapError = function(onError, originalModel, options) {
+    return function(model, resp) {
+      var resp = model === originalModel ? resp : model;
+      if (onError) {
+        onError(model, resp, options);
+      } else {
+        originalModel.trigger('error', model, resp, options);
+      }
+    };
+  };
+
   // Helpers
   // -------
 
@@ -1119,16 +1131,4 @@
     throw new Error('A "url" property or function must be specified');
   };
 
-  // Wrap an optional error callback with a fallback error event.
-  var wrapError = function(onError, originalModel, options) {
-    return function(model, resp) {
-      var resp = model === originalModel ? resp : model;
-      if (onError) {
-        onError(model, resp, options);
-      } else {
-        originalModel.trigger('error', model, resp, options);
-      }
-    };
-  };
-
 }).call(this);

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