Skip to main content

createLiteMachine()

createLiteMachine<S, E>(definition, initial): object

createLiteMachine<S, E, C>(definition, initial, initialContext): object

Creates a lightweight finite state machine (no trySend, no @zygos/option dependency).


Type Parameters​

S: S extends string​

Union of state names

E: E extends string​

Union of event names

C: C​

Context type


Parameters​

Overload 1:

definition: MachineDefinition<S, E, undefined>​

The state/transition map

initial: S​

The initial state

Overload 2:

definition: MachineDefinition<S, E, C>​

The state/transition map

initial: S​

The initial state

initialContext: C​

The initial context value


Returns: object​

A machine with current, send, matches, onTransition, reset

current(): () => S​

Returns: S​

send(): (event) => S​

event: E
Returns: S

matches(): (state) => boolean​

state: S
Returns: boolean

onTransition(): (listener) => () => void​

listener: TransitionListener<S, E>
Returns: > (): void

Returns: void​

reset(): () => void​

Returns: void​


Since​

2.5.0