[Persistence] Add to transaction on mutation

This commit is contained in:
Victor Woeltjen 2016-07-26 15:24:16 -07:00
parent 6f2c80bc2e
commit f6d6cb929f

View File

@ -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;
});