Skip to content

tbleckert/state

Repository files navigation

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');

About

Simple state machine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published