From: Jérôme Benoit Date: Mon, 10 Jul 2023 17:18:07 +0000 (+0200) Subject: refactor: cleanup loops over object keys X-Git-Tag: v1.2.18~55 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b2b606263e2676354259164d532ff9aa91ccdf87;p=e-mobility-charging-stations-simulator.git refactor: cleanup loops over object keys Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 1b4934ed..ba4d14a8 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -7,7 +7,7 @@ import { isMainThread } from 'node:worker_threads'; import chalk from 'chalk'; -import { waitForChargingStationEvents } from './ChargingStationUtils'; +import { waitChargingStationEvents } from './ChargingStationUtils'; import type { AbstractUIServer } from './ui-server/AbstractUIServer'; import { UIServerFactory } from './ui-server/UIServerFactory'; import { version } from '../../package.json' assert { type: 'json' }; @@ -174,7 +174,7 @@ export class Bootstrap extends EventEmitter { ) ); await Promise.race([ - waitForChargingStationEvents( + waitChargingStationEvents( this, ChargingStationWorkerMessageEvents.stopped, this.numberOfChargingStations diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 66a4725f..d0d99c0b 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -532,7 +532,7 @@ export const getIdTagsFile = (stationInfo: ChargingStationInfo): string | undefi ); }; -export const waitForChargingStationEvents = async ( +export const waitChargingStationEvents = async ( emitter: EventEmitter, event: ChargingStationWorkerMessageEvents, eventsToWait: number diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index bfe3751c..ab2c1167 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -19,7 +19,7 @@ import type { AbstractUIServer } from '../AbstractUIServer'; const moduleName = 'AbstractUIService'; export abstract class AbstractUIService { - protected static readonly ProcedureNameToBroadCastChannelProcedureNameMap: Omit< + protected static readonly ProcedureNameToBroadCastChannelProcedureNameMapping: Omit< Record, | ProcedureName.START_SIMULATOR | ProcedureName.STOP_SIMULATOR @@ -140,7 +140,7 @@ export abstract class AbstractUIService { ): void { this.sendBroadcastChannelRequest( uuid, - AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMap[ + AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping[ procedureName ] as BroadcastChannelProcedureName, payload diff --git a/src/charging-station/ui-server/ui-services/UIService001.ts b/src/charging-station/ui-server/ui-services/UIService001.ts index 598ebb26..e6ee2d2c 100644 --- a/src/charging-station/ui-server/ui-services/UIService001.ts +++ b/src/charging-station/ui-server/ui-services/UIService001.ts @@ -5,11 +5,9 @@ import type { AbstractUIServer } from '../AbstractUIServer'; export class UIService001 extends AbstractUIService { constructor(uiServer: AbstractUIServer) { super(uiServer, ProtocolVersion['0.0.1']); - for (const procedureName of Object.keys( - AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMap - ) as ProcedureName[]) { + for (const procedureName in AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping) { this.requestHandlers.set( - procedureName, + procedureName as ProcedureName, this.handleProtocolRequest.bind(this) as ProtocolRequestHandler ); }