kentcdodds / kentcdodds.com

My personal website
https://kentcdodds.com
Other
2.29k stars 617 forks source link

Wrong order of events in state-machine code #499

Open igittigitt opened 5 months ago

igittigitt commented 5 months ago

In your very finde article about state-machines https://kentcdodds.com/blog/implementing-a-simple-state-machine-library-in-javascript you put the onExit() and onEnter() events after the action() event:

destinationTransition.action()
currentStateDefinition.actions.onExit()
destinationStateDefinition.actions.onEnter()

Maybe i did not get the principles right, but wouldn't this order be the right one?

currentStateDefinition.actions.onExit()
destinationTransition.action()
destinationStateDefinition.actions.onEnter()
kentcdodds commented 5 months ago

I'm not positive, it was a long time ago that I wrote this blog post. But if you can link me to the part in the specification that says I'm wrong, then I'm happy to correct it!