mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 15:26:39 +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,14 +148,20 @@ define(
|
|||||||
*/
|
*/
|
||||||
PersistenceCapability.prototype.refresh = function () {
|
PersistenceCapability.prototype.refresh = function () {
|
||||||
var domainObject = this.domainObject;
|
var domainObject = this.domainObject;
|
||||||
|
var $q = this.$q;
|
||||||
|
|
||||||
// Update a domain object's model upon refresh
|
// Update a domain object's model upon refresh
|
||||||
function updateModel(model) {
|
function updateModel(model) {
|
||||||
|
if (model === undefined) {
|
||||||
|
//Get failed, reject promise
|
||||||
|
return $q.reject('Got empty object model');
|
||||||
|
} else {
|
||||||
var modified = model.modified;
|
var modified = model.modified;
|
||||||
return domainObject.useCapability("mutation", function () {
|
return domainObject.useCapability("mutation", function () {
|
||||||
return model;
|
return model;
|
||||||
}, modified);
|
}, modified);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (domainObject.getModel().persisted === undefined) {
|
if (domainObject.getModel().persisted === undefined) {
|
||||||
return this.$q.when(true);
|
return this.$q.when(true);
|
||||||
|
@ -34,12 +34,20 @@ define([], function () {
|
|||||||
transactionService,
|
transactionService,
|
||||||
cacheService
|
cacheService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
function hasChanged(domainObject) {
|
||||||
|
var model = domainObject.getModel();
|
||||||
|
return model.persisted === undefined || model.modified > model.persisted;
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
var wasActive = transactionService.isActive();
|
||||||
cacheService.put(domainObject.getId(), domainObject.getModel());
|
cacheService.put(domainObject.getId(), domainObject.getModel());
|
||||||
|
|
||||||
|
if (hasChanged(domainObject)) {
|
||||||
|
|
||||||
if (!wasActive) {
|
if (!wasActive) {
|
||||||
transactionService.startTransaction();
|
transactionService.startTransaction();
|
||||||
}
|
}
|
||||||
@ -52,6 +60,7 @@ define([], function () {
|
|||||||
if (!wasActive) {
|
if (!wasActive) {
|
||||||
transactionService.commit();
|
transactionService.commit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user