[Common UI] Initial commonUI bundles
Bring in work on general-purpose and over-arching user interface bundles from the sandbox transition branch. WTD-574.
This commit is contained in:
55
platform/commonUI/edit/src/capabilities/EditorCapability.js
Normal file
55
platform/commonUI/edit/src/capabilities/EditorCapability.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/*global define*/
|
||||
|
||||
/**
|
||||
* Implements "save" and "cancel" as capabilities of
|
||||
* the object. In editing mode, user is seeing/using
|
||||
* a copy of the object (an EditableDomainObject)
|
||||
* which is disconnected from persistence; the Save
|
||||
* and Cancel actions can use this capability to
|
||||
* propagate changes from edit mode to the underlying
|
||||
* actual persistable object.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
return function EditorCapability(
|
||||
persistenceCapability,
|
||||
editableObject,
|
||||
domainObject,
|
||||
cache
|
||||
) {
|
||||
|
||||
function doMutate() {
|
||||
return domainObject.useCapability('mutation', function () {
|
||||
return editableObject.getModel();
|
||||
});
|
||||
}
|
||||
|
||||
function doPersist() {
|
||||
return persistenceCapability.persist();
|
||||
}
|
||||
|
||||
function saveOthers() {
|
||||
return cache.saveAll();
|
||||
}
|
||||
|
||||
function markClean() {
|
||||
return cache.markClean(editableObject);
|
||||
}
|
||||
|
||||
return {
|
||||
save: function () {
|
||||
return Promise.resolve(doMutate())
|
||||
.then(doPersist)
|
||||
.then(markClean)
|
||||
.then(saveOthers);
|
||||
},
|
||||
cancel: function () {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user