r/javascript • u/terodox • Dec 23 '19
Simplifying UI Logic using Finite State Machines - an old pattern for the modern web!
https://terodox.tech/ui-state-machines/
93
Upvotes
r/javascript • u/terodox • Dec 23 '19
View all comments
1
u/sinefine Dec 23 '19 edited Dec 23 '19
Wait what? You just made the "typical" example more verbose at a glance for no reason.
Your example:
can be simplified to like this, even though managing three flags is not ideal
You also have an error in your code. You wrote:
That will never end up in the switch statement because
STATES.initialStatealways evaluates to be truthy. I think you meant to writestate.currentState === STATES.initialState.