Fix event listener and observer leaks in cookie banner
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -18,7 +18,7 @@ import { ProboElement } from "./base";
|
|||||||
export class ProboCategory extends ProboElement {
|
export class ProboCategory extends ProboElement {
|
||||||
|
|
||||||
get categoryName(): string {
|
get categoryName(): string {
|
||||||
return this.getAttribute("name") ?? "";
|
return this.getAttribute("name") ?? "Other";
|
||||||
}
|
}
|
||||||
|
|
||||||
get required(): boolean {
|
get required(): boolean {
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ export class ProboCookieBannerRoot extends ProboElement implements ProboRootElem
|
|||||||
this.initClient();
|
this.initClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disconnectedCallback(): void {
|
||||||
|
if (this._client) {
|
||||||
|
this._client.destroy();
|
||||||
|
this._client = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setState(state: ProboState): void {
|
setState(state: ProboState): void {
|
||||||
const prev = this._state;
|
const prev = this._state;
|
||||||
this._state = state;
|
this._state = state;
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ export class ProboPreferencePanel extends ProboElement {
|
|||||||
private onStateChange = (e: Event): void => {
|
private onStateChange = (e: Event): void => {
|
||||||
const { state } = (e as CustomEvent).detail;
|
const { state } = (e as CustomEvent).detail;
|
||||||
this.hidden = state !== "panel";
|
this.hidden = state !== "panel";
|
||||||
|
if (state === "panel") {
|
||||||
|
(this.root as ProboCookieBannerRoot).resetDraft();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
connectedCallback(): void {
|
connectedCallback(): void {
|
||||||
@@ -34,12 +37,6 @@ export class ProboPreferencePanel extends ProboElement {
|
|||||||
|
|
||||||
if (this.root) {
|
if (this.root) {
|
||||||
this.root.addEventListener("probo-state", this.onStateChange);
|
this.root.addEventListener("probo-state", this.onStateChange);
|
||||||
this.root.addEventListener("probo-state", (e: Event) => {
|
|
||||||
const { state } = (e as CustomEvent).detail;
|
|
||||||
if (state === "panel") {
|
|
||||||
(this.root as ProboCookieBannerRoot).resetDraft();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scheduleValidation(() => this.validate());
|
this.scheduleValidation(() => this.validate());
|
||||||
|
|||||||
Reference in New Issue
Block a user