TS-FSM is a strongly typed finite state machine for TypeScript that is using async operations. Library uses generics to take the user states and events. Zero dependencies!
Hello @eram, I really like the API design of your "typescript-fsm" library. It looks simple, yet powerful. I was wondering if it would be possible to generate the diagram of your "Basic Example" from the code?
One of the main reasons to use a FSM is to protect the internal state of the model (the context).
Normally the context is defined inside the FSM and is only accessible on transitions and onEnter/onExit executions (so you avoid side effects).
The only way to change the context of a FSM is sending an event to it.
Would be really nice to have conditional transitions.
Normally in a FSM you can define more than one transition for the same state/event and depending on the condition one transition is selected or not (first transition that fulfil a condition is chosen even if another transition would be a good candidate).
The transitions are evaluated on order of declaration.
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).
Sometimes in a FSM is needed to just do something not on the transition but when you enter or exit one state. Would be nice to add this functionality.
Good example is your state "breaking" where you want only to log and you have to define the action for all the states that reach that state (would have more sense to do onEnter).