Skip to content

Commit

Permalink
fix: remove optional chaining syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolm-kee committed Dec 5, 2022
1 parent 5298888 commit 10f69a1
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions client-src/overlay/fsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
});
}
}
},
};
Expand Down

0 comments on commit 10f69a1

Please sign in to comment.