MCPcopy
hub / github.com/statelyai/xstate / getStateNodes

Function getStateNodes

packages/core/src/stateUtils.ts:617–651  ·  view source on GitHub ↗
(
  stateNode: AnyStateNode,
  stateValue: StateValue
)

Source from the content-addressed store, hash-verified

615 * @param stateValue The state value or State instance
616 */
617export function getStateNodes(
618 stateNode: AnyStateNode,
619 stateValue: StateValue
620): Array<AnyStateNode> {
621 if (typeof stateValue === 'string') {
622 const childStateNode = stateNode.states[stateValue];
623 if (!childStateNode) {
624 throw new Error(
625 `State '${stateValue}' does not exist on '${stateNode.id}'`
626 );
627 }
628 return [stateNode, childStateNode];
629 }
630
631 const childStateKeys = Object.keys(stateValue);
632 const childStateNodes: Array<AnyStateNode> = childStateKeys
633 .map((subStateKey) => getStateNode(stateNode, subStateKey))
634 .filter(Boolean);
635
636 return [stateNode.machine.root, stateNode].concat(
637 childStateNodes,
638 childStateKeys.reduce((allSubStateNodes, subStateKey) => {
639 const subStateNode = getStateNode(stateNode, subStateKey);
640 if (!subStateNode) {
641 return allSubStateNodes;
642 }
643 const subStateNodes = getStateNodes(
644 subStateNode,
645 stateValue[subStateKey]!
646 );
647
648 return allSubStateNodes.concat(subStateNodes);
649 }, [] as Array<AnyStateNode>)
650 );
651}
652
653function transitionAtomicNode<
654 TContext extends MachineContext,

Callers 4

runTestToCompletionFunction · 0.90
resolveStateMethod · 0.90
restoreSnapshotMethod · 0.90
resolveStateValueFunction · 0.70

Calls 1

getStateNodeFunction · 0.85

Tested by 1

runTestToCompletionFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…