@simple-state-machine/core
v0.1.0-alpha.3
Published
## Installation ``` npm i @simple-state-machine/core ``` ## Quick glance - A simplest state machine can be a "Light<>Dark" Mode toggling. On click of button is toggle from `light` to `dark` or vice versa. - State diagram looks something like this for i
Downloads
25
Maintainers
Readme
Simple State Machine
Installation
npm i @simple-state-machine/core
Quick glance
- A simplest state machine can be a "Light<>Dark" Mode toggling. On click of button is toggle from
light
todark
or vice versa. - State diagram looks something like this for it:
- Code for the above machine using the library looks like
import {createState, createEvents, createContext, MachineConfig} from 'simple-state-machine' const states = createStates('light', 'dark'); const events = createEvents('TOGGLE'); const context = createContext({}); const ThemeMachine = new MachineConfig(states, context, events); const {whenIn} = ThemeMachine; whenIn('light').on('TOGGLE').moveTo('dark'); whenIn('dark').on('TOGGLE').moveTo('light');
Examples
- Toggle Theme Machine
- Throttling Machine in typescript