[Pkg-javascript-commits] [backbone] 104/281: merging in #739 -- a massive simplification.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:01 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 6687cde1969742948523b8f32d67c066b7826d9d
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Wed Nov 23 16:48:39 2011 -0500

    merging in #739 -- a massive simplification.
---
 backbone.js   | 24 ++++++++++++++----------
 test/model.js |  7 ++-----
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/backbone.js b/backbone.js
index 32ef58b..a7398c5 100644
--- a/backbone.js
+++ b/backbone.js
@@ -181,7 +181,15 @@
 
     // Set a hash of model attributes on the object, firing `"change"` unless you
     // choose to silence it.
-    set : function(attrs, options) {
+    set : function(key, value, options) {
+      var attrs;
+      if (_.isObject(key)) {
+        attrs = key;
+        options = value;
+      } else {
+        attrs = {};
+        attrs[key] = value;
+      }
 
       // Extract attributes and options.
       options || (options = {});
@@ -203,7 +211,7 @@
       // Update attributes.
       for (var attr in attrs) {
         var val = attrs[attr];
-        if (!_.isEqual(now[attr], val) || options.unset && (attr in now)) {
+        if (!_.isEqual(now[attr], val) || (options.unset && (attr in now))) {
           options.unset ? delete now[attr] : now[attr] = val;
           delete escaped[attr];
           this._changed = true;
@@ -221,20 +229,16 @@
 
     // Remove an attribute from the model, firing `"change"` unless you choose
     // to silence it. `unset` is a noop if the attribute doesn't exist.
-    unset : function(attrs, options) {
-      if (_.isString(attrs)) {
-        var args = _.toArray(arguments), attrs = {};
-        while (_.isString(options = args.shift())) attrs[options] = void 0;
-      }
+    unset : function(attr, options) {
       (options || (options = {})).unset = true;
-      return this.set(attrs, options);
+      return this.set(attr, null, options);
     },
 
     // Clear all attributes on the model, firing `"change"` unless you choose
     // to silence it.
     clear : function(options) {
-      var keys = _.without(_.keys(this.attributes), 'id');
-      return this.unset.apply(this, keys.concat([options]));
+      (options || (options = {})).unset = true;
+      return this.set(_.clone(this.attributes), options);
     },
 
     // Fetch the model from the server. If the server's representation of the
diff --git a/test/model.js b/test/model.js
index ac1ab0a..b0e0596 100644
--- a/test/model.js
+++ b/test/model.js
@@ -153,9 +153,9 @@ $(document).ready(function() {
     ok(changeCount == 1, "Change count should NOT have incremented.");
 
     a.validate = function(attrs) {
-      ok(attrs.foo === void 0, 'ignore values when unsetting');
+      equals(attrs.foo, void 0, 'ignore values when unsetting');
     };
-    a.unset({foo: 1});
+    a.unset('foo');
     ok(a.get('foo') == null, "Foo should have changed");
     delete a.validate;
     ok(changeCount == 2, "Change count should have incremented for unset.");
@@ -209,13 +209,10 @@ $(document).ready(function() {
     model.bind("change", function() {
       var changedAttrs = model.changedAttributes();
       ok('name' in changedAttrs);
-      ok(!('id' in changedAttrs));
     });
     model.clear();
     equals(changed, true);
     equals(model.get('name'), undefined);
-    equals(model.id, 1);
-    equals(model.get('id'), 1);
   });
 
   test("Model: defaults", function() {

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