[Pkg-javascript-commits] [backbone] 06/12: All Backbone events now pass through their options as the ffinal argument.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:40 UTC 2014


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

js pushed a commit to tag 0.3.3
in repository backbone.

commit 6e4046df026d44e056af6c5bfa7d7f8b97a56f45
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Tue Nov 30 16:04:55 2010 -0500

    All Backbone events now pass through their options as the ffinal argument.
---
 backbone.js        | 28 ++++++++++++++--------------
 test/collection.js | 12 ++++++++----
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/backbone.js b/backbone.js
index a77ad53..3138191 100644
--- a/backbone.js
+++ b/backbone.js
@@ -180,7 +180,7 @@
           delete escaped[attr];
           if (!options.silent) {
             this._changed = true;
-            this.trigger('change:' + attr, this, val);
+            this.trigger('change:' + attr, this, val, options);
           }
         }
       }
@@ -206,7 +206,7 @@
       delete this._escapedAttributes[attr];
       if (!options.silent) {
         this._changed = true;
-        this.trigger('change:' + attr, this);
+        this.trigger('change:' + attr, this, void 0, options);
         this.change(options);
       }
       return this;
@@ -228,7 +228,7 @@
       if (!options.silent) {
         this._changed = true;
         for (attr in old) {
-          this.trigger('change:' + attr, this);
+          this.trigger('change:' + attr, this, void 0, options);
         }
         this.change(options);
       }
@@ -245,7 +245,7 @@
         if (!model.set(model.parse(resp), options)) return false;
         if (options.success) options.success(model, resp);
       };
-      var error = wrapError(options.error, model);
+      var error = wrapError(options.error, model, options);
       (this.sync || Backbone.sync)('read', this, success, error);
       return this;
     },
@@ -261,7 +261,7 @@
         if (!model.set(model.parse(resp), options)) return false;
         if (options.success) options.success(model, resp);
       };
-      var error = wrapError(options.error, model);
+      var error = wrapError(options.error, model, options);
       var method = this.isNew() ? 'create' : 'update';
       (this.sync || Backbone.sync)(method, this, success, error);
       return this;
@@ -276,7 +276,7 @@
         if (model.collection) model.collection.remove(model);
         if (options.success) options.success(model, resp);
       };
-      var error = wrapError(options.error, model);
+      var error = wrapError(options.error, model, options);
       (this.sync || Backbone.sync)('delete', this, success, error);
       return this;
     },
@@ -361,7 +361,7 @@
         if (options.error) {
           options.error(this, error);
         } else {
-          this.trigger('error', this, error);
+          this.trigger('error', this, error, options);
         }
         return false;
       }
@@ -453,7 +453,7 @@
       options || (options = {});
       if (!this.comparator) throw new Error('Cannot sort a set without a comparator');
       this.models = this.sortBy(this.comparator);
-      if (!options.silent) this.trigger('refresh', this);
+      if (!options.silent) this.trigger('refresh', this, options);
       return this;
     },
 
@@ -470,7 +470,7 @@
       options || (options = {});
       this._reset();
       this.add(models, {silent: true});
-      if (!options.silent) this.trigger('refresh', this);
+      if (!options.silent) this.trigger('refresh', this, options);
       return this;
     },
 
@@ -483,7 +483,7 @@
         collection.refresh(collection.parse(resp));
         if (options.success) options.success(collection, resp);
       };
-      var error = wrapError(options.error, collection);
+      var error = wrapError(options.error, collection, options);
       (this.sync || Backbone.sync)('read', this, success, error);
       return this;
     },
@@ -542,7 +542,7 @@
       this.models.splice(index, 0, model);
       model.bind('all', this._boundOnModelEvent);
       this.length++;
-      if (!options.silent) model.trigger('add', model, this);
+      if (!options.silent) model.trigger('add', model, this, options);
       return model;
     },
 
@@ -557,7 +557,7 @@
       delete model.collection;
       this.models.splice(this.indexOf(model), 1);
       this.length--;
-      if (!options.silent) model.trigger('remove', model, this);
+      if (!options.silent) model.trigger('remove', model, this, options);
       model.unbind('all', this._boundOnModelEvent);
       return model;
     },
@@ -994,12 +994,12 @@
   };
 
   // Wrap an optional error callback with a fallback error event.
-  var wrapError = function(onError, model) {
+  var wrapError = function(onError, model, options) {
     return function(resp) {
       if (onError) {
         onError(model, resp);
       } else {
-        model.trigger('error', model, resp);
+        model.trigger('error', model, resp, options);
       }
     };
   };
diff --git a/test/collection.js b/test/collection.js
index 372e71a..4fccb8d 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -53,13 +53,17 @@ $(document).ready(function() {
   });
 
   test("Collection: add", function() {
-    var added = null;
-    col.bind('add', function(model){ added = model.get('label'); });
+    var added = opts = null;
+    col.bind('add', function(model, collection, options){
+      added = model.get('label');
+      opts = options;
+    });
     e = new Backbone.Model({id: 10, label : 'e'});
-    col.add(e);
+    col.add(e, {amazing: true});
     equals(added, 'e');
     equals(col.length, 5);
     equals(col.last(), e);
+    ok(opts.amazing);
   });
 
   test("Collection: remove", function() {
@@ -70,7 +74,7 @@ $(document).ready(function() {
     equals(col.length, 4);
     equals(col.first(), d);
   });
-  
+
   test("Collection: remove in multiple collections", function() {
     var modelData = {
       id : 5,

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