This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

stachine
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Stachine

A TypeScript state machine with events and effects

Gist

import { Stachine } from 'stachine';

type State = { state: 'Home' } | { state: 'Bed' } | { state: 'Work' } | { state: 'Error' };
type Action = { action: 'Commute' } | { action: 'Wake' } | { action: 'Sleep' } | { action: 'Error' };

const machine = Stachine<State, Action>({
  initialState: { state: 'Home' },
  createErrorAction: () => ({ action: 'Error' }),
  createErrorState: () => ({ state: 'Error' }),
  states: {
    Home: {
      actions: {
        Commute: () => ({ state: 'Work' }),
        Sleep: () => ({ state: 'Bed' }),
      },
    },
    Work: {
      actions: {
        Commute: () => ({ state: 'Home' }),
      },
    },
    Bed: {
      actions: {
        Wake: () => ({ state: 'Home' }),
      },
    },
    Error: {},
  },
});

Package Sidebar

Install

npm i stachine

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

24.3 kB

Total Files

8

Last publish

Collaborators

  • etienne-dldc-graveyard