Skip to content

Commit

Permalink
Change to leave logic to existing state machine. Now things should 'j…
Browse files Browse the repository at this point in the history
…ust work'
  • Loading branch information
courajs committed May 10, 2016
1 parent 82abc18 commit 3382029
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 13 additions & 8 deletions addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,13 +854,18 @@ InternalModel.prototype = {
}

if (isEnabled('ds-reset-attribute')) {
InternalModel.prototype.resetAttribute = function resetAttribute(attributeName) {
var attrs = this._attributes;
var dirtyKeys = Object.keys(attrs);
if (dirtyKeys.indexOf(attributeName) !== -1) {
delete this._attributes[attributeName];
this.send('propertyWasReset', attributeName);
this.record.notifyPropertyChange(attributeName);
/*
Returns the latest truth for an attribute - the canonical value, or the
in-flight value.
@method latestTrueValue
@private
*/
InternalModel.prototype.latestTrueValue = function latestTrueValue(key) {
if (key in this._inFlightAttributes) {
return this._inFlightAttributes[key];
} else {
return this._data[key];
}
}
};
}
4 changes: 3 additions & 1 deletion addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,9 @@ if (isEnabled('ds-reset-attribute')) {
@method resetAttribute
*/
resetAttribute(attributeName) {
this._internalModel.resetAttribute(attributeName);
if (attributeName in this._internalModel._attributes) {
this.set(attributeName, this._internalModel.latestTrueValue(attributeName));
}
}
});
}
Expand Down

0 comments on commit 3382029

Please sign in to comment.