Package Exports
- st8
- st8/st8.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (st8) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
st8

Tiny state machine for structural describing behavior of components.
Usage
$ npm install st8
Standalone state machine
import State from 'st8';
var state = new State({
// 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'
Define stateful object property
import State from 'st8'
var state = new State({
a() {
// onenter
this === target //true
},
b() {
// onenter
this === target //true
return () => {
// onexit
}
}
}, target);
Object.defineProperty(target, property, {
set: function (value) {
return state.set(value);
},
get: function () {
return state.get();
}
});
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.
🕉