Skip to content

StateMachine <TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, TResolvedTypesMeta>

Represents logic which can be used by an actor.

Implements

Index

Constructors

constructor

Properties

__TResolvedTypesMeta

__TResolvedTypesMeta: TResolvedTypesMeta
@deprecated

an internal property acting as a "phantom" type, not meant to be used at runtime

public__xstatenode

__xstatenode: true = true

publicconfig

config: MachineConfig<TContext, TEvent, any, any, any, any, any, any, TOutput, any>

The raw config used to create the machine.

publicevents

events: EventDescriptor<TEvent>[]

publicid

id: string

publicidMap

idMap: Map<string, StateNode<TContext, TEvent>> = ...

publicimplementations

publicroot

root: StateNode<TContext, TEvent>

publicstates

states: StateNodesConfig<TContext, TEvent>

publicoptionalversion

version?: string

The machine's own version.

Accessors

publicdefinition

Methods

publicgetInitialSnapshot

  • getInitialSnapshot(actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, AnyActorSystem>, input?: TInput): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>
  • Returns the initial State instance, with reference to self as an ActorRef.


    Parameters

    • actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, AnyActorSystem>
    • optionalinput: TInput

    Returns MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>

publicgetPersistedSnapshot

  • getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, options?: unknown): Snapshot<unknown>
  • Obtains the internal state of the actor in a representation which can be be persisted. The persisted state can be restored by restoreSnapshot.


    Parameters

    • snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>

      The current state.

    • optionaloptions: unknown

    Returns Snapshot<unknown>

    The a representation of the internal state to be persisted.

publicgetStateNodeById

  • getStateNodeById(stateId: string): StateNode<TContext, TEvent>
  • Parameters

    • stateId: string

    Returns StateNode<TContext, TEvent>

publicgetTransitionData

  • getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, event: TEvent): TransitionDefinition<TContext, TEvent>[]

publicmicrostep

  • microstep(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, event: TEvent, actorScope: AnyActorScope): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>[]
  • Determines the next state given the current state and event. Calculates a microstep.


    Parameters

    • snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>
    • event: TEvent

      The received event

    • actorScope: AnyActorScope

    Returns MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>[]

publicprovide

  • provide(implementations: { [ K in string | number | symbol ]: { [K in keyof ((IsNever<Prop<Prop<Prop<TResolvedTypesMeta, "resolved">, "missingImplementations">, "actions">> extends true ? {} : { ...; }) & { ...; })]: ((IsNever<...> extends true ? {} : { ...; }) & { ...; })[K]; } & { [K in keyof ((IsNever<Prop<Prop<Prop<TResolvedTypesMeta, "resolved">, "missingImplementations">, "actors">> extends true ? {} : { ...; }) & { ...; })]: ((IsNever<...> extends true ? {} : { ...; }) & { ...; })[K]; } & { [K in keyof ((IsNever<Prop<Prop<Prop<TResolvedTypesMeta, "resolved">, "missingImplementations">, "delays">> extends true ? {} : { ...; }) & { ...; })]: ((IsNever<...> extends true ? {} : { ...; }) & { ...; })[K]; } & { [K in keyof ((IsNever<Prop<Prop<Prop<TResolvedTypesMeta, "resolved">, "missingImplementations">, "guards">> extends true ? {} : { ...; }) & { ...; })]: ((IsNever<...> extends true ? {} : { ...; }) & { ...; })[K]; }[K] }): StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>
  • Clones this state machine with the provided implementations and merges the context (if provided).


    Parameters

    • implementations: { [ K in string | number | symbol ]: { [K in keyof ((IsNever<Prop<Prop<Prop<TResolvedTypesMeta, "resolved">, "missingImplementations">, "actions">> extends true ? {} : { ...; }) & { ...; })]: ((IsNever<...> extends true ? {} : { ...; }) & { ...; })[K]; } & { [K in keyof ((IsNever<Prop<Prop<Prop<TResolvedTypesMeta, "resolved">, "missingImplementations">, "actors">> extends true ? {} : { ...; }) & { ...; })]: ((IsNever<...> extends true ? {} : { ...; }) & { ...; })[K]; } & { [K in keyof ((IsNever<Prop<Prop<Prop<TResolvedTypesMeta, "resolved">, "missingImplementations">, "delays">> extends true ? {} : { ...; }) & { ...; })]: ((IsNever<...> extends true ? {} : { ...; }) & { ...; })[K]; } & { [K in keyof ((IsNever<Prop<Prop<Prop<TResolvedTypesMeta, "resolved">, "missingImplementations">, "guards">> extends true ? {} : { ...; }) & { ...; })]: ((IsNever<...> extends true ? {} : { ...; }) & { ...; })[K]; }[K] }

      Options (actions, guards, actors, delays, context) to recursively merge with the existing options.

    Returns StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>

    A new StateMachine instance with the provided implementations.

publicresolveState

  • resolveState(config: { context?: TContext; error?: unknown; historyValue?: HistoryValue<TContext, TEvent>; output?: TOutput; status?: error | active | done | stopped; value: StateValue } & (Equals<TContext, MachineContext> extends false ? { context: unknown } : {})): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>
  • Parameters

    • config: { context?: TContext; error?: unknown; historyValue?: HistoryValue<TContext, TEvent>; output?: TOutput; status?: error | active | done | stopped; value: StateValue } & (Equals<TContext, MachineContext> extends false ? { context: unknown } : {})

    Returns MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>

publicrestoreSnapshot

  • restoreSnapshot(snapshot: Snapshot<unknown>, _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, AnyActorSystem>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>
  • Called when Actor is created to restore the internal state of the actor given a persisted state. The persisted state can be created by getPersistedSnapshot.


    Parameters

    • snapshot: Snapshot<unknown>

      The persisted state to restore from.

    • _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, AnyActorSystem>

      The actor scope.

    Returns MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>

    The restored state.

publicstart

  • start(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>): void
  • Called when the actor is started.


    Parameters

    • snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>

      The starting state.

    Returns void

publictoJSON

publictransition

  • transition(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, event: TEvent, actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, AnyActorSystem>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>
  • Determines the next snapshot given the current snapshot and received event. Calculates a full macrostep from all microsteps.


    Parameters

    • snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>

      The current snapshot

    • event: TEvent

      The received event

    • actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, AnyActorSystem>

    Returns MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>