国图
Statechart 是用于构建的 TypeScript 库 Harel 状态图。 。 。 .
安装
npm install @corey.burrows/statechart
基本用途
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']
文档
相关项目
- 状态图
- 使用状态图管理 React 组件的状态
许可证
国图是 麻省理工学院执照。 。 。 .