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