Skip to content

Latest commit

 

History

History
56 lines (48 loc) · 1.23 KB

File metadata and controls

56 lines (48 loc) · 1.23 KB

Simple state machine

NPM

Install

npm i @bleckert/state or yarn add @bleckert/state

Usage

import Machine from '@bleckert/state';

const machine = new Machine({
    IDLE: {
        on: {
            send: 'SENDING',
        },
    },
    SENDING: {
        on: {
            sent: 'SENT',
            failed: 'ERROR',
        },
    },
    SENT: {
        final: true,
    },
    FAILED: {
        on: {
            retry: 'SENDING',
        },
    },
});

machine.onState('SENDING', console.log);
machine.dispatch('send');