diff --git a/src/plugins/condition/ConditionManager.js b/src/plugins/condition/ConditionManager.js index c125f0b542..ffe26e5d8d 100644 --- a/src/plugins/condition/ConditionManager.js +++ b/src/plugins/condition/ConditionManager.js @@ -45,38 +45,12 @@ export default class ConditionManager extends EventEmitter { } } - // observeForChanges(conditionSetDomainObject) { - // this.stopObservingForChanges = this.openmct.objects.observe(conditionSetDomainObject, 'configuration.conditionCollection', this.handleConditionCollectionUpdated.bind(this)); - // } - // - // handleConditionCollectionUpdated(newConditionCollection) { - // // let oldConditionIds = this.conditionSetDomainObject.configuration.conditionCollection.map((conditionConfiguration) => { - // // return conditionConfiguration.id; - // // }); - // // let newConditionIds = newConditionCollection.map((conditionConfiguration) => { - // // return conditionConfiguration.id; - // // }); - // - // this.conditionSetDomainObject.configuration.conditionCollection = newConditionCollection; - // - // // //check for removed conditions - // // oldConditionIds.forEach((id, index) => { - // // if (newConditionIds.indexOf(id) < 0) { - // // this.removeCondition(id); - // // } - // // }); - // - // // const conditionSetDOConditionCollection = this.conditionSetDomainObject.configuration.conditionCollection; - // //should not need to check for removed conditions since this happens from the ConditionManager itself - // - // for (let i = 0; i < newConditionCollection.length; i++) { - // const conditionConfiguration = newConditionCollection[i]; - // const found = this.findConditionById(conditionConfiguration.id); - // if (!found) { - // this.initCondition(conditionConfiguration, i); - // } - // } - // } + //this should not happen very frequently + update(newConditionCollection) { + this.destroy(); + this.conditionSetDomainObject.configuration.conditionCollection = newConditionCollection; + this.initialize(); + } updateCondition(conditionConfiguration, index) { let condition = this.conditionClassCollection[index]; @@ -240,9 +214,6 @@ export default class ConditionManager extends EventEmitter { } destroy() { - if (typeof this.stopObservingForChanges === 'function') { - this.stopObservingForChanges(); - } this.conditionClassCollection.forEach((condition) => { condition.off('conditionResultUpdated', this.handleConditionResult); condition.destroy(); diff --git a/src/plugins/condition/ConditionSetTelemetryProvider.js b/src/plugins/condition/ConditionSetTelemetryProvider.js index cf721654ce..3aadfc502e 100644 --- a/src/plugins/condition/ConditionSetTelemetryProvider.js +++ b/src/plugins/condition/ConditionSetTelemetryProvider.js @@ -1,3 +1,25 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2020, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + import ConditionManager from './ConditionManager' export default class ConditionSetTelemetryProvider { @@ -21,9 +43,16 @@ export default class ConditionSetTelemetryProvider { let conditionManager = new ConditionManager(domainObject, this.openmct); conditionManager.on('conditionSetResultUpdated', callback); + let stopObservingForChanges = this.openmct.objects.observe(domainObject, 'configuration.conditionCollection', (newConditionCollection) => { + conditionManager.update(newConditionCollection); + }); + return function unsubscribe() { conditionManager.off('conditionSetResultUpdated'); conditionManager.destroy(); + if (stopObservingForChanges) { + stopObservingForChanges(); + } } } } diff --git a/src/plugins/condition/components/ConditionSet.vue b/src/plugins/condition/components/ConditionSet.vue index c2dfd13623..653fdd9985 100644 --- a/src/plugins/condition/components/ConditionSet.vue +++ b/src/plugins/condition/components/ConditionSet.vue @@ -58,27 +58,15 @@ export default { }, mounted() { this.conditionSetIdentifier = this.openmct.objects.makeKeyString(this.domainObject.identifier); - this.observeForChanges(); this.provideTelemetry(); }, beforeDestroy() { if (this.stopProvidingTelemetry) { this.stopProvidingTelemetry(); } - if (this.stopObservingForChanges) { - this.stopObservingForChanges(); - } }, methods: { - observeForChanges() { - this.stopObservingForChanges = this.openmct.objects.observe(this.domainObject, '*', (newDomainObject) => { - //Since the domain object changes in conditionCollection.vue we need to resubscribe when that happens - this.domainObject = newDomainObject; - this.provideTelemetry(); - }); - }, updateCurrentOutput(currentConditionResult) { - console.log(currentConditionResult); this.currentConditionOutput = currentConditionResult.output; }, provideTelemetry() {