Skip to content

Fsm

Defined in: fsm.ts:38

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.

TBubbles extends string = never

String literal union of inputs this FSM declares via bubbles. Type-only — carried so BubblesOfInstance can extract it from a constructed instance; nothing at runtime reads this generic.

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

Defined in: fsm.ts:66

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

Fsm<TCtx, TStateNames, TInputNames, TBubbles>

readonly [MACHINA_TYPE]: "Fsm"

Defined in: fsm.ts:48


readonly context: TCtx

Defined in: fsm.ts:58


readonly id: string

Defined in: fsm.ts:45


readonly initialState: TStateNames

Defined in: fsm.ts:46


readonly states: Record<string, Record<string, unknown>>

Defined in: fsm.ts:52

canHandle(inputName): boolean

Defined in: fsm.ts:121

Returns true if the current state has a handler for inputName (or a catch-all "*" handler), or if the current state’s _child chain can handle it (checked recursively, matching handle()’s delegation reach). Does not trigger initialization or any side effects. Returns false when disposed.

string

boolean


compositeState(): string

Defined in: fsm.ts:164

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:143

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

TStateNames


dispose(options?): void

Defined in: fsm.ts:207

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:193

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:107

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:175

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:179

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:132

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:152

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

TStateNames

void