From: Jérôme Benoit Date: Tue, 5 Mar 2024 19:08:57 +0000 (+0100) Subject: fix(ui): remove WS event listeners at main page unmount X-Git-Tag: v1.3.0~50 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aa9b0a1ec352572d91076a4d0cfa78b53a46c759;p=e-mobility-charging-stations-simulator.git fix(ui): remove WS event listeners at main page unmount Signed-off-by: Jérôme Benoit --- diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index 04b703e3..8a86d150 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -53,6 +53,14 @@ export class UIClient { this.ws?.addEventListener(event, listener, options) } + public unregisterWSEventListener( + event: K, + listener: (event: WebSocketEventMap[K]) => void, + options?: boolean | AddEventListenerOptions + ) { + this.ws?.removeEventListener(event, listener, options) + } + public async simulatorState(): Promise { return this.sendRequest(ProcedureName.SIMULATOR_STATE, {}) } diff --git a/ui/web/src/views/ChargingStationsView.vue b/ui/web/src/views/ChargingStationsView.vue index 109803f4..621c7122 100644 --- a/ui/web/src/views/ChargingStationsView.vue +++ b/ui/web/src/views/ChargingStationsView.vue @@ -18,7 +18,7 @@ state.uiServerIndex ] ) - initializeWSEventListeners() + registerWSEventListeners() uiClient.registerWSEventListener( 'open', () => { @@ -41,7 +41,7 @@ getFromLocalStorage('uiServerConfigurationIndex', 0) ] ) - initializeWSEventListeners() + registerWSEventListeners() }, { once: true } ) @@ -115,7 +115,7 @@