2 comments

[ 9.8 ms ] story [ 12.4 ms ] thread
(comment deleted)
I would use a state machine in this case. The best tool for doing this in JavaScript/TypeScript is XState. Highly recommend.