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.
Type Parameters
Section titled “Type Parameters”TCtx extends object
The context type, inferred from config.context.
TStateNames
Section titled “TStateNames”TStateNames extends string
String literal union of valid state names.
TInputNames
Section titled “TInputNames”TInputNames extends string
String literal union of valid input names.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Fsm<
TCtx,TStateNames,TInputNames>(config):Fsm<TCtx,TStateNames,TInputNames>
Defined in: fsm.ts:57
Parameters
Section titled “Parameters”config
Section titled “config”FsmConfig<TCtx, Record<string, Record<string, unknown>>>
Returns
Section titled “Returns”Fsm<TCtx, TStateNames, TInputNames>
Properties
Section titled “Properties”[MACHINA_TYPE]
Section titled “[MACHINA_TYPE]”
readonly[MACHINA_TYPE]:"Fsm"
Defined in: fsm.ts:39
context
Section titled “context”
readonlycontext:TCtx
Defined in: fsm.ts:49
readonlyid:string
Defined in: fsm.ts:36
initialState
Section titled “initialState”
readonlyinitialState:TStateNames
Defined in: fsm.ts:37
states
Section titled “states”
readonlystates:Record<string,Record<string,unknown>>
Defined in: fsm.ts:43
Methods
Section titled “Methods”canHandle()
Section titled “canHandle()”canHandle(
inputName):boolean
Defined in: fsm.ts:110
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.
Parameters
Section titled “Parameters”inputName
Section titled “inputName”string
Returns
Section titled “Returns”boolean
compositeState()
Section titled “compositeState()”compositeState():
string
Defined in: fsm.ts:153
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.
Returns
Section titled “Returns”string
currentState()
Section titled “currentState()”currentState():
TStateNames
Defined in: fsm.ts:132
Returns the current state name. Always defined — Fsm eagerly
initializes into initialState during construction.
Returns
Section titled “Returns”TStateNames
dispose()
Section titled “dispose()”dispose(
options?):void
Defined in: fsm.ts:196
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).
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”void
emit()
Section titled “emit()”emit(
eventName,data?):void
Defined in: fsm.ts:182
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.
Parameters
Section titled “Parameters”eventName
Section titled “eventName”string
unknown
Returns
Section titled “Returns”void
handle()
Section titled “handle()”handle(
inputName, …args):void
Defined in: fsm.ts:98
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.
Parameters
Section titled “Parameters”inputName
Section titled “inputName”TInputNames
…unknown[]
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”on<
K>(eventName,callback):Subscription
Defined in: fsm.ts:164
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.
Type Parameters
Section titled “Type Parameters”K extends "transitioning" | "transitioned" | "handling" | "handled" | "nohandler" | "invalidstate" | "deferred"
Parameters
Section titled “Parameters”eventName
Section titled “eventName”K
callback
Section titled “callback”(data) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”on(
eventName,callback):Subscription
Defined in: fsm.ts:168
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.
Parameters
Section titled “Parameters”eventName
Section titled “eventName”"*"
callback
Section titled “callback”(eventName, data) => void
Returns
Section titled “Returns”reset()
Section titled “reset()”reset():
void
Defined in: fsm.ts:121
Transition back to initialState, firing _onEnter and lifecycle
events as if entering it fresh. No-ops silently when disposed.
Returns
Section titled “Returns”void
transition()
Section titled “transition()”transition(
toState):void
Defined in: fsm.ts:141
Directly transition to toState, firing _onExit, _onEnter, and
lifecycle events. Same-state transitions are silently ignored.
No-ops when disposed.
Parameters
Section titled “Parameters”toState
Section titled “toState”TStateNames
Returns
Section titled “Returns”void