mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 07:16:39 +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
|
||||
* @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;
|
||||
});
|
Loading…
Reference in New Issue
Block a user