TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/statelyai/xstate/llms.txt
Use this file to discover all available pages before exploring further.
stateUtils module contains a collection of internal utility functions used by XState for managing state nodes, transitions, and state values. These utilities are primarily used internally by the XState library.
State Node Utilities
getStateNodes
Returns the state nodes represented by the current state value.The parent state node to search within.
The state value (string or object) representing the current state.
An array of state nodes that correspond to the given state value.
getStateNodeByPath
Returns the relative state node from the givenstatePath, or throws an error if not found.
The starting state node.
The string or string array relative path to the target state node. Can use state IDs (strings starting with
#).The state node at the specified path.
getStateValue
Computes the state value from a root node and a collection of state nodes.The root state node of the machine.
The collection of active state nodes.
The computed state value (string for atomic states, object for compound/parallel states).
resolveStateValue
Resolves a partial state value with its full representation in the state node’s machine.The root state node of the machine.
The partial state value to resolve.
The fully resolved state value.
Transition Utilities
formatTransition
Formats a transition config into a complete transition definition.The source state node.
The event descriptor for this transition.
The raw transition configuration.
A fully formatted transition definition with resolved targets and guards.
transitionNode
Determines the enabled transitions for a state node given a state value and event.The state node to get transitions from.
The current state value.
The current machine snapshot.
The event that may trigger transitions.
An array of enabled transitions, or undefined if no transitions are enabled.
getCandidates
Returns candidate transitions for a given event type on a state node.The state node to get candidates from.
The type of the received event.
An array of candidate transitions that match the event type.
State Checking Utilities
isInFinalState
Checks if a state node is in a final state.The set of currently active state nodes.
The state node to check.
true if the state node is in a final state:- For compound states: if a direct child final state is active
- For parallel states: if all child regions are in final states
- For atomic states: if the state itself is a final state
isAtomicStateNode
Checks if a state node is atomic (has no child states).The state node to check.
true if the state node type is 'atomic' or 'final'.getProperAncestors
Returns all proper ancestors of a state node up to (but not including) a target ancestor.The starting state node.
The ancestor to stop at (not included in results). If
undefined, returns all ancestors.An array of ancestor state nodes, from immediate parent to the generation before
toStateNode.Transition Processing
macrostep
Performs a macrostep, which processes an event and executes all resulting microsteps until a stable state is reached.The current machine snapshot.
The event to process.
The actor scope containing execution context.
Queue for internally raised events.
An object containing the resulting snapshot and an array of microsteps that were executed.
Notes
Many of these utilities are used during state machine initialization and transition processing. They implement core algorithms from the SCXML specification.