Kristi
Kristi is an asynchronous finite state machine engine. It allows you to describe a program (or part of it) using an automata-based approach.
In addition, this is my first experiment with literate programming (with help of a literate-programming-lib).
Kristi is inspired by Machina.js library.
Usage
Import
Users of npm can use npm install kristi
.
In other case, use gulp build-min
to get minified UMD-compatible build.
FSM Construction
; let fsm = 'login-screen-is-shown': transitions: 'user-authenticated' : 'todo-screen-is-shown' 'password-recovery-requested' : 'password-recovery-screen-is-shown' { let fsm = this; // Automaton instance is set as `this` in `coming` and `leaving`; // AJAX requests for screen template, etc... return { ; ; }; } { // Some clean-up } 'todo-screen-is-shown' : ... ...; fsm;
The "best practice" is to move transition functions out of fsm-schema definition:
let fsm = 'login-screen-is-shown': transitions: 'user-authenticated' : 'todo-screen-is-shown' 'password-recovery-requested' : 'password-recovery-screen-is-show' coming: showLoginScreen leaving: hideLoginScreen ...;
Events
Kristi provides simple on/off
interface, so you can subscribe to some events from fsm instance.
fsm; fsm;
TODO: add full Event API description.
API
The full API description could be found here.