[Pkg-javascript-commits] [backbone] 15/37: refactor `_changed` to prevent confusion

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:02:47 UTC 2014


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

js pushed a commit to tag 0.9.1
in repository backbone.

commit c860070ca306998937247a9c8f22bac1ad30100b
Author: Brad Dunbar <dunbarb2 at gmail.com>
Date:   Wed Feb 1 09:13:31 2012 -0500

    refactor `_changed` to prevent confusion
---
 backbone.js | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/backbone.js b/backbone.js
index d72fa9c..5849d9c 100644
--- a/backbone.js
+++ b/backbone.js
@@ -163,11 +163,10 @@
     this.attributes = {};
     this._escapedAttributes = {};
     this.cid = _.uniqueId('c');
-    this._changed = {};
     if (!this.set(attributes, {silent: true})) {
       throw new Error("Can't create an invalid model");
     }
-    this._changed = {};
+    delete this._changed;
     this._previousAttributes = _.clone(this.attributes);
     this.initialize.apply(this, arguments);
   };
@@ -235,6 +234,7 @@
       var escaped = this._escapedAttributes;
       var prev = this._previousAttributes || {};
       var alreadyChanging = this._changing;
+      this._changed || (this._changed = {});
       this._changing = true;
 
       // Update attributes.
@@ -378,13 +378,13 @@
       }
       this.trigger('change', this, options);
       this._previousAttributes = _.clone(this.attributes);
-      this._changed = {};
+      delete this._changed;
     },
 
     // Determine if the model has changed since the last `"change"` event.
     // If you specify an attribute name, determine if that attribute has changed.
     hasChanged: function(attr) {
-      if (attr) return _.has(this._changed, attr);
+      if (attr) return this._changed && _.has(this._changed, attr);
       return !_.isEmpty(this._changed);
     },
 

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