mirror of
https://github.com/nasa/openmct.git
synced 2025-04-09 04:14:32 +00:00
restrict conditionManager instances to one per domainObject
This commit is contained in:
parent
a5a197680d
commit
78487a48f6
@ -25,6 +25,7 @@ import ConditionManager from './ConditionManager'
|
||||
export default class ConditionSetTelemetryProvider {
|
||||
constructor(openmct) {
|
||||
this.openmct = openmct;
|
||||
this.conditionManagerPool = {};
|
||||
}
|
||||
|
||||
isTelemetryObject(domainObject) {
|
||||
@ -39,36 +40,45 @@ export default class ConditionSetTelemetryProvider {
|
||||
return domainObject.type === 'conditionSet';
|
||||
}
|
||||
|
||||
request(domainObject, options) {
|
||||
let conditionManager = options.conditionManager;
|
||||
let newConditionManager = false;
|
||||
if (!conditionManager) {
|
||||
newConditionManager = true;
|
||||
conditionManager = new ConditionManager(domainObject, this.openmct);
|
||||
}
|
||||
request(domainObject) {
|
||||
let conditionManager = this.getConditionManager(domainObject);
|
||||
|
||||
return conditionManager.requestLADConditionSetOutput()
|
||||
.then(latestOutput => {
|
||||
if (newConditionManager) {
|
||||
conditionManager.destroy();
|
||||
conditionManager = undefined;
|
||||
}
|
||||
return latestOutput ? [latestOutput] : [];
|
||||
});
|
||||
}
|
||||
|
||||
subscribe(domainObject, callback, options) {
|
||||
let conditionManager = options.conditionManager;
|
||||
if (!conditionManager) {
|
||||
conditionManager = new ConditionManager(domainObject, this.openmct);
|
||||
conditionManager.on('conditionSetResultUpdated', callback);
|
||||
return function unsubscribe() {
|
||||
conditionManager.off('conditionSetResultUpdated');
|
||||
conditionManager.destroy();
|
||||
conditionManager = undefined;
|
||||
};
|
||||
}
|
||||
subscribe(domainObject, callback) {
|
||||
let conditionManager = this.getConditionManager(domainObject);
|
||||
|
||||
conditionManager.on('conditionSetResultUpdated', callback);
|
||||
|
||||
return this.destroyConditionManager.bind(this, this.openmct.objects.makeKeyString(domainObject.identifier));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns conditionManager instance for corresponding domain object
|
||||
* creates the instance if it is not yet created
|
||||
* @private
|
||||
*/
|
||||
getConditionManager(domainObject) {
|
||||
const id = this.openmct.objects.makeKeyString(domainObject.identifier);
|
||||
|
||||
if (!this.conditionManagerPool[id]) {
|
||||
this.conditionManagerPool[id] = new ConditionManager(domainObject, this.openmct);
|
||||
}
|
||||
|
||||
return this.conditionManagerPool[id];
|
||||
}
|
||||
|
||||
/**
|
||||
* cleans up and destroys conditionManager instance for corresponding domain object id
|
||||
* can be called manually for views that only request but do not subscribe to data
|
||||
*/
|
||||
destroyConditionManager(id) {
|
||||
this.conditionManagerPool[id].off('conditionSetResultUpdated');
|
||||
this.conditionManagerPool[id].destroy();
|
||||
delete this.conditionManagerPool[id];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user