From 9e9194c977f2100a92a4549e6562750499607706 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 23 Mar 2024 01:09:14 +0100 Subject: [PATCH] refactor: cleanup app message handling code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index c13eb1b1..0f2a26a8 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -376,38 +376,35 @@ export class Bootstrap extends EventEmitter { // 2 // )}` // ) + const { event, data } = msg try { - switch (msg.event) { + switch (event) { case ChargingStationWorkerMessageEvents.added: - this.emit(ChargingStationWorkerMessageEvents.added, msg.data) + this.emit(ChargingStationWorkerMessageEvents.added, data) break case ChargingStationWorkerMessageEvents.deleted: - this.emit(ChargingStationWorkerMessageEvents.deleted, msg.data) + this.emit(ChargingStationWorkerMessageEvents.deleted, data) break case ChargingStationWorkerMessageEvents.started: - this.emit(ChargingStationWorkerMessageEvents.started, msg.data) + this.emit(ChargingStationWorkerMessageEvents.started, data) break case ChargingStationWorkerMessageEvents.stopped: - this.emit(ChargingStationWorkerMessageEvents.stopped, msg.data) + this.emit(ChargingStationWorkerMessageEvents.stopped, data) break case ChargingStationWorkerMessageEvents.updated: - this.emit(ChargingStationWorkerMessageEvents.updated, msg.data) + this.emit(ChargingStationWorkerMessageEvents.updated, data) break case ChargingStationWorkerMessageEvents.performanceStatistics: - this.emit(ChargingStationWorkerMessageEvents.performanceStatistics, msg.data) + this.emit(ChargingStationWorkerMessageEvents.performanceStatistics, data) break default: throw new BaseError( - `Unknown charging station worker event: '${ - msg.event - }' received with data: ${JSON.stringify(msg.data, undefined, 2)}` + `Unknown charging station worker event: '${event}' received with data: ${JSON.stringify(data, undefined, 2)}` ) } } catch (error) { logger.error( - `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while handling '${ - msg.event - }' event:`, + `${this.logPrefix()} ${moduleName}.messageHandler: Error occurred while handling '${event}' event:`, error ) } -- 2.34.1