[Pkg-javascript-commits] [backbone] 73/211: Issue #209 ... unsetting a missing attribute should not fire a change event.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:00:04 UTC 2014


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

js pushed a commit to tag 0.5.0
in repository backbone.

commit b86d3f6afcf9ee203f35daf8a0e618930fb4bdba
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Mon Feb 7 14:16:31 2011 -0500

    Issue #209 ... unsetting a missing attribute should not fire a change event.
---
 backbone.js   |  3 ++-
 test/model.js | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/backbone.js b/backbone.js
index 6ee10c1..3048117 100644
--- a/backbone.js
+++ b/backbone.js
@@ -206,8 +206,9 @@
     },
 
     // Remove an attribute from the model, firing `"change"` unless you choose
-    // to silence it.
+    // to silence it. `unset` is a noop if the attribute doesn't exist.
     unset : function(attr, options) {
+      if (!(attr in this.attributes)) return this;
       options || (options = {});
       var value = this.attributes[attr];
 
diff --git a/test/model.js b/test/model.js
index 649ed67..049db7f 100644
--- a/test/model.js
+++ b/test/model.js
@@ -152,6 +152,17 @@ $(document).ready(function() {
     equals(a.id, undefined, "Unsetting the id should remove the id property.");
   });
 
+  test("Model: multiple unsets", function() {
+    var i = 0;
+    var counter = function(){ i++; };
+    var model = new Backbone.Model({a: 1});
+    model.bind("change:a", counter);
+    model.set({a: 2});
+    model.unset('a');
+    model.unset('a');
+    equals(i, 2, 'Unset does not fire an event for missing attributes.');
+  });
+
   test("Model: using a non-default id attribute.", function() {
     var MongoModel = Backbone.Model.extend({idAttribute : '_id'});
     var model = new MongoModel({id: 'eye-dee', _id: 25, title: 'Model'});

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