Skip to content
您正在瀏覽 v0.18 的文件。最新版本為 v0.20。 前往最新文件

@ue-too/being / index / HierarchicalStateMachine

類別: HierarchicalStateMachine<EventPayloadMapping, Context, States, EventOutputMapping> ​

定義於: hierarchical.ts:306

Extended state machine that supports hierarchical state paths.

備註 ​

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

Extends ​

型別參數 ​

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

建構函式 ​

建構函式 ​

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

定義於: interface.ts:701

參數 ​

states ​

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

initialState ​

States

context ​

Context

autoStart ​

boolean = true

回傳 ​

HierarchicalStateMachine<EventPayloadMapping, Context, States, EventOutputMapping>

繼承自 ​

TemplateStateMachine.constructor

屬性 ​

_context ​

protected _context: Context

定義於: interface.ts:683

繼承自 ​

TemplateStateMachine._context


_currentState ​

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

定義於: interface.ts:678

繼承自 ​

TemplateStateMachine._currentState


_eventResultCallbacks ​

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

定義於: interface.ts:693

繼承自 ​

TemplateStateMachine._eventResultCallbacks


_happensCallbacks ​

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

定義於: interface.ts:686

參數 ​

args ​

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

context ​

Context

回傳 ​

void

繼承自 ​

TemplateStateMachine._happensCallbacks


_initialState ​

protected _initialState: States

定義於: interface.ts:699

繼承自 ​

TemplateStateMachine._initialState


_stateChangeCallbacks ​

protected _stateChangeCallbacks: StateChangeCallback<States>[]

定義於: interface.ts:685

繼承自 ​

TemplateStateMachine._stateChangeCallbacks


_states ​

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

定義於: interface.ts:679

繼承自 ​

TemplateStateMachine._states


_statesArray ​

protected _statesArray: States[]

定義於: interface.ts:684

繼承自 ​

TemplateStateMachine._statesArray


_timeouts ​

protected _timeouts: number | undefined = undefined

定義於: interface.ts:698

繼承自 ​

TemplateStateMachine._timeouts

存取器 ​

context ​

Getter 簽章 ​

get context(): Context

定義於: 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.

回傳 ​

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.

繼承自 ​

TemplateStateMachine.context


currentState ​

Getter 簽章 ​

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

定義於: interface.ts:866

回傳 ​

"INITIAL" | "TERMINAL" | States

繼承自 ​

TemplateStateMachine.currentState


possibleStates ​

Getter 簽章 ​

get possibleStates(): States[]

定義於: interface.ts:878

回傳 ​

States[]

繼承自 ​

TemplateStateMachine.possibleStates


states ​

Getter 簽章 ​

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

定義於: interface.ts:882

回傳 ​

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

繼承自 ​

TemplateStateMachine.states

方法 ​

getActiveStatePath() ​

getActiveStatePath(): string[]

定義於: 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.

回傳 ​

string[]


getCurrentStatePath() ​

getCurrentStatePath(): string

定義於: 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").

回傳 ​

string


happens() ​

呼叫簽章 ​

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

定義於: interface.ts:763

型別參數 ​
K ​

K extends string | number | symbol

參數 ​
args ​

...EventArgs<EventPayloadMapping, K>

回傳 ​

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

繼承自 ​

TemplateStateMachine.happens

呼叫簽章 ​

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

定義於: interface.ts:769

型別參數 ​
K ​

K extends string

參數 ​
args ​

...EventArgs<EventPayloadMapping, K>

回傳 ​

EventResult<States, unknown>

繼承自 ​

TemplateStateMachine.happens


isInStatePath() ​

isInStatePath(path): boolean

定義於: hierarchical.ts:368

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

參數 ​

path ​

string

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

回傳 ​

boolean


onEventResult() ​

onEventResult(callback): () => void

定義於: 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.

參數 ​

callback ​

EventResultCallback<EventPayloadMapping, Context, States>

回傳 ​

(): void

回傳 ​

void

繼承自 ​

TemplateStateMachine.onEventResult


onHappens() ​

onHappens(callback): () => void

定義於: 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.

參數 ​

callback ​

(args, context) => void

回傳 ​

(): void

回傳 ​

void

繼承自 ​

TemplateStateMachine.onHappens


onStateChange() ​

onStateChange(callback): () => void

定義於: 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.

參數 ​

callback ​

StateChangeCallback<States>

回傳 ​

(): void

回傳 ​

void

繼承自 ​

TemplateStateMachine.onStateChange


reset() ​

reset(): void

定義於: interface.ts:723

回傳 ​

void

繼承自 ​

TemplateStateMachine.reset


setContext() ​

setContext(context): void

定義於: interface.ts:870

參數 ​

context ​

Context

回傳 ​

void

繼承自 ​

TemplateStateMachine.setContext


start() ​

start(): void

定義於: interface.ts:729

回傳 ​

void

繼承自 ​

TemplateStateMachine.start


switchTo() ​

switchTo(state): void

定義於: interface.ts:758

參數 ​

state ​

"INITIAL" | "TERMINAL" | States

回傳 ​

void

繼承自 ​

TemplateStateMachine.switchTo


wrapup() ​

wrapup(): void

定義於: interface.ts:742

回傳 ​

void

繼承自 ​

TemplateStateMachine.wrapup