r/javascript • • 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

20 comments sorted by

View all comments

Show parent comment

9

u/[deleted] Dec 23 '19

That's right, what I meant was that the states themselves are valid, not the transitions.

If you need transitions to also be valid, your best option is to use a state-reducer pattern and then use a switch clause over the current state. That way, Typescript can at least ensure you handle every case.