From bbcf19684c7fb87b78acfbcc33e12217265e08ae Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Fri, 3 Dec 2010 09:54:27 -0500 Subject: [PATCH] A silent change to a model will now make hasChanged() return true ... Issue #105 --- backbone.js | 10 ++++------ test/model.js | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backbone.js b/backbone.js index 3031eb10..4217e625 100644 --- a/backbone.js +++ b/backbone.js @@ -180,10 +180,8 @@ if (!_.isEqual(now[attr], val)) { now[attr] = val; delete escaped[attr]; - if (!options.silent) { - this._changed = true; - this.trigger('change:' + attr, this, val, options); - } + this._changed = true; + if (!options.silent) this.trigger('change:' + attr, this, val, options); } } @@ -206,8 +204,8 @@ // Remove the attribute. delete this.attributes[attr]; delete this._escapedAttributes[attr]; + this._changed = true; if (!options.silent) { - this._changed = true; this.trigger('change:' + attr, this, void 0, options); this.change(options); } @@ -227,8 +225,8 @@ this.attributes = {}; this._escapedAttributes = {}; + this._changed = true; if (!options.silent) { - this._changed = true; for (attr in old) { this.trigger('change:' + attr, this, void 0, options); } diff --git a/test/model.js b/test/model.js index c1dfe3e9..87e12e6e 100644 --- a/test/model.js +++ b/test/model.js @@ -159,6 +159,8 @@ $(document).ready(function() { ok(_.isEqual(model.previousAttributes(), {name : "Tim", age : 10}), 'previousAttributes is correct'); }); model.set({name : 'Rob'}, {silent : true}); + equals(model.hasChanged(), true); + equals(model.hasChanged('name'), true); model.change(); equals(model.get('name'), 'Rob'); });