Interface State<EventPayloadMapping, Context, States>

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"

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.

interface State<
    EventPayloadMapping,
    Context extends BaseContext,
    States extends string = "IDLE",
> {
    eventGuards: Partial<
        EventGuards<
            EventPayloadMapping,
            States,
            Context,
            Guard<Context, string>,
        >,
    >;
    eventReactions: EventReactions<EventPayloadMapping, Context, States>;
    guards: Guard<Context>;
    handles<K extends string | number | symbol>(
        event: K,
        payload: EventPayloadMapping[K],
        context: Context,
    ): States;
    uponEnter(context: Context): void;
    uponLeave(context: Context): void;
}

Type Parameters

  • EventPayloadMapping
  • Context extends BaseContext
  • States extends string = "IDLE"

Implemented by

Properties

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

Methods