Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface StateMachine<TContext, TStateSchema, TEvent, TTypestate>

Type parameters

Hierarchy

  • StateNode<TContext, TStateSchema, TEvent, TTypestate>
    • StateMachine

Index

Constructors

constructor

Properties

__xstatenode

__xstatenode: true = true

activities

activities: Array<ActivityDefinition<TContext, TEvent>>

The activities to be started upon entering the state node, and stopped upon exiting the state node.

config

config: StateNodeConfig<TContext, TStateSchema, TEvent>

The raw config used to create the machine.

context

context: Readonly<TContext>

The initial extended state

delimiter

delimiter: string

The string delimiter for serializing the path to a string. The default is "."

Optional doneData

doneData: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>

The data sent with the "done.state.id" event if this is a final state node.

history

history: false | "shallow" | "deep"

The type of history on this state node. Can be:

  • 'shallow' - recalls only top-level historical state value
  • 'deep' - recalls historical state value at all levels

id

id: string

Optional initial

initial: keyof TStateSchema["states"]

The initial state node key.

invoke

invoke: Array<InvokeDefinition<TContext, TEvent>>

The services invoked by this state node.

key

key: string

The relative key of the state node, which represents its location in the overall state value.

machine

machine: StateNode<TContext, any, TEvent, TTypestate>

The root machine node.

Optional meta

meta: TStateSchema extends { meta: infer D } ? D : any

The meta data associated with this state node, which will be returned in State instances.

onEntry

onEntry: Array<ActionObject<TContext, TEvent>>

The action(s) to be executed upon entering the state node.

onExit

onExit: Array<ActionObject<TContext, TEvent>>

The action(s) to be executed upon exiting the state node.

options

options: MachineOptions<TContext, TEvent>

order

order: number = -1

The order this state node appears. Corresponds to the implicit SCXML document order.

Optional parallel

parallel: undefined | false | true

(DEPRECATED) Whether the state node is a parallel state node.

Use type: 'parallel' instead.

Optional parent

parent: StateNode<TContext, any, TEvent, any>

The parent state node.

path

path: string[]

The string path from the root machine node to this node.

schema

schema: MachineSchema<TContext, TEvent>

states

states: StateNode<TContext, TStateSchema, TEvent>["states"]

strict

strict: boolean

type

type: "atomic" | "compound" | "parallel" | "final" | "history"

The type of this state node:

  • 'atomic' - no child state nodes
  • 'compound' - nested child state nodes (XOR)
  • 'parallel' - orthogonal nested child state nodes (AND)
  • 'history' - history state node
  • 'final' - final state node

Optional version

version: undefined | string

The machine's own version.

Accessors

after

definition

events

  • get events(): Array<TEvent["type"]>
  • All the event types accepted by this state node and its descendants.

    Returns Array<TEvent["type"]>

initialState

  • get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>
  • The initial State instance, which includes all actions to be executed from entering the initial state.

    Returns State<TContext, TEvent, TStateSchema, TTypestate>

initialStateNodes

  • get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>

on

ownEvents

  • get ownEvents(): Array<TEvent["type"]>
  • All the events that have transitions directly from this state node.

    Excludes any inert events.

    Returns Array<TEvent["type"]>

stateIds

  • get stateIds(): string[]

target

  • The target state value of the history state node, if it exists. This represents the default state value to transition to if no history value exists yet.

    Returns StateValue | undefined

transitions

Methods

getFromRelativePath

  • getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>

getInitialState

getRelativeStateNodes

  • getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>
  • Returns the leaf nodes from a state path relative to this state node.

    Parameters

    • relativeStateId: StateNode<TContext, any, TEvent>

      The relative state path to retrieve the state nodes

    • Optional historyValue: HistoryValue
    • Default value resolve: boolean = true

      Whether state nodes should resolve to initial child state nodes

    Returns Array<StateNode<TContext, any, TEvent>>

getStateNode

  • getStateNode(stateKey: string): StateNode<TContext, any, TEvent>

getStateNodeById

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

getStateNodeByPath

  • getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>
  • Returns the relative state node from the given statePath, or throws.

    Parameters

    • statePath: string | string[]

      The string or string array relative path to the state node.

    Returns StateNode<TContext, any, TEvent, any>

getStateNodes

  • getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, any>>

handles

  • handles(event: Event<TEvent>): boolean
  • Returns true if this state node explicitly handles the given event.

    Parameters

    • event: Event<TEvent>

      The event in question

    Returns boolean

resolve

resolveState

  • resolveState(state: State<TContext, TEvent, any, any>): State<TContext, TEvent, TStateSchema, TTypestate>
  • Resolves the given state to a new State instance relative to this machine.

    This ensures that .events and .nextEvents represent the correct values.

    Parameters

    • state: State<TContext, TEvent, any, any>

      The state to resolve

    Returns State<TContext, TEvent, TStateSchema, TTypestate>

toJSON

transition

  • Determines the next state given the current state and sent event.

    Parameters

    • Default value state: StateValue | State<TContext, TEvent, any, TTypestate> = this.initialState

      The current State instance or state value

    • event: Event<TEvent> | Event<TEvent>

      The event that was sent at the current state

    • Optional context: TContext

      The current context (extended state) of the current state

    Returns State<TContext, TEvent, TStateSchema, TTypestate>

withConfig

  • withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | undefined): StateNode<TContext, TStateSchema, TEvent, TTypestate>
  • Clones this state machine with custom options and context.

    Parameters

    • options: Partial<MachineOptions<TContext, TEvent>>

      Options (actions, guards, activities, services) to recursively merge with the existing options.

    • Default value context: TContext | undefined = this.context

      Custom context (will override predefined context)

    Returns StateNode<TContext, TStateSchema, TEvent, TTypestate>

withContext

  • withContext(context: TContext): StateNode<TContext, TStateSchema, TEvent>
  • Clones this state machine with custom context.

    Parameters

    • context: TContext

      Custom context (will override predefined context, not recursive)

    Returns StateNode<TContext, TStateSchema, TEvent>

Generated using TypeDoc