[Persistence] Add to transaction on mutation
This commit is contained in:
@@ -28,15 +28,27 @@ define([], function () {
|
||||
* @param {Topic} topic the `topic` service; used to listen for mutation
|
||||
* @memberof platform/core
|
||||
*/
|
||||
function PersistingMutationListener(topic) {
|
||||
function TransactingMutationListener(topic, transactionService) {
|
||||
var mutationTopic = topic('mutation');
|
||||
mutationTopic.listen(function (domainObject) {
|
||||
var persistence = domainObject.getCapability('persistence');
|
||||
var wasActive = transactionService.isActive();
|
||||
if (persistence.persisted()) {
|
||||
persistence.persist();
|
||||
if (!wasActive) {
|
||||
transactionService.startTransaction();
|
||||
}
|
||||
|
||||
transactionService.addToTransaction(
|
||||
persistence.persist.bind(persistence),
|
||||
persistence.refresh.bind(persistence)
|
||||
);
|
||||
|
||||
if (!wasActive) {
|
||||
transactionService.commit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return PersistingMutationListener;
|
||||
return TransactingMutationListener;
|
||||
});
|
||||
Reference in New Issue
Block a user