Skip to content

Fsm

Defined in: fsm.ts:35

Single-client FSM. Wraps a BehavioralFsm and uses the config’s context object as the implicit client, so callers never pass a client argument.

Prefer createFsm() over constructing this directly — the factory infers all generic parameters from the config object.

All public methods silently no-op after dispose() is called.

TCtx extends object

The context type, inferred from config.context.

TStateNames extends string

String literal union of valid state names.

TInputNames extends string

String literal union of valid input names.

new Fsm<TCtx, TStateNames, TInputNames>(config): Fsm<TCtx, TStateNames, TInputNames>

Defined in: fsm.ts:48

FsmConfig<TCtx, Record<string, Record<string, unknown>>>

Fsm<TCtx, TStateNames, TInputNames>

readonly [MACHINA_TYPE]: "Fsm"

Defined in: fsm.ts:38


readonly id: string

Defined in: fsm.ts:36

canHandle(inputName): boolean

Defined in: fsm.ts:97

Returns true if the current state has a handler for inputName (or a catch-all "*" handler). Does not trigger initialization or any side effects. Returns false when disposed.

string

boolean


compositeState(): string

Defined in: fsm.ts:140

Returns the current state as a dot-delimited path that includes any active child FSM states (e.g. "active.connecting.retrying"). Returns just the current state name when no child is active.

string


currentState(): TStateNames

Defined in: fsm.ts:119

Returns the current state name. Always defined — Fsm eagerly initializes into initialState during construction.

TStateNames


dispose(options?): void

Defined in: fsm.ts:183

Permanently shut down this FSM. Irreversible — all subsequent method calls become silent no-ops. Clears all listeners and cascades disposal to child FSMs (unless preserveChildren is set).

DisposeOptions

void


emit(eventName, data?): void

Defined in: fsm.ts:169

Emit a custom event through the FSM. Built-in lifecycle events are emitted automatically — this is for user-defined events from handlers. Routes through the BehavioralFsm so all relay paths are consistent. No-ops when disposed.

string

unknown

void


handle(inputName, …args): void

Defined in: fsm.ts:85

Dispatch an input to the current state’s handler. If a _child FSM in the current state can handle it, delegation occurs there first; unhandled inputs bubble up to the parent. No-ops silently when disposed.

TInputNames

unknown[]

void


on<K>(eventName, callback): Subscription

Defined in: fsm.ts:151

Subscribe to a built-in lifecycle event or the wildcard.

Named overload: typed payload, no event name in callback. Wildcard ("*"): receives (eventName, data) for every event. Returns a no-op Subscription when disposed.

K extends "transitioning" | "transitioned" | "handling" | "handled" | "nohandler" | "invalidstate" | "deferred"

K

(data) => void

Subscription

on(eventName, callback): Subscription

Defined in: fsm.ts:155

Subscribe to a built-in lifecycle event or the wildcard.

Named overload: typed payload, no event name in callback. Wildcard ("*"): receives (eventName, data) for every event. Returns a no-op Subscription when disposed.

"*"

(eventName, data) => void

Subscription


reset(): void

Defined in: fsm.ts:108

Transition back to initialState, firing _onEnter and lifecycle events as if entering it fresh. No-ops silently when disposed.

void


transition(toState): void

Defined in: fsm.ts:128

Directly transition to toState, firing _onExit, _onEnter, and lifecycle events. Same-state transitions are silently ignored. No-ops when disposed.

TStateNames

void