JavaScript Event State Machine

There are two main libraries for a finite state machine in js :

1/ Machina: Very well documented, examples, supports two JavaScript message bus providers out of the box: postal.js and amplify.js.

2/ Javascript State Machine: simpler and easier to use, perfect for "basic" usages.


I recently built a state machine implementation in JS, which is certainly the easiest to configure, thanks to its transition DSL:

transitions: [
  'next    : intro > form > finish',
  'back    : intro < form           < error',
  'error   :         form >           error',
  'restart : intro        < finish'
]

It's really flexible in both configuration and event handler assignment, you can add and remove states at runtime, pause and resume transitions, hook into a ton of events, with helpers for jQuery and reactive frameworks like Vue:

state-machine-demo

Docs and a whole host of demos here:

  • http://statemachine.davestewart.io