0.3.0 • Published 1 month ago

@corey.burrows/statechart v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

Statechart

Statechart

Statechart is a TypeScript library for building Harel Statecharts.

Installation

npm install @corey.burrows/statechart

Basic Usage

import Statechart from '@corey.burrows/statechart';

type Ctx {}
type Evt = {type: 'toggle'};

const toggle = new Statechart<Ctx, Evt>({}, s => {
  s.state('on', s => {
    s.on('toggle', '../off');
  });

  s.state('off', s => {
    s.on('toggle', '../on');
  });
});

let state = toggle.initialState;
console.log(state.paths); // ['/on']
state = toggle.send(state, {type: 'toggle'});
console.log(state.paths); // ['/off']
state = toggle.send(state, {type: 'toggle'});
console.log(state.paths); // ['/on']

Documentation

Related Projects

  • useStatechart
    • Use a statechart to manage a React component's state

License

Statechart is MIT licensed.

0.3.0

1 month ago

0.2.2

9 months ago

0.2.1

1 year ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago