diff --git a/platform/core/src/runs/PersistingMutationListener.js b/platform/core/src/runs/TransactingMutationListener.js similarity index 75% rename from platform/core/src/runs/PersistingMutationListener.js rename to platform/core/src/runs/TransactingMutationListener.js index b992ed3d8a..c534c6fae2 100644 --- a/platform/core/src/runs/PersistingMutationListener.js +++ b/platform/core/src/runs/TransactingMutationListener.js @@ -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; });