mirror of
https://github.com/nasa/openmct.git
synced 2025-02-24 02:41:25 +00:00
avoid multiple instantiations of condtionManager if possible
This commit is contained in:
parent
6b4cd25417
commit
00d1b5e69f
@ -67,12 +67,10 @@ export default class ConditionClass extends EventEmitter {
|
||||
}
|
||||
|
||||
handleReceivedTelemetry(datum) {
|
||||
console.log(`received datum`);
|
||||
if (!datum || !datum.id) {
|
||||
console.log('no data received');
|
||||
return;
|
||||
}
|
||||
|
||||
this.criteria.filter(criterion => criterion.telemetryObjectIdAsString === datum.id)
|
||||
.forEach(subscribingCriterion => {
|
||||
subscribingCriterion.emit(`subscription`, datum)
|
||||
|
@ -32,8 +32,8 @@ export default class ConditionManager extends EventEmitter {
|
||||
this.timeAPI = this.openmct.time;
|
||||
this.latestTimestamp = {};
|
||||
this.composition = this.openmct.composition.get(conditionSetDomainObject);
|
||||
this.composition.on('add', this.addTelemetry, this)
|
||||
this.composition.on('remove', this.removeTelemetry, this)
|
||||
this.composition.on('add', this.addTelemetry, this);
|
||||
this.composition.on('remove', this.removeTelemetry, this);
|
||||
|
||||
this.loaded = this.composition.load();
|
||||
this.subscriptions = {};
|
||||
@ -53,8 +53,7 @@ export default class ConditionManager extends EventEmitter {
|
||||
|
||||
this.subscriptions[id] = this.openmct.telemetry.subscribe(
|
||||
endpoint,
|
||||
this.broadcastTelemetry
|
||||
.bind(this, id)
|
||||
this.broadcastTelemetry.bind(this, id)
|
||||
);
|
||||
}
|
||||
|
||||
@ -212,7 +211,6 @@ export default class ConditionManager extends EventEmitter {
|
||||
// update conditions results and then calculate the current condition
|
||||
this.updateConditionResults(resultObj);
|
||||
const currentCondition = this.getCurrentCondition();
|
||||
|
||||
this.emit('conditionSetResultUpdated',
|
||||
Object.assign(
|
||||
{
|
||||
@ -264,20 +262,7 @@ export default class ConditionManager extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
// subscribeToTelemetry() {
|
||||
|
||||
// this.load().then((endpoints) => {
|
||||
// this.unsubscribes = endpoints.map(endpoint => {
|
||||
// this.openmct.telemetry.subscribe(
|
||||
// endpoint,
|
||||
// this.broadcastTelemetry
|
||||
// .bind(this, this.openmct.objects.makeKeyString(endpoint.identifier)));
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
broadcastTelemetry(id, datum) {
|
||||
console.log(this.conditionClassCollection);
|
||||
this.conditionClassCollection.filter(condition => {
|
||||
return condition.getTelemetrySubscriptions().includes(id);
|
||||
}).forEach(subscribingCondition => {
|
||||
@ -293,11 +278,15 @@ export default class ConditionManager extends EventEmitter {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.composition.off('add', this.addTelemetry, this)
|
||||
this.composition.off('remove', this.removeTelemetry, this)
|
||||
this.composition.off('add', this.addTelemetry, this);
|
||||
this.composition.off('remove', this.removeTelemetry, this);
|
||||
Object.values(this.subscriptions).forEach(unsubscribe => unsubscribe());
|
||||
this.subscriptions = undefined;
|
||||
|
||||
if(this.stopObservingForChanges) {
|
||||
this.stopObservingForChanges();
|
||||
}
|
||||
|
||||
this.conditionClassCollection.forEach((condition) => {
|
||||
condition.off('conditionResultUpdated', this.handleConditionResult);
|
||||
condition.destroy();
|
||||
|
@ -40,7 +40,7 @@ export default class ConditionSetTelemetryProvider {
|
||||
}
|
||||
|
||||
request(domainObject, options) {
|
||||
let conditionManager = new ConditionManager(domainObject, this.openmct);
|
||||
let conditionManager = options.conditionManager || new ConditionManager(domainObject, this.openmct);
|
||||
|
||||
return conditionManager.requestLADConditionSetOutput()
|
||||
.then(latestOutput => {
|
||||
@ -50,8 +50,9 @@ export default class ConditionSetTelemetryProvider {
|
||||
});
|
||||
}
|
||||
|
||||
subscribe(domainObject, callback) {
|
||||
let conditionManager = new ConditionManager(domainObject, this.openmct);
|
||||
subscribe(domainObject, callback, options) {
|
||||
let conditionManager = options.conditionManager || new ConditionManager(domainObject, this.openmct);
|
||||
|
||||
conditionManager.on('conditionSetResultUpdated', callback);
|
||||
|
||||
return function unsubscribe() {
|
||||
|
@ -121,11 +121,15 @@ export default {
|
||||
this.conditionCollection = this.domainObject.configuration.conditionCollection;
|
||||
this.observeForChanges();
|
||||
this.conditionManager = new ConditionManager(this.domainObject, this.openmct);
|
||||
this.conditionManager.requestLADConditionSetOutput()
|
||||
console.log(`collection condition manager: ${this.conditionManager.id}`);
|
||||
|
||||
let options = { conditionManager: this.conditionManager };
|
||||
this.openmct.telemetry.request(this.domainObject, options)
|
||||
.then(data => this.$emit('conditionSetResultUpdated', data[0]));
|
||||
this.conditionManager.on('conditionSetResultUpdated', (data) => {
|
||||
this.$emit('conditionSetResultUpdated', data);
|
||||
});
|
||||
this.unsubscribe = this.openmct.telemetry.subscribe(
|
||||
this.domainObject,
|
||||
(data) => { this.$emit('conditionSetResultUpdated', data); },
|
||||
options);
|
||||
},
|
||||
methods: {
|
||||
observeForChanges() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user