[StackedPlots] Destroy programmatically created component instances (#4345)

This commit is contained in:
Jamie V 2021-10-22 10:54:46 -07:00 committed by GitHub
parent 4f8cba160d
commit 0249ab4df5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 27 deletions

View File

@ -37,7 +37,6 @@ describe("the plugin", function () {
let openmct; let openmct;
let telemetryPromise; let telemetryPromise;
let telemetryPromiseResolve; let telemetryPromiseResolve;
let cleanupFirst;
let mockObjectPath; let mockObjectPath;
let telemetrylimitProvider; let telemetrylimitProvider;
@ -77,7 +76,6 @@ describe("the plugin", function () {
'some-other-key': 'some-other-value 3' 'some-other-key': 'some-other-value 3'
} }
]; ];
cleanupFirst = [];
const timeSystem = { const timeSystem = {
timeSystemKey: 'utc', timeSystemKey: 'utc',
@ -168,19 +166,13 @@ describe("the plugin", function () {
}); });
afterEach((done) => { afterEach((done) => {
// Needs to be in a timeout because plots use a bunch of setTimeouts, some of which can resolve during or after openmct.time.timeSystem('utc', {
// teardown, which causes problems start: 0,
// This is hacky, we should find a better approach here. end: 1
setTimeout(() => {
//Cleanup code that needs to happen before dom elements start being destroyed
cleanupFirst.forEach(cleanup => cleanup());
cleanupFirst = [];
document.body.removeChild(element);
configStore.deleteAll();
resetApplicationState(openmct).then(done).catch(done);
}); });
configStore.deleteAll();
resetApplicationState(openmct).then(done).catch(done);
}); });
describe("the plot views", () => { describe("the plot views", () => {
@ -393,10 +385,6 @@ describe("the plugin", function () {
plotView = plotViewProvider.view(testTelemetryObject, [testTelemetryObject]); plotView = plotViewProvider.view(testTelemetryObject, [testTelemetryObject]);
plotView.show(child, true); plotView.show(child, true);
cleanupFirst.push(() => {
plotView.destroy();
});
return Vue.nextTick(); return Vue.nextTick();
}); });
@ -759,11 +747,6 @@ describe("the plugin", function () {
template: "<stacked-plot></stacked-plot>" template: "<stacked-plot></stacked-plot>"
}); });
cleanupFirst.push(() => {
component.$destroy();
component = undefined;
});
return telemetryPromise return telemetryPromise
.then(Vue.nextTick()) .then(Vue.nextTick())
.then(() => { .then(() => {

View File

@ -69,7 +69,7 @@
</template> </template>
<script> <script>
import eventHelpers from '../lib/eventHelpers';
import StackedPlotItem from './StackedPlotItem.vue'; import StackedPlotItem from './StackedPlotItem.vue';
import ImageExporter from '../../../exporters/ImageExporter'; import ImageExporter from '../../../exporters/ImageExporter';
@ -104,8 +104,6 @@ export default {
this.destroy(); this.destroy();
}, },
mounted() { mounted() {
eventHelpers.extend(this);
this.imageExporter = new ImageExporter(this.openmct); this.imageExporter = new ImageExporter(this.openmct);
this.tickWidthMap = {}; this.tickWidthMap = {};
@ -120,7 +118,6 @@ export default {
this.loading = loaded; this.loading = loaded;
}, },
destroy() { destroy() {
this.stopListening();
this.composition.off('add', this.addChild); this.composition.off('add', this.addChild);
this.composition.off('remove', this.removeChild); this.composition.off('remove', this.removeChild);
this.composition.off('reorder', this.compositionReorder); this.composition.off('reorder', this.compositionReorder);

View File

@ -75,6 +75,11 @@ export default {
mounted() { mounted() {
this.updateView(); this.updateView();
}, },
beforeDestroy() {
if (this.component) {
this.component.$destroy();
}
},
methods: { methods: {
updateComponentProp(prop, value) { updateComponentProp(prop, value) {
if (this.component) { if (this.component) {