Skip to content

@ue-too/being / State

Interface: State<EventPayloadMapping, Context, States, EventOutputMapping>

Defined in: interface.ts:285

Description

This is the interface for the state. The interface takes in a few generic parameters: You can probably get by extending the TemplateState class.

Generic parameters:

  • EventPayloadMapping: A mapping of events to their payloads.
  • Context: The context of the state machine. (which can be used by each state to do calculations that would persist across states)
  • States: All of the possible states that the state machine can be in. e.g. a string literal union like "IDLE" | "SELECTING" | "PAN" | "ZOOM"
  • EventOutputMapping: A mapping of events to their output types. Defaults to void for all events.

A state's all possible states can be only a subset of the possible states of the state machine. (a state only needs to know what states it can transition to) This allows for a state to be reusable across different state machines.

See

TemplateState

Type Parameters

EventPayloadMapping

EventPayloadMapping

Context

Context extends BaseContext

States

States extends string = "IDLE"

EventOutputMapping

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

Properties

delay

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

Defined in: interface.ts:331


eventGuards

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

Defined in: interface.ts:328


eventReactions

eventReactions: EventReactions<EventPayloadMapping, Context, States, EventOutputMapping>

Defined in: interface.ts:334


guards

guards: Guard<Context>

Defined in: interface.ts:327

Methods

beforeExit()

beforeExit(context, stateMachine, to): void

Defined in: interface.ts:303

Parameters

context

Context

stateMachine

StateMachine<EventPayloadMapping, Context, States, EventOutputMapping>

to

States | "TERMINAL"

Returns

void


handles()

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

Defined in: interface.ts:313

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>


uponEnter()

uponEnter(context, stateMachine, from): void

Defined in: interface.ts:293

Parameters

context

Context

stateMachine

StateMachine<EventPayloadMapping, Context, States, EventOutputMapping>

from

States | "INITIAL"

Returns

void