typescript-fsm icon indicating copy to clipboard operation
typescript-fsm copied to clipboard

Send context on callbacks - protect from side effects

Open carlos-verdes opened this issue 5 years ago • 0 comments

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

carlos-verdes avatar Feb 18 '19 16:02 carlos-verdes