Skip to content

@ue-too/being / 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:854

Inherited from

TemplateState._defer


_delay

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

Defined in: interface.ts:850

Inherited from

TemplateState._delay


_eventGuards

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

Defined in: interface.ts:845

Inherited from

TemplateState._eventGuards


_eventReactions

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

Defined in: interface.ts:833

Inherited from

TemplateState._eventReactions


_guards

protected _guards: Guard<Context>

Defined in: interface.ts:844

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:883

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:868

Returns

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

Inherited from

TemplateState.eventGuards


eventReactions

Get Signature

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

Defined in: interface.ts:874

Returns

EventReactions<EventPayloadMapping, Context, States, EventOutputMapping>

Inherited from

TemplateState.eventReactions


guards

Get Signature

get guards(): Guard<Context>

Defined in: interface.ts:864

Returns

Guard<Context>

Inherited from

TemplateState.guards


handlingEvents

Get Signature

get handlingEvents(): keyof EventPayloadMapping[]

Defined in: interface.ts:858

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