3.0.1 • Published 1 year ago

@dldc/stachine v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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

1 year ago

3.0.0

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago