[Transaction] Sync mutation within transaction
This commit is contained in:
@@ -171,7 +171,9 @@ define([
|
|||||||
|
|
||||||
function finishEditing(clonedObject) {
|
function finishEditing(clonedObject) {
|
||||||
return domainObject.getCapability("editor").finish()
|
return domainObject.getCapability("editor").finish()
|
||||||
.then(resolveWith(clonedObject));
|
.then(function () {
|
||||||
|
return fetchObject(clonedObject.getId());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onFailure() {
|
function onFailure() {
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
/*global define*/
|
/*global define*/
|
||||||
|
|
||||||
define([], function () {
|
define([], function () {
|
||||||
|
|
||||||
|
var MUTATION_TRACKER = new WeakMap();
|
||||||
/**
|
/**
|
||||||
* Listens for mutation on domain objects and triggers persistence when
|
* Listens for mutation on domain objects and triggers persistence when
|
||||||
* it occurs.
|
* it occurs.
|
||||||
@@ -37,10 +39,29 @@ define([], function () {
|
|||||||
if (!wasActive) {
|
if (!wasActive) {
|
||||||
transactionService.startTransaction();
|
transactionService.startTransaction();
|
||||||
}
|
}
|
||||||
|
var wrap = function(f) {
|
||||||
|
return function () {
|
||||||
|
if (MUTATION_TRACKER.has(domainObject)) {
|
||||||
|
MUTATION_TRACKER.get(domainObject)();
|
||||||
|
MUTATION_TRACKER.delete(domainObject);
|
||||||
|
}
|
||||||
|
return f();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MUTATION_TRACKER.has(domainObject)) {
|
||||||
|
MUTATION_TRACKER.set(domainObject, domainObject
|
||||||
|
.getCapability('mutation')
|
||||||
|
.listen(function () {})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add model to cache and keep cache up to date with listener
|
||||||
|
// remove listener and remove from cache on commit & on cancel.
|
||||||
|
|
||||||
transactionService.addToTransaction(
|
transactionService.addToTransaction(
|
||||||
persistence.persist.bind(persistence),
|
wrap(persistence.persist.bind(persistence)),
|
||||||
persistence.refresh.bind(persistence)
|
wrap(persistence.refresh.bind(persistence))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!wasActive) {
|
if (!wasActive) {
|
||||||
|
|||||||
Reference in New Issue
Block a user