Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds method to reset data object to last snapshot #1952

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions data/service/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -86,7 +86,7 @@ exports.DataService = Montage.specialize(/** @lends DataService.prototype */ {
if (value) {
this.delegate = value;
}

return result;
}
},
Expand Down Expand Up @@ -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.
*
Expand Down
45 changes: 24 additions & 21 deletions data/service/raw-data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -808,6 +805,12 @@ exports.RawDataService = DataService.specialize(/** @lends RawDataService.protot
* [addRawData()]{@link RawDataService#addRawData}
* call that invoked this method.
*/
mapRawDataToObject: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't that break backward compatibility or are we now in position to do so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix - the code comments were not lined up so I put it over the right function. There was a merge conflict and I removed the wrong block.

value: function (rawData, object, context) {
return this.mapFromRawData(object, rawData, context);
}
},

_mapRawDataToObject: {
value: function (record, object, context) {
var self = this,
Expand Down