@datnguyen1215/hsmjs
v2.2.1
Published
A lightweight hierarchical state machine library
Downloads
28
Maintainers
Readme
HSMJS
Lightweight hierarchical state machine for JavaScript with XState-like syntax.
Features
Installation
npm install @datnguyen1215/hsmjsQuick Start
import { createMachine, assign } from '@datnguyen1215/hsmjs';
const toggleMachine = createMachine({
id: 'toggle',
initial: 'inactive',
context: { count: 0 },
states: {
inactive: {
on: {
TOGGLE: {
target: 'active',
actions: [assign({ count: ({ context }) => context.count + 1 })]
}
}
},
active: {
entry: [() => console.log('Activated!')],
on: { TOGGLE: 'inactive' }
}
}
});
// Use the machine
await toggleMachine.send('TOGGLE'); // inactive -> active, count: 1
console.log(toggleMachine.state); // 'active'
console.log(toggleMachine.context); // { count: 1 }Documentation
Quick Links
- Quick Start - Get started in 5 minutes
- Syntax Cheatsheet - All syntax on one page
- API Quick Reference - Most used methods
- Migration from XState - Switching from XState
Feature Guides
- Context & assign()
- Actions
- Guards
- Events
- Nested States
- Async Patterns
- History & Undo
- Visualization
- Validation
- Subscriptions
More Resources
- Framework Integration - React, Svelte, Vue
- Examples - Real-world patterns
- Full API Reference - Complete documentation
License
MIT
