jab jab - 5 months ago 60
Javascript Question

JavaScript Event State Machine

Does anybody know of any javascript implementations of a state machine? My goal is to setup a state machine implementation that would bind events to state transitions. So, if a user clicks on a button then the state will be changed, and this state might define certain values in objects to be changed for example.

I want this to be a state machine simply because there will be a rules json file that will allow to dictate what values change of various objects when certain events are called. Because this will be structured within the file, I think it would be easy to parse that information into a state machine object.


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

1/ https://github.com/ifandelse/machina.js Very well documented, examples, supports two JavaScript message bus providers out of the box: postal.js and amplify.js.

2/ https://github.com/jakesgordon/javascript-state-machine simpler and easier to use, perfect for "basic" usages.