Skip to content

@ue-too/being / index / StateMachine

介面: StateMachine<EventPayloadMapping, Context, States, EventOutputMapping> ​

定義於: interface.ts:212

Description ​

This is the interface for the state machine. The interface takes in a few generic parameters.

Generic parameters:

  • EventPayloadMapping: A mapping of events to their payloads.
  • Context: The context of the state machine. (which can be used by each state to do calculations that would persist across states)
  • States: All of the possible states that the state machine can be in. e.g. a string literal union like "IDLE" | "SELECTING" | "PAN" | "ZOOM"
  • EventOutputMapping: A mapping of events to their output types. Defaults to void for all events.

You can probably get by using the TemplateStateMachine class. The naming is that an event would "happen" and the state of the state machine would "handle" it.

參閱 ​

型別參數 ​

EventPayloadMapping ​

EventPayloadMapping

Context ​

Context extends BaseContext

States ​

States extends string = "IDLE"

EventOutputMapping ​

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

屬性 ​

context? ​

readonly optional context: Context

定義於: interface.ts:229

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.


currentState ​

currentState: States | "INITIAL" | "TERMINAL"

定義於: interface.ts:289


possibleStates ​

possibleStates: States[]

定義於: interface.ts:258


states ​

states: Record<States, State<EventPayloadMapping, Context, string extends States ? string : States, EventOutputMapping>>

定義於: interface.ts:242

方法 ​

happens() ​

呼叫簽章 ​

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

定義於: interface.ts:231

型別參數 ​
K ​

K extends string | number | symbol

參數 ​
args ​

...EventArgs<EventPayloadMapping, K>

回傳 ​

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

呼叫簽章 ​

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

定義於: interface.ts:238

型別參數 ​
K ​

K extends string

參數 ​
args ​

...EventArgs<EventPayloadMapping, K>

回傳 ​

EventResult<States, unknown>


onEventResult()? ​

optional onEventResult(callback): void | () => void

定義於: interface.ts:283

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


onHappens() ​

onHappens(callback): void | () => void

定義於: interface.ts:266

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


onStateChange() ​

onStateChange(callback): void | () => void

定義於: interface.ts:257

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


reset() ​

reset(): void

定義於: interface.ts:286

回傳 ​

void


setContext() ​

setContext(context): void

定義於: interface.ts:241

參數 ​

context ​

Context

回傳 ​

void


start() ​

start(): void

定義於: interface.ts:287

回傳 ​

void


switchTo() ​

switchTo(state): void

定義於: interface.ts:220

參數 ​

state ​

States

回傳 ​

void


wrapup() ​

wrapup(): void

定義於: interface.ts:288

回傳 ​

void