1.1.1 • Published 11 months ago

stachine v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
11 months ago

Stachine

A TypeScript state machine with events and effects

Gist

import { StateMachine } from 'stachine';

type States = { type: 'Home' } | { type: 'Bed' } | { type: 'Work' };
type Events = { type: 'Commute' } | { type: 'Wake' } | { type: 'Sleep' };

const machine = new StateMachine<States, Events>(
  { type: 'Home' },
  {
    onEvent: {
      Commute: {
        Home: () => ({ type: 'Work' }),
        Work: () => ({ type: 'Home' }),
      },
      Sleep: {
        Home: () => ({ type: 'Bed' }),
      },
      Wake: {
        Bed: (effect) => {
          effect(() => {
            console.log(`Good night`);
          });
          return { type: 'Home' };
        },
      },
    },
  }
);
2.0.0-1

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

2.0.0-0

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.2

2 years ago

1.0.0-19

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.3

2 years ago

1.0.0-20

2 years ago

1.0.0-21

2 years ago

1.0.0-18

2 years ago

1.0.0-17

3 years ago

1.0.0-16

3 years ago

1.0.0-14

3 years ago

1.0.0-15

3 years ago

1.0.0-13

3 years ago

1.0.0-11

3 years ago

1.0.0-12

3 years ago

1.0.0-10

3 years ago

1.0.0-9

3 years ago

1.0.0-8

3 years ago

1.0.0-7

3 years ago

1.0.0-6

3 years ago

1.0.0-5

3 years ago

1.0.0-4

3 years ago

1.0.0-3

3 years ago

1.0.0-2

3 years ago

1.0.0-1

4 years ago

1.0.0-0

4 years ago