Neapolitan Pizza Margherita
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

st8

2.0.0 • Public • Published

st8 Build Status

St8 is a tiny state machine for structural describing behavior of components.

Usage

$ npm install st8
var State = require('st8');
 
var state = new State({
    a: {
        enter: () => {
            ...
        },
        exit: () => {
            ...
        }
    },
 
    // shortcut for enter/exit
    b: [ () => {}, () => {} ],
 
    // enter shortcut, forwards to state d
    c: () => 'd',
 
    // shorter cut, redirects to state a
    d: 'a',
 
    // any other state
    _: 'a'
});
 
 
//enter state 'a', invoke corresponding callbacks
state.set('a');
 
//get current state
state.get(); // 'a'

API

let state = new State(states [, context])

Create a new state machine based on the states object. Optionally pass a context for callbacks.

state.get()

Get current state.

state.set(value)

Transition to a new state, invoking necessary callbacks.

NPM

Install

npm i st8

DownloadsWeekly Downloads

2,647

Version

2.0.0

License

MIT

Unpacked Size

16.8 kB

Total Files

9

Last publish

Collaborators

  • avatar
  • avatar