Skip to content
You're viewing the docs for v0.18. The latest version is v0.20. Go to the latest docs

@ue-too/being / index / HierarchicalStateMachine

Class: HierarchicalStateMachine<EventPayloadMapping, Context, States, EventOutputMapping> ​

Defined in: hierarchical.ts:306

Extended state machine that supports hierarchical state paths.

Remarks ​

This class extends TemplateStateMachine to track and expose hierarchical state paths when composite states are used.

Extends ​

Type Parameters ​

EventPayloadMapping ​

EventPayloadMapping = any

Event payload mapping

Context ​

Context extends BaseContext = BaseContext

Context type

States ​

States extends string = string

State names

EventOutputMapping ​

EventOutputMapping extends Partial<Record<keyof EventPayloadMapping, unknown>> = DefaultOutputMapping<EventPayloadMapping>

Event output mapping

Constructors ​

Constructor ​

new HierarchicalStateMachine<EventPayloadMapping, Context, States, EventOutputMapping>(states, initialState, context, autoStart): HierarchicalStateMachine<EventPayloadMapping, Context, States, EventOutputMapping>

Defined in: interface.ts:701

Parameters ​

states ​

Record<States, State<EventPayloadMapping, Context, States, EventOutputMapping>>

initialState ​

States

context ​

Context

autoStart ​

boolean = true

Returns ​

HierarchicalStateMachine<EventPayloadMapping, Context, States, EventOutputMapping>

Inherited from ​

TemplateStateMachine.constructor

Properties ​

_context ​

protected _context: Context

Defined in: interface.ts:683

Inherited from ​

TemplateStateMachine._context


_currentState ​

protected _currentState: "INITIAL" | "TERMINAL" | States

Defined in: interface.ts:678

Inherited from ​

TemplateStateMachine._currentState


_eventResultCallbacks ​

protected _eventResultCallbacks: EventResultCallback<EventPayloadMapping, Context, States>[]

Defined in: interface.ts:693

Inherited from ​

TemplateStateMachine._eventResultCallbacks


_happensCallbacks ​

protected _happensCallbacks: (args, context) => void[]

Defined in: interface.ts:686

Parameters ​

args ​

EventArgs<EventPayloadMapping, string> | EventArgs<EventPayloadMapping, keyof EventPayloadMapping>

context ​

Context

Returns ​

void

Inherited from ​

TemplateStateMachine._happensCallbacks


_initialState ​

protected _initialState: States

Defined in: interface.ts:699

Inherited from ​

TemplateStateMachine._initialState


_stateChangeCallbacks ​

protected _stateChangeCallbacks: StateChangeCallback<States>[]

Defined in: interface.ts:685

Inherited from ​

TemplateStateMachine._stateChangeCallbacks


_states ​

protected _states: Record<States, State<EventPayloadMapping, Context, States, EventOutputMapping>>

Defined in: interface.ts:679

Inherited from ​

TemplateStateMachine._states


_statesArray ​

protected _statesArray: States[]

Defined in: interface.ts:684

Inherited from ​

TemplateStateMachine._statesArray


_timeouts ​

protected _timeouts: number | undefined = undefined

Defined in: interface.ts:698

Inherited from ​

TemplateStateMachine._timeouts

Accessors ​

context ​

Get Signature ​

get context(): Context

Defined in: interface.ts:874

Read-only access to the machine's live context object. Optional so existing StateMachine implementations remain valid; TemplateStateMachine always provides it. Intended for tooling/introspection (e.g. visualizers evaluating guards against the current context) — mutate state through events, not through this reference.

Returns ​

Context

Read-only access to the machine's live context object. Optional so existing StateMachine implementations remain valid; TemplateStateMachine always provides it. Intended for tooling/introspection (e.g. visualizers evaluating guards against the current context) — mutate state through events, not through this reference.

Inherited from ​

TemplateStateMachine.context


currentState ​

Get Signature ​

get currentState(): "INITIAL" | "TERMINAL" | States

Defined in: interface.ts:866

Returns ​

"INITIAL" | "TERMINAL" | States

Inherited from ​

TemplateStateMachine.currentState


possibleStates ​

Get Signature ​

get possibleStates(): States[]

Defined in: interface.ts:878

Returns ​

States[]

Inherited from ​

TemplateStateMachine.possibleStates


states ​

Get Signature ​

get states(): Record<States, State<EventPayloadMapping, Context, States, EventOutputMapping>>

Defined in: interface.ts:882

Returns ​

Record<States, State<EventPayloadMapping, Context, States, EventOutputMapping>>

Inherited from ​

TemplateStateMachine.states

Methods ​

getActiveStatePath() ​

getActiveStatePath(): string[]

Defined in: hierarchical.ts:343

Gets all active states in the hierarchy. Returns an array where the first element is the top-level state, and subsequent elements are nested child states.

Returns ​

string[]


getCurrentStatePath() ​

getCurrentStatePath(): string

Defined in: hierarchical.ts:324

Gets the current hierarchical state path. Returns a simple state name for non-composite states, or a dot-notation path for composite states (e.g., "PARENT.CHILD").

Returns ​

string


happens() ​

Call Signature ​

happens<K>(...args): EventResult<States, K extends keyof EventOutputMapping ? EventOutputMapping[K<K>] : void>

Defined in: interface.ts:763

Type Parameters ​
K ​

K extends string | number | symbol

Parameters ​
args ​

...EventArgs<EventPayloadMapping, K>

Returns ​

EventResult<States, K extends keyof EventOutputMapping ? EventOutputMapping[K<K>] : void>

Inherited from ​

TemplateStateMachine.happens

Call Signature ​

happens<K>(...args): EventResult<States, unknown>

Defined in: interface.ts:769

Type Parameters ​
K ​

K extends string

Parameters ​
args ​

...EventArgs<EventPayloadMapping, K>

Returns ​

EventResult<States, unknown>

Inherited from ​

TemplateStateMachine.happens


isInStatePath() ​

isInStatePath(path): boolean

Defined in: hierarchical.ts:368

Checks if the state machine is currently in a specific hierarchical path. Supports both simple state names and dot-notation paths.

Parameters ​

path ​

string

State path to check (e.g., "PARENT" or "PARENT.CHILD")

Returns ​

boolean


onEventResult() ​

onEventResult(callback): () => void

Defined in: interface.ts:854

Subscribe to every event result. Optional so existing StateMachine implementations remain valid; TemplateStateMachine always provides it. Returns a disposer on implementations that support one. Disposing during a dispatch takes effect starting with the next dispatch, not the one in progress — see EventResultCallback for the exact snapshot-iteration semantics.

Parameters ​

callback ​

EventResultCallback<EventPayloadMapping, Context, States>

Returns ​

(): void

Returns ​

void

Inherited from ​

TemplateStateMachine.onEventResult


onHappens() ​

onHappens(callback): () => void

Defined in: interface.ts:836

Subscribe to every happens() call, before the state handles it. Returns a disposer on implementations that support one. Disposing during a dispatch takes effect starting with the next dispatch, not the one in progress — see EventResultCallback for the exact snapshot-iteration semantics.

Parameters ​

callback ​

(args, context) => void

Returns ​

(): void

Returns ​

void

Inherited from ​

TemplateStateMachine.onHappens


onStateChange() ​

onStateChange(callback): () => void

Defined in: interface.ts:826

Subscribe to state changes. Returns a disposer on implementations that support one. Disposing during a dispatch takes effect starting with the next dispatch, not the one in progress — see EventResultCallback for the exact snapshot-iteration semantics.

Parameters ​

callback ​

StateChangeCallback<States>

Returns ​

(): void

Returns ​

void

Inherited from ​

TemplateStateMachine.onStateChange


reset() ​

reset(): void

Defined in: interface.ts:723

Returns ​

void

Inherited from ​

TemplateStateMachine.reset


setContext() ​

setContext(context): void

Defined in: interface.ts:870

Parameters ​

context ​

Context

Returns ​

void

Inherited from ​

TemplateStateMachine.setContext


start() ​

start(): void

Defined in: interface.ts:729

Returns ​

void

Inherited from ​

TemplateStateMachine.start


switchTo() ​

switchTo(state): void

Defined in: interface.ts:758

Parameters ​

state ​

"INITIAL" | "TERMINAL" | States

Returns ​

void

Inherited from ​

TemplateStateMachine.switchTo


wrapup() ​

wrapup(): void

Defined in: interface.ts:742

Returns ​

void

Inherited from ​

TemplateStateMachine.wrapup