mirror of
https://github.com/nasa/openmct.git
synced 2025-05-03 09:12:51 +00:00
[Persistence] Add to transaction on mutation
This commit is contained in:
parent
6f2c80bc2e
commit
f6d6cb929f
@ -28,15 +28,27 @@ define([], function () {
|
|||||||
* @param {Topic} topic the `topic` service; used to listen for mutation
|
* @param {Topic} topic the `topic` service; used to listen for mutation
|
||||||
* @memberof platform/core
|
* @memberof platform/core
|
||||||
*/
|
*/
|
||||||
function PersistingMutationListener(topic) {
|
function TransactingMutationListener(topic, transactionService) {
|
||||||
var mutationTopic = topic('mutation');
|
var mutationTopic = topic('mutation');
|
||||||
mutationTopic.listen(function (domainObject) {
|
mutationTopic.listen(function (domainObject) {
|
||||||
var persistence = domainObject.getCapability('persistence');
|
var persistence = domainObject.getCapability('persistence');
|
||||||
|
var wasActive = transactionService.isActive();
|
||||||
if (persistence.persisted()) {
|
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;
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user