From 410002a8a95b90befd627e218779ad495e1c2f32 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Fri, 16 Mar 2018 08:07:29 -1000 Subject: [PATCH 1/3] Adds method to reset data object to last snapshot --- data/service/data-service.js | 24 +++++++++++++++-- data/service/raw-data-service.js | 45 +++++++++++++++++--------------- 2 files changed, 46 insertions(+), 23 deletions(-) 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..e58c8deb3b 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, record, context); + } + }, + _mapRawDataToObject: { value: function (record, object, context) { var self = this, From c627df18136afd77577837297c3fbecedf6d302e Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Fri, 16 Mar 2018 09:09:32 -1000 Subject: [PATCH 2/3] Fixes error from merge conflict Inadvertently removed support for backwards compability. --- data/service/raw-data-service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/service/raw-data-service.js b/data/service/raw-data-service.js index e58c8deb3b..74bc73b16b 100644 --- a/data/service/raw-data-service.js +++ b/data/service/raw-data-service.js @@ -807,7 +807,7 @@ exports.RawDataService = DataService.specialize(/** @lends RawDataService.protot */ mapRawDataToObject: { value: function (rawData, object, context) { - // return this.mapFromRawData(object, record, context); + return this.mapFromRawData(object, record, context); } }, From b3b169467cc812cdde5182a0acad6aa36d7ba7ee Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Fri, 16 Mar 2018 10:30:40 -1000 Subject: [PATCH 3/3] Fixes another merge error --- data/service/raw-data-service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/service/raw-data-service.js b/data/service/raw-data-service.js index 74bc73b16b..51ee2e084d 100644 --- a/data/service/raw-data-service.js +++ b/data/service/raw-data-service.js @@ -807,7 +807,7 @@ exports.RawDataService = DataService.specialize(/** @lends RawDataService.protot */ mapRawDataToObject: { value: function (rawData, object, context) { - return this.mapFromRawData(object, record, context); + return this.mapFromRawData(object, rawData, context); } },