My blog posts about this subject:
- Predictable programming 3 - using XState
- Testing complex XState machines
- (WIP) Strongly typed state machines in Typescript
Thoughts:
Use XState, currently the only good state chart library out there.
- Prefer small machines, avoid complex monsters.
- Use typegen, even though it’s a messy and weird solution.
- Inject your dependencies in context, it makes it easier to test.
- Black-box test your machines.
- I originally built tsbuilder to make it easier to build state machines for testing.
- I’m also working on a library to help mock XState machines.
However, I’m not convinced that state charts are even the right model. A state chart is a combination of state machines, and I think a better library would provide only state machines and some simple, functional tools to connect them. This would force users to create small, easily testable machines. It would also ostensibly simplify the types.
See tstate for a developing library built on these ideas.