[Pkg-javascript-commits] [backbone] 256/281: Fire `'change:attr'` from `change`

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:20 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 0d6e5f39341724ad7f348e272bdf2b1ad64670ca
Author: Brad Dunbar <dunbarb2 at gmail.com>
Date:   Fri Jan 27 14:07:33 2012 -0500

    Fire `'change:attr'` from `change`
---
 backbone.js   | 13 +++++--------
 test/model.js |  7 +++++++
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/backbone.js b/backbone.js
index 80c1fc3..1b01322 100644
--- a/backbone.js
+++ b/backbone.js
@@ -239,23 +239,16 @@
       this._changing = true;
 
       // Update attributes.
-      var changes = {};
       for (attr in attrs) {
         val = attrs[attr];
         if (!_.isEqual(now[attr], val) || (options.unset && (attr in now))) {
           delete escaped[attr];
           this._changed = true;
-          changes[attr] = val;
         }
         options.unset ? delete now[attr] : now[attr] = val;
       }
 
-      // Fire `change:attribute` events.
-      for (var attr in changes) {
-        if (!options.silent) this.trigger('change:' + attr, this, changes[attr], options);
-      }
-
-      // Fire the `"change"` event, if the model has been changed.
+      // Fire the `"change"` events, if the model has been changed.
       if (!alreadyChanging) {
         if (!options.silent && this._changed) this.change(options);
         this._changing = false;
@@ -379,6 +372,10 @@
     // Call this method to manually fire a `change` event for this model.
     // Calling this will cause all objects observing the model to update.
     change: function(options) {
+      var changes = this.changedAttributes();
+      for (var attr in changes) {
+        this.trigger('change:' + attr, this, changes[attr], options);
+      }
       this.trigger('change', this, options);
       this._previousAttributes = _.clone(this.attributes);
       this._changed = false;
diff --git a/test/model.js b/test/model.js
index 66cd729..861ec61 100644
--- a/test/model.js
+++ b/test/model.js
@@ -552,4 +552,11 @@ $(document).ready(function() {
     ok('x' in model.attributes);
   });
 
+  test("change fires change:attr", 1, function() {
+    var model = new Backbone.Model({x: 1});
+    model.set({x: 2}, {silent: true});
+    model.on('change:x', function(){ ok(true); });
+    model.change();
+  });
+
 });

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