jakesgordon / javascript-state-machine

A javascript finite state machine library
MIT License
8.69k stars 964 forks source link

Force a state without lifecycle events #132

Open giocasu opened 7 years ago

giocasu commented 7 years ago

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 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.

adami commented 7 years ago

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.

giocasu commented 7 years ago

Yes, I am using a similar workaround, thanks

G.

dolgarev commented 5 years ago

I found "hackly" solution:

const stateMachine = new OrderDeliveryStateMachine()
stateMachine._fsm.state = order.deliveryStatus
diversemix commented 5 years ago

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

NelsonFrancisco commented 5 years ago

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