Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 780 Bytes

README.md

File metadata and controls

39 lines (30 loc) · 780 Bytes

Hine

A JavaScript state machine library.

Install

npm install hine

Getting started

import { atomic, compound, emitEvent, resolveState } from 'hine';

const toggleConfig = compound('toggle', {
	initial: 'inactive',
	children: [
		atomic('inactive', {
			on: { toggle: 'active' },
		}),
		atomic('active', {
			on: { toggle: 'inactive' },
		}),
	],
});
const myToggle = resolveState(toggleConfig);

// All compound states have exactly one active state
myToggle.activeChildren.length === 1; // true

myToggle.activeChildren[0].name === 'inactive'; // true
emitEvent(myToggle, 'toggle');
myToggle.activeChildren[0].name === 'active'; // true