Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@corey.burrows/statechart

burrows1.9kMIT0.3.0TypeScript support: included

Simple Stateless Statechart

statechart, state, chart, statemachine, machine, harel, fsm

readme

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

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

License

Statechart is MIT licensed.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.3.0 - 2024-04-01

Added

  • Node#on now accepts multiple event types.

0.2.2 - 2023-08-03

Fixed

  • Activities were not being cleaned up properly when calling Statechart#stop.

Added

  • Updated Machine class to take in optional observer and trace options.

0.2.1 - 2022-11-11

Fixed

  • Concurrent state exit bug where sibling states had child states with the same name.

0.2.0 - 2022-04-20

Added

  • OVERVIEW docs.
  • API docs.

Changed

  • Allow condition functions to return undefined so that a state can both use a condition function and be a history state.

0.1.1 - 2022-03-13

Added

  • Toggle example app.
  • Stopwatch example app.

Changed

  • Package size optimizations.

0.1.0 - 2022-03-09

Added

  • Initial release.