Skip to content

@ue-too/being / StateMachine

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

Defined in: interface.ts:212

Description

This is the interface for the state machine. The interface takes in a few generic parameters.

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.

You can probably get by using the TemplateStateMachine class. The naming is that an event would "happen" and the state of the state machine would "handle" it.

See

Type Parameters

EventPayloadMapping

EventPayloadMapping

Context

Context extends BaseContext

States

States extends string = "IDLE"

EventOutputMapping

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

Properties

possibleStates

possibleStates: States[]

Defined in: interface.ts:243


states

states: Record<States, State<EventPayloadMapping, Context, string extends States ? string : States, EventOutputMapping>>

Defined in: interface.ts:233

Methods

happens()

Call Signature

happens<K>(...args): EventResult<States, K extends keyof EventOutputMapping ? EventOutputMapping[K<K>] : void>

Defined in: interface.ts:222

Type Parameters
K

K extends string | number | symbol

Parameters
args

...EventArgs<EventPayloadMapping, K>

Returns

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

Call Signature

happens<K>(...args): EventResult<States, unknown>

Defined in: interface.ts:229

Type Parameters
K

K extends string

Parameters
args

...EventArgs<EventPayloadMapping, K>

Returns

EventResult<States, unknown>


onHappens()

onHappens(callback): void

Defined in: interface.ts:244

Parameters

callback

(args, context) => void

Returns

void


onStateChange()

onStateChange(callback): void

Defined in: interface.ts:242

Parameters

callback

StateChangeCallback<States>

Returns

void


reset()

reset(): void

Defined in: interface.ts:253

Returns

void


setContext()

setContext(context): void

Defined in: interface.ts:232

Parameters

context

Context

Returns

void


start()

start(): void

Defined in: interface.ts:254

Returns

void


switchTo()

switchTo(state): void

Defined in: interface.ts:220

Parameters

state

States

Returns

void


wrapup()

wrapup(): void

Defined in: interface.ts:255

Returns

void