Skip to content

@ue-too/being / 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:591

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

Inherited from

TemplateStateMachine._context


_currentState

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

Defined in: interface.ts:573

Inherited from

TemplateStateMachine._currentState


_happensCallbacks

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

Defined in: interface.ts:581

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

Inherited from

TemplateStateMachine._initialState


_stateChangeCallbacks

protected _stateChangeCallbacks: StateChangeCallback<States>[]

Defined in: interface.ts:580

Inherited from

TemplateStateMachine._stateChangeCallbacks


_states

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

Defined in: interface.ts:574

Inherited from

TemplateStateMachine._states


_statesArray

protected _statesArray: States[]

Defined in: interface.ts:579

Inherited from

TemplateStateMachine._statesArray


_timeouts

protected _timeouts: number | undefined = undefined

Defined in: interface.ts:588

Inherited from

TemplateStateMachine._timeouts

Accessors

currentState

Get Signature

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

Defined in: interface.ts:722

Returns

"INITIAL" | "TERMINAL" | States

Inherited from

TemplateStateMachine.currentState


possibleStates

Get Signature

get possibleStates(): States[]

Defined in: interface.ts:730

Returns

States[]

Inherited from

TemplateStateMachine.possibleStates


states

Get Signature

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

Defined in: interface.ts:734

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

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

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


onHappens()

onHappens(callback): void

Defined in: interface.ts:710

Parameters

callback

(args, context) => void

Returns

void

Inherited from

TemplateStateMachine.onHappens


onStateChange()

onStateChange(callback): void

Defined in: interface.ts:706

Parameters

callback

StateChangeCallback<States>

Returns

void

Inherited from

TemplateStateMachine.onStateChange


reset()

reset(): void

Defined in: interface.ts:612

Returns

void

Inherited from

TemplateStateMachine.reset


setContext()

setContext(context): void

Defined in: interface.ts:726

Parameters

context

Context

Returns

void

Inherited from

TemplateStateMachine.setContext


start()

start(): void

Defined in: interface.ts:618

Returns

void

Inherited from

TemplateStateMachine.start


switchTo()

switchTo(state): void

Defined in: interface.ts:647

Parameters

state

"INITIAL" | "TERMINAL" | States

Returns

void

Inherited from

TemplateStateMachine.switchTo


wrapup()

wrapup(): void

Defined in: interface.ts:631

Returns

void

Inherited from

TemplateStateMachine.wrapup