perf(simulator): filter array for undefined before running map()
[e-mobility-charging-stations-simulator.git] / src / charging-station / UIServiceWorkerBroadcastChannel.ts
index 8528c0e247002a3f830d5f777e5f488f93cda99a..3a21bc7378d71161da31480e9b7e9a3d36ada4bc 100644 (file)
@@ -70,31 +70,31 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel {
       status: responsesStatus,
       hashIdsSucceeded: this.responses
         .get(uuid)
-        ?.responses.map(({ status, hashId }) => {
+        ?.responses.filter(({ hashId }) => hashId !== undefined)
+        .map(({ status, hashId }) => {
           if (status === ResponseStatus.SUCCESS) {
             return hashId;
           }
-        })
-        .filter((hashId) => hashId !== undefined),
+        }),
       ...(responsesStatus === ResponseStatus.FAILURE && {
         hashIdsFailed: this.responses
           .get(uuid)
-          ?.responses.map(({ status, hashId }) => {
+          ?.responses.filter(({ hashId }) => hashId !== undefined)
+          .map(({ status, hashId }) => {
             if (status === ResponseStatus.FAILURE) {
               return hashId;
             }
-          })
-          .filter((hashId) => hashId !== undefined),
+          }),
       }),
       ...(responsesStatus === ResponseStatus.FAILURE && {
         responsesFailed: this.responses
           .get(uuid)
-          ?.responses.map((response) => {
+          ?.responses.filter((response) => response !== undefined)
+          .map((response) => {
             if (response.status === ResponseStatus.FAILURE) {
               return response;
             }
-          })
-          .filter((response) => response !== undefined),
+          }),
       }),
     };
   }