mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
Move mutation listening out of cache service
This commit is contained in:
parent
9a7f69a614
commit
d74eba1922
@ -373,9 +373,6 @@ define([
|
||||
{
|
||||
"key": "cacheService",
|
||||
"implementation": ModelCacheService,
|
||||
"depends": [
|
||||
"topic"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "now",
|
||||
@ -415,7 +412,7 @@ define([
|
||||
"runs": [
|
||||
{
|
||||
"implementation": TransactingMutationListener,
|
||||
"depends": ["topic", "transactionService"]
|
||||
"depends": ["topic", "transactionService", "cacheService"]
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
|
@ -28,13 +28,8 @@ define([], function () {
|
||||
* @constructor
|
||||
* @memberof platform/core
|
||||
*/
|
||||
function ModelCacheService(topic) {
|
||||
function ModelCacheService() {
|
||||
this.cache = {};
|
||||
topic('mutation').listen(function (domainObject) {
|
||||
if (this.has(domainObject.getId())) {
|
||||
this.put(domainObject.getId(), domainObject.getModel());
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,11 @@ define([], function () {
|
||||
* @param {Topic} topic the `topic` service; used to listen for mutation
|
||||
* @memberof platform/core
|
||||
*/
|
||||
function TransactingMutationListener(topic, transactionService) {
|
||||
function TransactingMutationListener(
|
||||
topic,
|
||||
transactionService,
|
||||
cacheService
|
||||
) {
|
||||
var mutationTopic = topic('mutation');
|
||||
mutationTopic.listen(function (domainObject) {
|
||||
var persistence = domainObject.getCapability('persistence');
|
||||
@ -39,15 +43,6 @@ define([], function () {
|
||||
if (!wasActive) {
|
||||
transactionService.startTransaction();
|
||||
}
|
||||
var wrap = function(f) {
|
||||
return function () {
|
||||
if (MUTATION_TRACKER.has(domainObject)) {
|
||||
MUTATION_TRACKER.get(domainObject)();
|
||||
MUTATION_TRACKER.delete(domainObject);
|
||||
}
|
||||
return f();
|
||||
}
|
||||
}
|
||||
|
||||
if (!MUTATION_TRACKER.has(domainObject)) {
|
||||
MUTATION_TRACKER.set(domainObject, domainObject
|
||||
@ -56,12 +51,21 @@ define([], function () {
|
||||
);
|
||||
}
|
||||
|
||||
// add model to cache and keep cache up to date with listener
|
||||
// remove listener and remove from cache on commit & on cancel.
|
||||
cacheService.put(domainObject.getId(), domainObject.getModel());
|
||||
|
||||
function unlistenAndCall(f) {
|
||||
return function () {
|
||||
if (MUTATION_TRACKER.has(domainObject)) {
|
||||
MUTATION_TRACKER.get(domainObject)();
|
||||
MUTATION_TRACKER.delete(domainObject);
|
||||
}
|
||||
return f();
|
||||
}
|
||||
}
|
||||
|
||||
transactionService.addToTransaction(
|
||||
wrap(persistence.persist.bind(persistence)),
|
||||
wrap(persistence.refresh.bind(persistence))
|
||||
unlistenAndCall(persistence.persist.bind(persistence)),
|
||||
unlistenAndCall(persistence.refresh.bind(persistence))
|
||||
);
|
||||
|
||||
if (!wasActive) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user