@ue-too/being / index / DelegatingState
抽象 類別: DelegatingState<EventPayloadMapping, Context, States, Child, EventOutputMapping>
A state that hosts a complete child state machine and forwards events to it.
備註
This is the composition primitive for nesting one machine inside another. While the parent machine is in a DelegatingState, every event is offered to the child first. When the child handles it, the child's output is returned and the parent stays in this state; the child's own nextState is deliberately dropped because it names a child state, not a parent one. When the child does not handle the event, the state's own _eventReactions get their turn, which is how a subclass declares its exits.
Lifecycle is tied to the parent state: entering starts (or restarts) the child from its initial state, leaving calls wrapup() on it. Subclasses that override uponEnter or beforeExit must call super.
範例
class MoveState extends DelegatingState<AppEvents, BaseContext, AppStates, KmtInputStateMachine> {
constructor(context: KmtInputContext) {
super(createKmtInputStateMachine(context));
}
protected _eventReactions = {
switchToApp: { action: NO_OP, defaultTargetState: 'IDLE' },
};
}Extends
TemplateState<EventPayloadMapping,Context,States,EventOutputMapping>
型別參數
EventPayloadMapping
EventPayloadMapping
The parent machine's event mapping
Context
Context extends BaseContext
The parent machine's context
States
States extends string
The parent machine's state union
Child
Child extends HostableStateMachine
The child machine type, exposed through DelegatingState.child
EventOutputMapping
EventOutputMapping extends Partial<Record<keyof EventPayloadMapping, unknown>> = DefaultOutputMapping<EventPayloadMapping>
The parent machine's output mapping
建構函式
建構函式
new DelegatingState<
EventPayloadMapping,Context,States,Child,EventOutputMapping>(child):DelegatingState<EventPayloadMapping,Context,States,Child,EventOutputMapping>
參數
child
Child
回傳
DelegatingState<EventPayloadMapping, Context, States, Child, EventOutputMapping>
覆寫了
屬性
_defer
protected_defer:Defer<Context,EventPayloadMapping,States,EventOutputMapping>
覆寫了
_delay
protected_delay:Delay<Context,EventPayloadMapping,States,EventOutputMapping> |undefined=undefined
定義於: interface.ts:1003
繼承自
_eventGuards
protected_eventGuards:Partial<EventGuards<EventPayloadMapping,States,Context,Guard<Context>>>
定義於: interface.ts:993
繼承自
_eventPreconditions
protected_eventPreconditions:Partial<EventPreconditions<EventPayloadMapping,Context,Guard<Context>>>
定義於: interface.ts:998
繼承自
TemplateState._eventPreconditions
_eventReactions
protected_eventReactions:EventReactions<EventPayloadMapping,Context,States,EventOutputMapping>
定義於: interface.ts:981
繼承自
_guards
protected_guards:Guard<Context>
定義於: interface.ts:992
繼承自
存取器
child
Getter 簽章
get child():
Child
The hosted child machine, for introspection and tests.
回傳
Child
delay
Getter 簽章
get delay():
Delay<Context,EventPayloadMapping,States,EventOutputMapping> |undefined
定義於: interface.ts:1042
回傳
Delay<Context, EventPayloadMapping, States, EventOutputMapping> | undefined
繼承自
eventGuards
Getter 簽章
get eventGuards():
Partial<EventGuards<EventPayloadMapping,States,Context,Guard<Context>>>
定義於: interface.ts:1021
回傳
Partial<EventGuards<EventPayloadMapping, States, Context, Guard<Context>>>
繼承自
eventPreconditions
Getter 簽章
get eventPreconditions():
Partial<EventPreconditions<EventPayloadMapping,Context,Guard<Context>>>
定義於: interface.ts:1027
Pre-action vetoes: named guards that must all pass before this state handles an event. Optional so existing State implementations remain valid; TemplateState always provides it.
回傳
Partial<EventPreconditions<EventPayloadMapping, Context, Guard<Context>>>
Pre-action vetoes: named guards that must all pass before this state handles an event. Optional so existing State implementations remain valid; TemplateState always provides it.
繼承自
TemplateState.eventPreconditions
eventReactions
Getter 簽章
get eventReactions():
EventReactions<EventPayloadMapping,Context,States,EventOutputMapping>
定義於: interface.ts:1033
回傳
EventReactions<EventPayloadMapping, Context, States, EventOutputMapping>
繼承自
guards
Getter 簽章
get guards():
Guard<Context>
定義於: interface.ts:1017
回傳
Guard<Context>
繼承自
handlingEvents
Getter 簽章
get handlingEvents(): keyof
EventPayloadMapping[]
定義於: interface.ts:1011
回傳
keyof EventPayloadMapping[]
繼承自
方法
beforeExit()
beforeExit(
_context,_stateMachine,_to):void
參數
_context
Context
_stateMachine
StateMachine<EventPayloadMapping, Context, States, EventOutputMapping>
_to
"TERMINAL" | States
回傳
void
覆寫了
handles()
handles<
K>(args,context,stateMachine):EventResult<States,Kextends keyofEventOutputMapping?EventOutputMapping[K<K>] :void>
定義於: interface.ts:1074
型別參數
K
K extends string | number | symbol
參數
args
EventArgs<EventPayloadMapping, K>
context
Context
stateMachine
StateMachine<EventPayloadMapping, Context, States, EventOutputMapping>
回傳
EventResult<States, K extends keyof EventOutputMapping ? EventOutputMapping[K<K>] : void>
繼承自
uponEnter()
uponEnter(
_context,_stateMachine,_from):void
參數
_context
Context
_stateMachine
StateMachine<EventPayloadMapping, Context, States, EventOutputMapping>
_from
"INITIAL" | States
回傳
void