@vielzeug/clockwork
v26.10.16
Published
Framework-neutral finite state machines with pure transitions and actors
Readme
@vielzeug/clockwork
Framework-neutral finite state machines with pure transitions and actors
Installation
pnpm add @vielzeug/clockwork
npm install @vielzeug/clockwork
yarn add @vielzeug/clockworkQuick Start
import { defineMachine } from '@vielzeug/clockwork';
type Event = { type: 'INC' } | { type: 'RESET' };
const counter = defineMachine<{ count: number }, Event>()({
context: { count: 0 },
initial: 'idle',
states: {
idle: {
on: {
INC: { reduce: ({ context }) => ({ count: context.count + 1 }), target: 'idle' },
RESET: { reduce: () => ({ count: 0 }), target: 'idle' },
},
},
},
});
const actor = counter.createActor();
actor.send({ type: 'INC' });
console.log(actor.snapshot);
// { state: 'idle', context: { count: 1 } }
actor.dispose();Documentation
License
MIT © Helmuth Saatkamp: part of the Vielzeug monorepo.
