Skip to content
You're viewing the docs for v0.18. The latest version is v0.20. Go to the latest docs

@ue-too/being / index / CompositeState

Abstract Class: CompositeState<EventPayloadMapping, Context, ParentStates, ChildStates, EventOutputMapping> ​

Defined in: hierarchical.ts:106

Composite state that contains a child state machine.

Remarks ​

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.

Example ​

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>

Type Parameters ​

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

Constructors ​

Constructor ​

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

Returns ​

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

Inherited from ​

TemplateState.constructor

Properties ​

_childStateMachineConfig ​

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

Defined in: hierarchical.ts:120


_context ​

protected _context: Context | null = null

Defined in: hierarchical.ts:127


_defer ​

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

Defined in: interface.ts:1007

Inherited from ​

TemplateState._defer


_delay ​

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

Defined in: interface.ts:1003

Inherited from ​

TemplateState._delay


_eventGuards ​

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

Defined in: interface.ts:993

Inherited from ​

TemplateState._eventGuards


_eventPreconditions ​

protected _eventPreconditions: Partial<EventPreconditions<EventPayloadMapping, Context, Guard<Context>>>

Defined in: interface.ts:998

Inherited from ​

TemplateState._eventPreconditions


_eventReactions ​

protected _eventReactions: EventReactions<EventPayloadMapping, Context, States, EventOutputMapping>

Defined in: interface.ts:981

Inherited from ​

TemplateState._eventReactions


_guards ​

protected _guards: Guard<Context>

Defined in: interface.ts:992

Inherited from ​

TemplateState._guards


_historyState ​

protected _historyState: ChildStates | null = null

Defined in: hierarchical.ts:126

Accessors ​

delay ​

Get Signature ​

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

Defined in: interface.ts:1042

Returns ​

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

Inherited from ​

TemplateState.delay


eventGuards ​

Get Signature ​

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

Defined in: interface.ts:1021

Returns ​

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

Inherited from ​

TemplateState.eventGuards


eventPreconditions ​

Get Signature ​

get eventPreconditions(): Partial<EventPreconditions<EventPayloadMapping, Context, Guard<Context>>>

Defined in: 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.

Returns ​

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.

Inherited from ​

TemplateState.eventPreconditions


eventReactions ​

Get Signature ​

get eventReactions(): EventReactions<EventPayloadMapping, Context, States, EventOutputMapping>

Defined in: interface.ts:1033

Returns ​

EventReactions<EventPayloadMapping, Context, States, EventOutputMapping>

Inherited from ​

TemplateState.eventReactions


guards ​

Get Signature ​

get guards(): Guard<Context>

Defined in: interface.ts:1017

Returns ​

Guard<Context>

Inherited from ​

TemplateState.guards


handlingEvents ​

Get Signature ​

get handlingEvents(): keyof EventPayloadMapping[]

Defined in: interface.ts:1011

Returns ​

keyof EventPayloadMapping[]

Inherited from ​

TemplateState.handlingEvents

Methods ​

beforeExit() ​

beforeExit(context, stateMachine, to): void

Defined in: hierarchical.ts:217

Parameters ​

context ​

Context

stateMachine ​

StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>

to ​

"TERMINAL" | ParentStates

Returns ​

void

Overrides ​

TemplateState.beforeExit


getChildStateMachine() ​

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

Defined in: hierarchical.ts:133

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

Returns ​

ChildStateMachineConfig<EventPayloadMapping, Context, ChildStates, EventOutputMapping>


getCurrentChildState() ​

getCurrentChildState(): ChildStates | null

Defined in: hierarchical.ts:143

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

Returns ​

ChildStates | null


getStatePath() ​

getStatePath(parentState): HierarchicalStatePath<ParentStates, ChildStates>

Defined in: hierarchical.ts:164

Gets the full hierarchical path of the current state.

Parameters ​

parentState ​

ParentStates

Returns ​

HierarchicalStatePath<ParentStates, ChildStates>


handles() ​

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

Defined in: hierarchical.ts:255

Type Parameters ​

K ​

K extends string | number | symbol

Parameters ​

args ​

EventArgs<EventPayloadMapping, K>

context ​

Context

stateMachine ​

StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>

Returns ​

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

Overrides ​

TemplateState.handles


uponEnter() ​

uponEnter(context, stateMachine, from): void

Defined in: hierarchical.ts:177

Parameters ​

context ​

Context

stateMachine ​

StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>

from ​

"INITIAL" | ParentStates

Returns ​

void

Overrides ​

TemplateState.uponEnter