this.ws?.addEventListener(event, listener, options)
}
+ public unregisterWSEventListener<K extends keyof WebSocketEventMap>(
+ event: K,
+ listener: (event: WebSocketEventMap[K]) => void,
+ options?: boolean | AddEventListenerOptions
+ ) {
+ this.ws?.removeEventListener(event, listener, options)
+ }
+
public async simulatorState(): Promise<ResponsePayload> {
return this.sendRequest(ProcedureName.SIMULATOR_STATE, {})
}
state.uiServerIndex
]
)
- initializeWSEventListeners()
+ registerWSEventListeners()
uiClient.registerWSEventListener(
'open',
() => {
getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
]
)
- initializeWSEventListeners()
+ registerWSEventListeners()
},
{ once: true }
)
</template>
<script setup lang="ts">
-import { computed, getCurrentInstance, onMounted, ref } from 'vue'
+import { computed, getCurrentInstance, onMounted, onUnmounted, ref } from 'vue'
import { useToast } from 'vue-toast-notification'
import CSTable from '@/components/charging-stations/CSTable.vue'
import type { ResponsePayload, SimulatorState, UIServerConfigurationSection } from '@/types'
}
}
-const initializeWSEventListeners = () => {
- uiClient.registerWSEventListener('open', () => {
- getSimulatorState()
- getTemplates()
- getChargingStations()
- })
+const getData = (): void => {
+ getSimulatorState()
+ getTemplates()
+ getChargingStations()
+}
+
+const registerWSEventListeners = () => {
+ uiClient.registerWSEventListener('open', getData)
uiClient.registerWSEventListener('error', clearChargingStations)
uiClient.registerWSEventListener('close', clearChargingStations)
}
+const unregisterWSEventListeners = () => {
+ uiClient.unregisterWSEventListener('open', getData)
+ uiClient.unregisterWSEventListener('error', clearChargingStations)
+ uiClient.unregisterWSEventListener('close', clearChargingStations)
+}
+
onMounted(() => {
- initializeWSEventListeners()
+ registerWSEventListeners()
+})
+
+onUnmounted(() => {
+ unregisterWSEventListeners()
})
const uiServerConfigurations: { index: number; configuration: UIServerConfigurationSection }[] =