Skip to content

yay-machine

a modern, simple, lightweight, zero-dependency, TypeScript state-machine library

Modern

yay-machine borrows the best ideas from other JS/TypeScript state-machine and state-management libraries.

It will feel familiar to XState users, with features including:

  • JSON config
  • state-data (context / extended-state / dynamic state)
  • conditional transitions (guards)
  • immediate (always) transitions
  • event handling in specific-state or any-state
  • similar creation and lifecycle API

And yay-machine brings new ideas of its own:

  • states are types (think: interface). They are an object with a name and any associated data. Different states may have different associated data
  • side-effects are all you need for sync/async interactions with the current machine and outside world

We prefer contemporary accessible language, to traditional academic terms.

Simple

yay-machine has only a handful of concepts and the API is minimal

  • states
  • events
  • transitions
  • side-effects

These features can be combined to model just about anything.

It should be quick to learn, and have a minimal ongoing cost-of-ownership.

Lightweight

yay-machine is a tiny package and won’t bloat your app bundles.

yay-machine bundlephobia stats

Minimal implementation means minimal overhead and you can trust yay-machine with your high-performance workloads.

bench tests

Zero-dependency

The core yay-machine state-machine library has zero production dependencies.

It won’t bloat your node_modules/ and you won’t have to worry about having to patch some security vulnerability or compatibility issue in a 3rd-party package that yay-machine depends on.

TypeScript

We ❤️ TypeScript and want the best experience for TypeScript developers with state-machines.

Each state in yay-machine is a type, giving you more compile-time confidence.

Where next?

Examples

Checkout out our various examples to demonstrate solving problems with with yay-machine

Reference docs

Get detailed explanations of concepts and application in the reference docs