3.0.1 • Published 11 days ago

@dldc/stachine v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 days ago

Stachine

A TypeScript state machine with events and effects

npm install @dldc/stachine

Gist

import { Stachine } from '@dldc/stachine';

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

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

11 days ago

3.0.0

19 days ago

2.1.8

29 days ago

2.1.7

3 months ago

2.1.6

5 months ago

2.1.5

6 months ago

2.1.4

7 months ago

2.1.3

7 months ago

2.1.2

8 months ago

2.1.1

10 months ago

2.1.0

10 months ago

2.0.0

11 months ago