diff --git a/data/service/data-service.js b/data/service/data-service.js index b98c19048e..c93ee8e9ec 100644 --- a/data/service/data-service.js +++ b/data/service/data-service.js @@ -56,7 +56,7 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ { deserializeSelf: { value:function (deserializer) { var self = this, - result = null, + result = null, value; value = deserializer.getProperty("childServices"); @@ -86,7 +86,7 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ { if (value) { this.delegate = value; } - + return result; } }, @@ -1893,6 +1893,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. * diff --git a/data/service/raw-data-service.js b/data/service/raw-data-service.js index 14df6020dd..51ee2e084d 100644 --- a/data/service/raw-data-service.js +++ b/data/service/raw-data-service.js @@ -283,6 +283,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 delete a data object when that * object's raw data would be useful to perform the deletion. @@ -754,27 +772,6 @@ exports.RawDataService = DataService.specialize(/** @lends RawDataService.protot } }, - /** - * Convert raw data to data objects of an appropriate type. - * - * Subclasses should override this method to map properties of the raw data - * to data objects: - * @method - * @argument {Object} record - An object whose properties' values hold - * the raw data. - * @argument {Object} object - An object whose properties must be set or - * modified to represent the raw data. - * @argument {?} context - The value that was passed in to the - * [addRawData()]{@link RawDataService#addRawData} - * call that invoked this method. - */ - - - mapRawDataToObject: { - value: function (rawData, object, context) { - return this.mapFromRawData(object, rawData, context); - } - }, /** * Convert raw data to data objects of an appropriate type. * @@ -808,6 +805,12 @@ exports.RawDataService = DataService.specialize(/** @lends RawDataService.protot * [addRawData()]{@link RawDataService#addRawData} * call that invoked this method. */ + mapRawDataToObject: { + value: function (rawData, object, context) { + return this.mapFromRawData(object, rawData, context); + } + }, + _mapRawDataToObject: { value: function (record, object, context) { var self = this,