From 10f69a10abc1fe4a8e87880604a479cf337553ec Mon Sep 17 00:00:00 2001 From: Malcolm Kee Date: Mon, 5 Dec 2022 23:45:39 +1100 Subject: [PATCH] fix: remove optional chaining syntax --- client-src/overlay/fsm.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/client-src/overlay/fsm.js b/client-src/overlay/fsm.js index 95abd60f58..78020e97aa 100644 --- a/client-src/overlay/fsm.js +++ b/client-src/overlay/fsm.js @@ -36,19 +36,26 @@ function createMachine({ states, context, initial }, { actions }) { return { send: (event) => { - const transitionConfig = states[currentState].on?.[event.type]; + const currentStateOn = states[currentState].on; + const transitionConfig = currentStateOn && currentStateOn[event.type]; if (transitionConfig) { currentState = transitionConfig.target; - transitionConfig.actions?.forEach((actName) => { - const nextContextValue = actions[actName]?.(currentContext, event); - if (nextContextValue) { - currentContext = { - ...currentContext, - ...nextContextValue, - }; - } - }); + if (transitionConfig.actions) { + transitionConfig.actions.forEach((actName) => { + const actionImpl = actions[actName]; + + const nextContextValue = + actionImpl && actionImpl(currentContext, event); + + if (nextContextValue) { + currentContext = { + ...currentContext, + ...nextContextValue, + }; + } + }); + } } }, };