@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