Bug, probably
When transitioning from a child state to another state on higher level using an ID, the onExit actions of the parent on the same level as the state being transitioned to are not fired.
onExit actions of parent state to be called
onExit actions are not being called
https://codepen.io/MiChAeLoKGB/pen/vjZvMg
This is related to #93 and I am not 100% sure if this is trully a bug, or just how the transitions between states are implemented (ie. they do not bubble).
If you dont use ID's, it calls the "parents" actions, because you have to have the on.SUCCESS in the parent itself (so the onExit and onEntry are the actions of that state).
Question is, which behavior is the correct one.
I would expect it to bubble up, just like the transitions do (if there is no SUCCESS on the child, it bubbles to the parent which has it).
Looking at the documentation of the onExit action, it should indeed be fired in this case:
When the state is a leaf state and is exited to go to a different state
> When the state is a parent state and the next state goes to a different same-level parent
When the state explicitly transitions to itself
The algorithm is currently being refactored internally, so I'm reworking how actions are determined, and it's likely that this bug (and #93) will be fixed in that refactor.
It does seem to be a bug. I exposed it in the debugger: https://bit.ly/2JU4G5I — The codepen had a little typo with onEnty instead of onEntry and when that's fixed, the _entry_ handlers are included, but the exit handlers are indeed not.
Here's a pending test that (hopefully after that refactor) will pass ensuring that the exit handlers are called: https://github.com/davidkpiano/xstate/blob/875c9ad67227d2c5b097772cc78f2506d5f25bbd/test/deep.test.ts#L106-L112
Thanks for the info about the typo, I was confused as to why my live code does fire then onEntry actions, but not the test code...
I have edited the question and fixed the codepen.
Fixed in master! (Hooray for refactoring magically fixing problems 🎉)
Most helpful comment
Fixed in master! (Hooray for refactoring magically fixing problems 🎉)