@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
TemplateStateMachine<EventPayloadMapping,Context,States,EventOutputMapping>
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
_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
_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
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,Kextends keyofEventOutputMapping?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
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
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
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
switchTo()
switchTo(
state):void
Defined in: interface.ts:647
Parameters
state
"INITIAL" | "TERMINAL" | States
Returns
void
Inherited from
wrapup()
wrapup():
void
Defined in: interface.ts:631
Returns
void