[Persistence] Add refresh

Continue adding behavior for persistence failures; add a refresh method
to the persistence capability to support this. WTD-1033.
This commit is contained in:
Victor Woeltjen
2015-03-20 12:40:58 -07:00
parent d4691db8e2
commit 717b9b1b92
5 changed files with 109 additions and 7 deletions

View File

@ -22,6 +22,13 @@ define(
* @constructor
*/
function PersistenceCapability(persistenceService, SPACE, domainObject) {
// Update a domain object's model upon refresh
function updateModel(model) {
return domainObject.useCapability("mutation", function () {
return model;
});
}
return {
/**
* Persist any changes which have been made to this
@ -37,6 +44,19 @@ define(
domainObject.getModel()
);
},
/**
* Update this domain object to match the latest from
* persistence.
* @returns {Promise} a promise which will be resolved
* when the update is complete
*/
refresh: function () {
return persistenceService.readObject(
SPACE,
domainObject.getId(),
{ cache: false } // Disallow cached reads
).then(updateModel);
},
/**
* Get the space in which this domain object is persisted;
* this is useful when, for example, decided which space a