@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>
プロパティ
currentState
currentState:
States|"INITIAL"|"TERMINAL"
定義: interface.ts:256
possibleStates
possibleStates:
States[]
定義: interface.ts:243
states
states:
Record<States,State<EventPayloadMapping,Context,stringextendsStates?string:States,EventOutputMapping>>
定義: interface.ts:233
メソッド
happens()
コールシグネチャ
happens<
K>(...args):EventResult<States,Kextends keyofEventOutputMapping?EventOutputMapping[K<K>] :void>
定義: interface.ts:222
型パラメーター
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:229
型パラメーター
K
K extends string
パラメータ
args
...EventArgs<EventPayloadMapping, K>
戻り値
EventResult<States, unknown>
onHappens()
onHappens(
callback):void
定義: interface.ts:244
パラメータ
callback
(args, context) => void
戻り値
void
onStateChange()
onStateChange(
callback):void
定義: interface.ts:242
パラメータ
callback
StateChangeCallback<States>
戻り値
void
reset()
reset():
void
定義: interface.ts:253
戻り値
void
setContext()
setContext(
context):void
定義: interface.ts:232
パラメータ
context
Context
戻り値
void
start()
start():
void
定義: interface.ts:254
戻り値
void
switchTo()
switchTo(
state):void
定義: interface.ts:220
パラメータ
state
States
戻り値
void
wrapup()
wrapup():
void
定義: interface.ts:255
戻り値
void