javascript-state-machine
javascript-state-machine copied to clipboard
Force a state without lifecycle events
Hi, I am using the module to run a fsm in a serverless environment.
After the fsm reach a state the system saves the session (the current state) and then exits. When the fsm is actviated again, it retrieve the previous state, creates a new fsm and enter that old state (with 'goto').
My problem is that onEnter<STATE> is called twice, I would like to force the fsm to the old state when the session is restored without calling any lifecyle methods, a sort of 'goto' without side effects.
Regards.
G.
I had the same problem and didn't find a solution. As a workaround, i'm checking in onEnter if the transition that got me there is 'goto' and just do nothing, maybe it can help you too.
Yes, I am using a similar workaround, thanks
G.
I found "hackly" solution:
const stateMachine = new OrderDeliveryStateMachine()
stateMachine._fsm.state = order.deliveryStatus
Looking for the same thing too...will try this solution. Although because its something you shouldn't typically do, I thinks solution is ok.
@dolgarev thanks man! ugly hack, should be used with caution, but it works!