Skip to content

@ue-too/being / index / DelegatingState

Abstract Class: DelegatingState<EventPayloadMapping, Context, States, Child, EventOutputMapping> ​

Defined in: delegating-state.ts:65

A state that hosts a complete child state machine and forwards events to it.

Remarks ​

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.

Example ​

typescript
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>

Type Parameters ​

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

Constructors ​

Constructor ​

new DelegatingState<EventPayloadMapping, Context, States, Child, EventOutputMapping>(child): DelegatingState<EventPayloadMapping, Context, States, Child, EventOutputMapping>

Defined in: delegating-state.ts:81

Parameters ​

child ​

Child

Returns ​

DelegatingState<EventPayloadMapping, Context, States, Child, EventOutputMapping>

Overrides ​

TemplateState.constructor

Properties ​

_defer ​

protected _defer: Defer<Context, EventPayloadMapping, States, EventOutputMapping>

Defined in: delegating-state.ts:91

Overrides ​

TemplateState._defer


_delay ​

protected _delay: Delay<Context, EventPayloadMapping, States, 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

Accessors ​

child ​

Get Signature ​

get child(): Child

Defined in: delegating-state.ts:87

The hosted child machine, for introspection and tests.

Returns ​

Child


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: delegating-state.ts:129

Parameters ​

_context ​

Context

_stateMachine ​

StateMachine<EventPayloadMapping, Context, States, EventOutputMapping>

_to ​

"TERMINAL" | States

Returns ​

void

Overrides ​

TemplateState.beforeExit


handles() ​

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

Defined in: interface.ts:1074

Type Parameters ​

K ​

K extends string | number | symbol

Parameters ​

args ​

EventArgs<EventPayloadMapping, K>

context ​

Context

stateMachine ​

StateMachine<EventPayloadMapping, Context, States, EventOutputMapping>

Returns ​

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

Inherited from ​

TemplateState.handles


uponEnter() ​

uponEnter(_context, _stateMachine, _from): void

Defined in: delegating-state.ts:112

Parameters ​

_context ​

Context

_stateMachine ​

StateMachine<EventPayloadMapping, Context, States, EventOutputMapping>

_from ​

"INITIAL" | States

Returns ​

void

Overrides ​

TemplateState.uponEnter