[Pkg-javascript-commits] [backbone] 231/281: setting undefined attributes

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:16 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 3a891854e8e59b4e38d60b21147b0007cdec53a6
Author: Brad Dunbar <dunbarb2 at gmail.com>
Date:   Fri Jan 20 11:02:46 2012 -0500

    setting undefined attributes
    
    * undefined attrs should still be set
    * unset triggers change for undefined attrs
    * values are set regardless of change/equality
---
 backbone.js   |  2 +-
 test/model.js | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/backbone.js b/backbone.js
index 74becaa..5810783 100644
--- a/backbone.js
+++ b/backbone.js
@@ -239,11 +239,11 @@
       for (attr in attrs) {
         val = attrs[attr];
         if (!_.isEqual(now[attr], val) || (options.unset && (attr in now))) {
-          options.unset ? delete now[attr] : now[attr] = val;
           delete escaped[attr];
           this._changed = true;
           changes[attr] = val;
         }
+        options.unset ? delete now[attr] : now[attr] = val;
       }
 
       // Fire `change:attribute` events.
diff --git a/test/model.js b/test/model.js
index 9ad45d2..7d95da2 100644
--- a/test/model.js
+++ b/test/model.js
@@ -537,4 +537,22 @@ $(document).ready(function() {
     ok(model.has('attributes'));
   });
 
+  test("set value regardless of equality/change", function() {
+    var model = new Backbone.Model({x: []});
+    var a = [];
+    model.set({x: a});
+    ok(model.get('x') === a);
+  });
+
+  test("unset fires change for undefined attributes", 1, function() {
+    var model = new Backbone.Model({x: undefined});
+    model.bind('change:x', function(){ ok(true); });
+    model.unset('x');
+  });
+
+  test("set: undefined values", function() {
+    var model = new Backbone.Model({x: undefined});
+    ok('x' in model.attributes);
+  });
+
 });

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