mirror of
https://github.com/nasa/openmct.git
synced 2024-12-23 15:02:23 +00:00
Merge pull request #1490 from nasa/open1482
[Edit] Only persist on mutation if model has actually changed locally
This commit is contained in:
commit
058dfb0c87
@ -148,13 +148,19 @@ define(
|
||||
*/
|
||||
PersistenceCapability.prototype.refresh = function () {
|
||||
var domainObject = this.domainObject;
|
||||
var $q = this.$q;
|
||||
|
||||
// Update a domain object's model upon refresh
|
||||
function updateModel(model) {
|
||||
var modified = model.modified;
|
||||
return domainObject.useCapability("mutation", function () {
|
||||
return model;
|
||||
}, modified);
|
||||
if (model === undefined) {
|
||||
//Get failed, reject promise
|
||||
return $q.reject('Got empty object model');
|
||||
} else {
|
||||
var modified = model.modified;
|
||||
return domainObject.useCapability("mutation", function () {
|
||||
return model;
|
||||
}, modified);
|
||||
}
|
||||
}
|
||||
|
||||
if (domainObject.getModel().persisted === undefined) {
|
||||
|
@ -34,23 +34,32 @@ define([], function () {
|
||||
transactionService,
|
||||
cacheService
|
||||
) {
|
||||
|
||||
function hasChanged(domainObject) {
|
||||
var model = domainObject.getModel();
|
||||
return model.persisted === undefined || model.modified > model.persisted;
|
||||
}
|
||||
|
||||
var mutationTopic = topic('mutation');
|
||||
mutationTopic.listen(function (domainObject) {
|
||||
var persistence = domainObject.getCapability('persistence');
|
||||
var wasActive = transactionService.isActive();
|
||||
cacheService.put(domainObject.getId(), domainObject.getModel());
|
||||
|
||||
if (!wasActive) {
|
||||
transactionService.startTransaction();
|
||||
}
|
||||
if (hasChanged(domainObject)) {
|
||||
|
||||
transactionService.addToTransaction(
|
||||
persistence.persist.bind(persistence),
|
||||
persistence.refresh.bind(persistence)
|
||||
);
|
||||
if (!wasActive) {
|
||||
transactionService.startTransaction();
|
||||
}
|
||||
|
||||
if (!wasActive) {
|
||||
transactionService.commit();
|
||||
transactionService.addToTransaction(
|
||||
persistence.persist.bind(persistence),
|
||||
persistence.refresh.bind(persistence)
|
||||
);
|
||||
|
||||
if (!wasActive) {
|
||||
transactionService.commit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user