Skip to content

Commit 218cbf7

Browse files
committed
fix(data-content): remove event listener on disconnect
1 parent d1b97ac commit 218cbf7

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

web/src/testgrid-data-content.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,30 @@ export class TestgridDataContent extends LitElement {
6969
navigateTab(this.dashboardName, this.tabName);
7070
}
7171

72+
private handleTabChanged = (evt: Event) => {
73+
this.tabName = (<CustomEvent>evt).detail.tabName;
74+
this.showTab = !this.showTab;
75+
this.highlightIndex(this.tabName);
76+
navigateTab(this.dashboardName, this.tabName!);
77+
};
78+
7279
/**
7380
* Lit-element lifecycle method.
7481
* Invoked when a component is added to the document's DOM.
7582
*/
7683
connectedCallback() {
7784
super.connectedCallback();
7885
this.fetchTabNames();
79-
window.addEventListener('tab-changed', (evt: Event) => {
80-
this.tabName = (<CustomEvent>evt).detail.tabName;
81-
this.showTab = !this.showTab;
82-
this.highlightIndex(this.tabName);
83-
navigateTab(this.dashboardName, this.tabName!);
84-
});
86+
window.addEventListener('tab-changed', this.handleTabChanged);
87+
}
88+
89+
/**
90+
* Lit-element lifecycle method.
91+
* Invoked when a component is removed from the document's DOM.
92+
*/
93+
disconnectedCallback() {
94+
super.disconnectedCallback();
95+
window.removeEventListener('tab-changed', this.handleTabChanged);
8596
}
8697

8798
/**

0 commit comments

Comments
 (0)