Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface StateMachine<TContext, TStateSchema, TEvent, TTypestate>

Type Parameters

Hierarchy

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

Index

Properties

__xstatenode: true
activities: ActivityDefinition<TContext, TEvent>[]

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

config: StateNodeConfig<TContext, TStateSchema, TEvent>

The raw config used to create the machine.

context?: Readonly<TContext>

The initial extended state

delimiter: string

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

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: 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: string

The unique ID of the state node.

initial?: keyof TStateSchema["states"]

The initial state node key.

invoke: InvokeDefinition<TContext, TEvent>[]

The services invoked by this state node.

key: string

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

machine: StateNode<TContext, any, TEvent, { context: TContext; value: any }>

The root machine node.

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

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

onEntry: ActionObject<TContext, TEvent>[]

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

onExit: ActionObject<TContext, TEvent>[]

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

options: MachineOptions<TContext, TEvent>
order: number

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

parallel?: boolean

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

Use type: 'parallel' instead.

parent?: StateNode<TContext, any, TEvent, { context: TContext; value: any }>

The parent state node.

path: string[]

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

states: StateNodesConfig<TContext, TStateSchema, TEvent>

The child state nodes.

strict: boolean
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
version?: string

The machine's own version.

Accessors

  • Returns DelayedTransitionDefinition<TContext, TEvent>[]

  • The well-structured state node definition.

    Returns StateNodeDefinition<TContext, TStateSchema, TEvent>

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

    Returns TEvent["type"][]

  • 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>

  • get initialStateNodes(): StateNode<TContext, any, TEvent, { context: TContext; value: any }>[]
  • Returns StateNode<TContext, any, TEvent, { context: TContext; value: any }>[]

  • The mapping of events to transitions.

    Returns TransitionDefinitionMap<TContext, TEvent>

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

    Excludes any inert events.

    Returns TEvent["type"][]

  • get stateIds(): string[]
  • All the state node IDs of this state node and its descendant state nodes.

    Returns string[]

  • 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 undefined | string | StateValueMap

  • All the transitions that can be taken from this state node.

    Returns TransitionDefinition<TContext, TEvent>[]

Methods

  • getFromRelativePath(relativePath: string[]): StateNode<TContext, any, TEvent, { context: TContext; value: any }>[]
  • Retrieves state nodes from a relative path to this state node.

    Parameters

    • relativePath: string[]

      The relative path from this state node

    Returns StateNode<TContext, any, TEvent, { context: TContext; value: any }>[]

  • getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>
  • Parameters

    Returns State<TContext, TEvent, TStateSchema, TTypestate>

  • getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent, { context: TContext; value: any }>, historyValue?: HistoryValue, resolve?: boolean): StateNode<TContext, any, TEvent, { context: TContext; value: any }>[]
  • Returns the leaf nodes from a state path relative to this state node.

    Parameters

    • relativeStateId: StateNode<TContext, any, TEvent, { context: TContext; value: any }>

      The relative state path to retrieve the state nodes

    • Optional historyValue: HistoryValue
    • Optional resolve: boolean

      Whether state nodes should resolve to initial child state nodes

    Returns StateNode<TContext, any, TEvent, { context: TContext; value: any }>[]

  • getStateNode(stateKey: string): StateNode<TContext, any, TEvent, { context: TContext; value: any }>
  • Returns the child state node from its relative stateKey, or throws.

    Parameters

    • stateKey: string

    Returns StateNode<TContext, any, TEvent, { context: TContext; value: any }>

  • getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, { context: TContext; value: any }>
  • Returns the state node with the given stateId, or throws.

    Parameters

    • stateId: string

      The state ID. The prefix "#" is removed.

    Returns StateNode<TContext, any, TEvent, { context: TContext; value: any }>

  • getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, { context: TContext; value: 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, { context: TContext; value: any }>

  • getStateNodes(state: string | StateValueMap | State<TContext, TEvent, any, TTypestate>): StateNode<TContext, any, TEvent, { context: TContext; value: any }>[]
  • Returns the state nodes represented by the current state value.

    Parameters

    • state: string | StateValueMap | State<TContext, TEvent, any, TTypestate>

      The state value or State instance

    Returns StateNode<TContext, any, TEvent, { context: TContext; value: any }>[]

  • 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

  • Resolves a partial state value with its full representation in this machine.

    Parameters

    • stateValue: StateValue

      The partial state value to resolve.

    Returns StateValue

  • resolveState(state: State<TContext, TEvent, any, { context: TContext; value: 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, { context: TContext; value: any }>

      The state to resolve

    Returns State<TContext, TEvent, TStateSchema, TTypestate>

  • transition(state: undefined | string | StateValueMap | State<TContext, TEvent, any, TTypestate>, event: TEvent | TEvent["type"] | Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>
  • Determines the next state given the current state and sent event.

    Parameters

    • state: undefined | string | StateValueMap | State<TContext, TEvent, any, TTypestate>

      The current State instance or state value

    • event: TEvent | TEvent["type"] | 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>

  • 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.

    • Optional context: TContext

      Custom context (will override predefined context)

    Returns StateNode<TContext, TStateSchema, TEvent, TTypestate>

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

    Parameters

    • context: TContext

      Custom context (will override predefined context, not recursive)

    Returns StateNode<TContext, TStateSchema, TEvent, { context: TContext; value: any }>

Generated using TypeDoc