@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.
参照
- TemplateStateMachine
- KmtInputStateMachine
型パラメーター
EventPayloadMapping
EventPayloadMapping
Context
Context extends BaseContext
States
States extends string = "IDLE"
EventOutputMapping
EventOutputMapping extends Partial<Record<keyof EventPayloadMapping, unknown>> = DefaultOutputMapping<EventPayloadMapping>
プロパティ
context?
readonlyoptionalcontext: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,stringextendsStates?string:States,EventOutputMapping>>
定義: interface.ts:242
メソッド
happens()
コールシグネチャ
happens<
K>(...args):EventResult<States,Kextends keyofEventOutputMapping?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()?
optionalonEventResult(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