I'm learning x-state and I'm overwhelmed about its functionality, but I'm having issues understanding history
nodes.
I'm creating a state which should hold the execution of the machine until an action is triggered:
So if the machine is in AwaitingEmployeeSignature
or AwaitingOnboardingCompletion
, and the EA_REDLINED
event is triggered, I want to move the machine to the Paused
state. But after a RESUME
event (which is not implemented), I want to resume the last state AwaitingEmployeeSignature
or AwaitingOnboardingCompletion
, depending on what was the state before the Paused
state
As I understand history nodes, it can achieve what I want, but as far as I understood, it doesn't hold this state, but when on it, it automatically moves to the last state (which is not what I want). How can I stay in the Paused
state, and only move to the previous state when the RESUME
event is triggered?
Thanks in advance!
A history node targets the most recently visited child state of a parent state before exiting that parent state.
In your case, the solution would be to place the top 5 states in your diagram in some parent state, add a history state to that parent state, and on resume, transition to that e.g.
parent.hist
state.Then the target of that resume event will be the last state that the parent state was in.