javascript-state-machine icon indicating copy to clipboard operation
javascript-state-machine copied to clipboard

Force a state without lifecycle events

Open giocasu opened this issue 7 years ago • 5 comments

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.

giocasu avatar Sep 10 '17 14:09 giocasu

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.

adami avatar Sep 11 '17 08:09 adami

Yes, I am using a similar workaround, thanks

G.

giocasu avatar Sep 11 '17 17:09 giocasu

I found "hackly" solution:

const stateMachine = new OrderDeliveryStateMachine()
stateMachine._fsm.state = order.deliveryStatus

dolgarev avatar Jan 31 '19 14:01 dolgarev

Looking for the same thing too...will try this solution. Although because its something you shouldn't typically do, I thinks solution is ok.

diversemix avatar Feb 15 '19 17:02 diversemix

@dolgarev thanks man! ugly hack, should be used with caution, but it works!

NelsonFrancisco avatar May 15 '19 17:05 NelsonFrancisco