Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kwangure/hine-archive

A state machine library
https://github.com/kwangure/hine-archive

finite-state-machine fsm state state-machine

Last synced: about 2 months ago
JSON representation

A state machine library

Awesome Lists containing this project

README

        



Hine

A JavaScript state machine library.

### Install

```bash
npm install hine
```

### Getting started

```javascript
import { atomic, compound } from 'hine';

// Compound states have `children`
const toggle = compound({
// The first state (in this case 'inactive') is the default initial state
children: {
// Atomic states do not have `children`. They're leaves in the tree.
inactive: atomic({
on: {
// `goto` will change the current state after a 'toggle' event
toggle: { goto: 'active' },
},
}),
active: atomic({
on: {
toggle: { goto: 'inactive' },
},
}),
},
});

toggle.resolve();

toggle.matches('inactive'); // true

toggle.dispatch('toggle');

toggle.matches('active'); // true
```