@simple-state-machine/core
TypeScript icon, indicating that this package has built-in type declarations

0.1.0-alpha.3 • Public • Published

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 to dark or vice versa.
  • State diagram looks something like this for it: toggle-sm
  • 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

API

Package Sidebar

Install

npm i @simple-state-machine/core

Weekly Downloads

11

Version

0.1.0-alpha.3

License

MIT

Unpacked Size

39.8 kB

Total Files

5

Last publish

Collaborators

  • akhil_001