Skip to content
您正在瀏覽 v0.18 的文件。最新版本為 v0.20。 前往最新文件

@ue-too/being / index / CompositeState

抽象 類別: CompositeState<EventPayloadMapping, Context, ParentStates, ChildStates, EventOutputMapping> ​

定義於: hierarchical.ts:106

Composite state that contains a child state machine.

備註 ​

A composite state is a state that contains its own internal state machine. When the composite state is active, its child state machine is also active. Events are first handled by the child state machine, and if unhandled, they bubble up to the parent state machine.

範例 ​

typescript
type ParentStates = "IDLE" | "ACTIVE";
type ChildStates = "LOADING" | "READY" | "ERROR";

class ActiveState extends CompositeState<Events, Context, ParentStates, ChildStates> {
  eventReactions = {
    stop: {
      action: () => console.log("Stopping..."),
      defaultTargetState: "IDLE"
    }
  };

  getChildStateMachine() {
    return {
      stateMachine: new TemplateStateMachine(...),
      defaultChildState: "LOADING",
      rememberHistory: true
    };
  }
}

Extends ​

  • TemplateState<EventPayloadMapping, Context, ParentStates, EventOutputMapping>

型別參數 ​

EventPayloadMapping ​

EventPayloadMapping = any

Event payload mapping

Context ​

Context extends BaseContext = BaseContext

Context type

ParentStates ​

ParentStates extends string = string

Parent state names

ChildStates ​

ChildStates extends string = string

Child state names

EventOutputMapping ​

EventOutputMapping extends Partial<Record<keyof EventPayloadMapping, unknown>> = DefaultOutputMapping<EventPayloadMapping>

Event output mapping

建構函式 ​

建構函式 ​

new CompositeState<EventPayloadMapping, Context, ParentStates, ChildStates, EventOutputMapping>(): CompositeState<EventPayloadMapping, Context, ParentStates, ChildStates, EventOutputMapping>

回傳 ​

CompositeState<EventPayloadMapping, Context, ParentStates, ChildStates, EventOutputMapping>

繼承自 ​

TemplateState.constructor

屬性 ​

_childStateMachineConfig ​

protected _childStateMachineConfig: ChildStateMachineConfig<EventPayloadMapping, Context, ChildStates, EventOutputMapping> | null = null

定義於: hierarchical.ts:120


_context ​

protected _context: Context | null = null

定義於: hierarchical.ts:127


_defer ​

protected _defer: Defer<Context, EventPayloadMapping, ParentStates, EventOutputMapping> | undefined = undefined

定義於: interface.ts:1007

繼承自 ​

TemplateState._defer


_delay ​

protected _delay: Delay<Context, EventPayloadMapping, ParentStates, EventOutputMapping> | undefined = undefined

定義於: interface.ts:1003

繼承自 ​

TemplateState._delay


_eventGuards ​

protected _eventGuards: Partial<EventGuards<EventPayloadMapping, States, Context, Guard<Context>>>

定義於: interface.ts:993

繼承自 ​

TemplateState._eventGuards


_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

繼承自 ​

TemplateState._eventReactions


_guards ​

protected _guards: Guard<Context>

定義於: interface.ts:992

繼承自 ​

TemplateState._guards


_historyState ​

protected _historyState: ChildStates | null = null

定義於: hierarchical.ts:126

存取器 ​

delay ​

Getter 簽章 ​

get delay(): Delay<Context, EventPayloadMapping, States, EventOutputMapping> | undefined

定義於: interface.ts:1042

回傳 ​

Delay<Context, EventPayloadMapping, States, EventOutputMapping> | undefined

繼承自 ​

TemplateState.delay


eventGuards ​

Getter 簽章 ​

get eventGuards(): Partial<EventGuards<EventPayloadMapping, States, Context, Guard<Context>>>

定義於: interface.ts:1021

回傳 ​

Partial<EventGuards<EventPayloadMapping, States, Context, Guard<Context>>>

繼承自 ​

TemplateState.eventGuards


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>

繼承自 ​

TemplateState.eventReactions


guards ​

Getter 簽章 ​

get guards(): Guard<Context>

定義於: interface.ts:1017

回傳 ​

Guard<Context>

繼承自 ​

TemplateState.guards


handlingEvents ​

Getter 簽章 ​

get handlingEvents(): keyof EventPayloadMapping[]

定義於: interface.ts:1011

回傳 ​

keyof EventPayloadMapping[]

繼承自 ​

TemplateState.handlingEvents

方法 ​

beforeExit() ​

beforeExit(context, stateMachine, to): void

定義於: hierarchical.ts:217

參數 ​

context ​

Context

stateMachine ​

StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>

to ​

"TERMINAL" | ParentStates

回傳 ​

void

覆寫了 ​

TemplateState.beforeExit


getChildStateMachine() ​

abstract protected getChildStateMachine(): ChildStateMachineConfig<EventPayloadMapping, Context, ChildStates, EventOutputMapping>

定義於: hierarchical.ts:133

Returns the configuration for the child state machine. Override this method to provide child state machine setup.

回傳 ​

ChildStateMachineConfig<EventPayloadMapping, Context, ChildStates, EventOutputMapping>


getCurrentChildState() ​

getCurrentChildState(): ChildStates | null

定義於: hierarchical.ts:143

Gets the current child state, or null if no child state machine is active.

回傳 ​

ChildStates | null


getStatePath() ​

getStatePath(parentState): HierarchicalStatePath<ParentStates, ChildStates>

定義於: hierarchical.ts:164

Gets the full hierarchical path of the current state.

參數 ​

parentState ​

ParentStates

回傳 ​

HierarchicalStatePath<ParentStates, ChildStates>


handles() ​

handles<K>(args, context, stateMachine): EventResult<ParentStates, K extends keyof EventOutputMapping ? EventOutputMapping[K<K>] : void>

定義於: hierarchical.ts:255

型別參數 ​

K ​

K extends string | number | symbol

參數 ​

args ​

EventArgs<EventPayloadMapping, K>

context ​

Context

stateMachine ​

StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>

回傳 ​

EventResult<ParentStates, K extends keyof EventOutputMapping ? EventOutputMapping[K<K>] : void>

覆寫了 ​

TemplateState.handles


uponEnter() ​

uponEnter(context, stateMachine, from): void

定義於: hierarchical.ts:177

參數 ​

context ​

Context

stateMachine ​

StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>

from ​

"INITIAL" | ParentStates

回傳 ​

void

覆寫了 ​

TemplateState.uponEnter