@ue-too/board / index / expandKmtInputStateMachine
関数: expandKmtInputStateMachine()
expandKmtInputStateMachine<
E,C,S,O>(context,define,initialState):TemplateStateMachine<E,C,S,O>
定義: packages/board/src/input-interpretation/input-state-machine/kmt-input-state-machine.ts:862
Builds a KMT input state machine with more events, states, context or outputs than the stock one, reusing every built-in state.
型パラメーター
E
E extends KmtInputEventMapping
C
C extends KmtInputContext
S
S extends string
O
O extends KmtInputEventOutputMapping & Partial<Record<keyof E, unknown>>
パラメータ
context
C
The expanded context; must satisfy KmtInputContext
define
["IDLE" | "READY_TO_PAN_VIA_SPACEBAR" | "READY_TO_PAN_VIA_SCROLL_WHEEL" | "PAN" | "INITIAL_PAN" | "PAN_VIA_SCROLL_WHEEL" | "DISABLED"] extends [S] ? KmtInputStateMachineExpansion<E, C, S, O> : object
Receives the stock states and an extend helper, returns the expanded state map. See KmtInputStateMachineExpansion.
initialState
S = ...
Defaults to 'IDLE'
戻り値
TemplateStateMachine<E, C, S, O>
A machine over the expanded generics
Remarks
The generics must be supersets of the stock ones: E extends KmtInputEventMapping, C extends KmtInputContext, O extends KmtInputEventOutputMapping, and S must include every KmtInputStates member (a type error otherwise). Shared events must keep the stock payload. Untouched stock states keep their stock behaviour and simply ignore events they do not know.
例
type ExpEvents = KmtInputEventMapping & { rightPointerUp: PointerEventPayload };
type ExpStates = KmtInputStates | 'PLACEMENT';
type ExpOut = KmtInputEventOutputMapping & { rightPointerUp: KmtOutputEvent };
const machine = expandKmtInputStateMachine<ExpEvents, ExpContext, ExpStates, ExpOut>(
context,
(stock, extend) => ({
...stock,
IDLE: extend(stock.IDLE, {
eventReactions: { rightPointerUp: { action: openMenu, defaultTargetState: 'PLACEMENT' } },
}),
PLACEMENT: new PlacementState(),
})
);