Skip to content

Commit

Permalink
Adds ability to reset data object
Browse files Browse the repository at this point in the history
This commit can be dropped after this PR is merged:

#1952
  • Loading branch information
johnnykahalawai authored and tejaede committed Dec 11, 2018
1 parent b660e6f commit cc0ca90
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
20 changes: 20 additions & 0 deletions data/service/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,26 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ {
}
},

/**
* Resets an object to the last value in the snapshot.
* @method
* @argument {Object} object - The object who will be reset.
* @returns {external:Promise} - A promise fulfilled when the object has
* been mapped back to its last known state.
*/
resetDataObject: {
value: function (object) {
var service = this._getChildServiceForObject(object),
promise;

if (service) {
promise = service.resetDataObject(object);
}

return promise;
}
},

/**
* Save changes made to a data object.
*
Expand Down
18 changes: 18 additions & 0 deletions data/service/raw-data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,24 @@ exports.RawDataService = DataService.specialize(/** @lends RawDataService.protot
}
},

/**
*
* Resets the object to its last known state.
*
* @method
* @argument {Object} object - The object to reset.
* @returns {external:Promise} - A promise fulfilled when the object has
* been reset to its last known state.
*
*/
resetDataObject: {
value: function (object) {
var snapshot = this.snapshotForObject(object),
result = this._mapRawDataToObject(snapshot, object);
return result || Promise.resolve(object);
}
},

/**
* Subclasses should override this method to save a data object when that
* object's raw data would be useful to perform the save.
Expand Down

0 comments on commit cc0ca90

Please sign in to comment.