Skip to content

Commit

Permalink
Changed the model's set function so that the 'nested' variable isn't …
Browse files Browse the repository at this point in the history
…required

Signed-off-by: Adriaan Labuschagne <[email protected]>
  • Loading branch information
adriaanlabusc committed Dec 26, 2012
1 parent a24544b commit 4f1cb85
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
// Set a hash of model attributes on the object, firing `"change"` unless
// you choose to silence it.
set: function(key, val, options) {
var attr, attrs, unset, changes, silent, nested, changing, prev, current;
var attr, attrs, unset, changes, silent, changing, prev, current;
if (key == null) return this;

// Handle both `"key", value` and `{key: value}` -style arguments.
Expand All @@ -308,7 +308,6 @@
unset = options.unset;
silent = options.silent;
changes = [];
nested = false;
changing = this._changing;
this._changing = true;

Expand All @@ -329,15 +328,14 @@
val = attrs[attr];
if (!_.isEqual(current[attr], val)) changes.push(attr);
if (!_.isEqual(prev[attr], val)) {
nested = true;
this.changed[attr] = val;
} else {
delete this.changed[attr];
}
unset ? delete current[attr] : current[attr] = val;
}

this._pending = !!changes.length;
if (changes.length) this._pending = true;

// Trigger all relevant attribute changes.
if (!silent) {
Expand All @@ -348,7 +346,6 @@

if (changing) return this;
if (!silent) {
if (!this._pending && nested) this.trigger('change', this, options);
while (this._pending) {
this._pending = false;
this.trigger('change', this, options);
Expand Down

0 comments on commit 4f1cb85

Please sign in to comment.