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:48
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:38
readonlyid:string
Defined in: fsm.ts:36
Methods
Section titled “Methods”canHandle()
Section titled “canHandle()”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.
Parameters
Section titled “Parameters”inputName
Section titled “inputName”string
Returns
Section titled “Returns”boolean
compositeState()
Section titled “compositeState()”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.
Returns
Section titled “Returns”string
currentState()
Section titled “currentState()”currentState():
TStateNames
Defined in: fsm.ts:119
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: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).
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: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.
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: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.
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: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.
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: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.
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:108
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:128
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