typescript-fsm
typescript-fsm copied to clipboard
Send context on callbacks - protect from side effects
The transition callbacks should receive and instance of the fsm event handler and the state from/to:
function onOpen(eh: EventHandler, from: State, to: State): Promise<void> {
console.log("onOpen...");
return eh.dispatch(Events.openComplete);
}
With your current code I would not be able to execute 2 instances of the same FSM, which is a problem if for example you want to use an FSM per user (to handle his user state).