Ensure that dynamically created vue components are destroyed. (#6948)

This commit is contained in:
Shefali Joshi 2023-08-17 16:24:02 -07:00 committed by GitHub
parent 3f80b53ea6
commit bada228b8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 13 deletions

View File

@ -98,9 +98,11 @@ export default function () {
}; };
function getScatterPlotFormControl(openmct) { function getScatterPlotFormControl(openmct) {
let destroyComponent;
return { return {
show(element, model, onChange) { show(element, model, onChange) {
const { vNode } = mount( const { vNode, destroy } = mount(
{ {
el: element, el: element,
components: { components: {
@ -122,8 +124,12 @@ export default function () {
element element
} }
); );
destroyComponent = destroy;
return vNode; return vNode;
},
destroy() {
destroyComponent();
} }
}; };
} }

View File

@ -30,7 +30,7 @@ export default function plugin(appliesToObjects, options = { indicator: true })
return function install(openmct) { return function install(openmct) {
if (installIndicator) { if (installIndicator) {
const { vNode } = mount( const { vNode, destroy } = mount(
{ {
components: { components: {
GlobalClearIndicator GlobalClearIndicator
@ -49,7 +49,8 @@ export default function plugin(appliesToObjects, options = { indicator: true })
let indicator = { let indicator = {
element: vNode.el, element: vNode.el,
key: 'global-clear-indicator', key: 'global-clear-indicator',
priority: openmct.priority.DEFAULT priority: openmct.priority.DEFAULT,
destroy: destroy
}; };
openmct.indicators.add(indicator); openmct.indicators.add(indicator);

View File

@ -167,9 +167,11 @@ export default function () {
}; };
function getGaugeFormController(openmct) { function getGaugeFormController(openmct) {
let destroyComponent;
return { return {
show(element, model, onChange) { show(element, model, onChange) {
const { vNode } = mount( const { vNode, destroy } = mount(
{ {
el: element, el: element,
components: { components: {
@ -191,8 +193,12 @@ export default function () {
element element
} }
); );
destroyComponent = destroy;
return vNode.componentInstance; return vNode.componentInstance;
},
destroy() {
destroyComponent();
} }
}; };
} }

View File

@ -98,6 +98,9 @@ export default {
if (this.unlisten) { if (this.unlisten) {
this.unlisten(); this.unlisten();
} }
if (this.destroyImageryContainer) {
this.destroyImageryContainer();
}
}, },
methods: { methods: {
setTimeContext() { setTimeContext() {
@ -237,7 +240,10 @@ export default {
imageryContainer = existingContainer; imageryContainer = existingContainer;
imageryContainer.style.maxWidth = `${containerWidth}px`; imageryContainer.style.maxWidth = `${containerWidth}px`;
} else { } else {
const { vNode } = mount( if (this.destroyImageryContainer) {
this.destroyImageryContainer();
}
const { vNode, destroy } = mount(
{ {
components: { components: {
SwimLane SwimLane
@ -257,6 +263,7 @@ export default {
} }
); );
this.destroyImageryContainer = destroy;
const component = vNode.componentInstance; const component = vNode.componentInstance;
this.$refs.imageryHolder.appendChild(component.$el); this.$refs.imageryHolder.appendChild(component.$el);

View File

@ -90,7 +90,10 @@ export default {
drawerElement.innerHTML = '<div></div>'; drawerElement.innerHTML = '<div></div>';
const divElement = document.querySelector('.l-shell__drawer div'); const divElement = document.querySelector('.l-shell__drawer div');
mount( if (this.destroySnapshotContainer) {
this.destroySnapshotContainer();
}
const { destroy } = mount(
{ {
el: divElement, el: divElement,
components: { components: {
@ -113,6 +116,7 @@ export default {
element: divElement element: divElement
} }
); );
this.destroySnapshotContainer = destroy;
}, },
updateSnapshotIndicatorTitle() { updateSnapshotIndicatorTitle() {
const snapshotCount = this.snapshotContainer.getSnapshots().length; const snapshotCount = this.snapshotContainer.getSnapshots().length;

View File

@ -83,7 +83,7 @@ function installBaseNotebookFunctionality(openmct) {
openmct.actions.register(new CopyToNotebookAction(openmct)); openmct.actions.register(new CopyToNotebookAction(openmct));
openmct.actions.register(new ExportNotebookAsTextAction(openmct)); openmct.actions.register(new ExportNotebookAsTextAction(openmct));
const { vNode } = mount( const { vNode, destroy } = mount(
{ {
components: { components: {
NotebookSnapshotIndicator NotebookSnapshotIndicator
@ -102,7 +102,8 @@ function installBaseNotebookFunctionality(openmct) {
const indicator = { const indicator = {
element: vNode.el, element: vNode.el,
key: 'notebook-snapshot-indicator', key: 'notebook-snapshot-indicator',
priority: openmct.priority.DEFAULT priority: openmct.priority.DEFAULT,
destroy: destroy
}; };
openmct.indicators.add(indicator); openmct.indicators.add(indicator);

View File

@ -24,7 +24,7 @@ import NotificationIndicator from './components/NotificationIndicator.vue';
export default function plugin() { export default function plugin() {
return function install(openmct) { return function install(openmct) {
const { vNode } = mount( const { vNode, destroy } = mount(
{ {
components: { components: {
NotificationIndicator NotificationIndicator
@ -42,7 +42,8 @@ export default function plugin() {
let indicator = { let indicator = {
key: 'notifications-indicator', key: 'notifications-indicator',
element: vNode.el, element: vNode.el,
priority: openmct.priority.DEFAULT priority: openmct.priority.DEFAULT,
destroy: destroy
}; };
openmct.indicators.add(indicator); openmct.indicators.add(indicator);
}; };

View File

@ -197,7 +197,7 @@ export default {
this.composition.load(); this.composition.load();
} }
const { vNode } = mount( const { vNode, destroy } = mount(
{ {
components: { components: {
Plot Plot
@ -249,6 +249,7 @@ export default {
} }
); );
this.component = vNode.componentInstance; this.component = vNode.componentInstance;
this._destroy = destroy;
if (this.isEditing) { if (this.isEditing) {
this.setSelection(); this.setSelection();

View File

@ -25,7 +25,7 @@ import UserIndicator from './components/UserIndicator.vue';
export default function UserIndicatorPlugin() { export default function UserIndicatorPlugin() {
function addIndicator(openmct) { function addIndicator(openmct) {
const { vNode } = mount( const { vNode, destroy } = mount(
{ {
components: { components: {
UserIndicator UserIndicator
@ -43,7 +43,8 @@ export default function UserIndicatorPlugin() {
openmct.indicators.add({ openmct.indicators.add({
key: 'user-indicator', key: 'user-indicator',
element: vNode.el, element: vNode.el,
priority: openmct.priority.HIGH priority: openmct.priority.HIGH,
destroy: destroy
}); });
} }