About Matchina
What is Matchina?
Section titled “What is Matchina?”A small state machine runtime built on matchbox factories. You define states as discriminated unions. You define transitions. The rest — event types, payload types, method signatures — falls out of the definition.
Why Matchina?
Section titled “Why Matchina?”- Types from definitions, not annotations. Define your machine shape. Get typed events, typed payloads, and typed method APIs without writing generics by hand. The types are already there if the library earns them.
- Call
machine.start()notmachine.send("start"). Derive a fully typed method API from your machine. Full autocomplete, full type safety, no string dispatch. - Open mutation pipeline. Every state transition runs through a hookable pipeline: guard, handle, before, update, enter/leave, effect, notify, after. Hook in at any phase, on any transition.
- Composable primitives. The same matchbox factories and lifecycle utilities the machines are built from are exported for standalone use. Take what you need.
- Not config-driven. Matchina is primitives that compose, not a declarative config format. If you want JSON-powered state machines, consider XState.
- Zero dependencies. 2kb.
What’s inside
Section titled “What’s inside”- Matchbox factories — discriminated union primitives, used standalone or as state definitions
- Factory machines — state machines with full type inference from matchbox shape
- Promise machines — async state with typed loading/success/error
- Lifecycle hooks — hook into any transition phase
- Event API — derive typed method APIs from your machine
- Integrations — React, Zod, Valibot