@corey.burrows/statechart
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

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.

Package Sidebar

Install

npm i @corey.burrows/statechart

Weekly Downloads

232

Version

0.3.0

License

MIT

Unpacked Size

71.1 kB

Total Files

21

Last publish

Collaborators

  • corey.burrows