UNPKG

4.42 kBTypeScriptView Raw
1import type { StateMachine } from "./StateMachine.js";
2import type { DelayedTransitionDefinition, EventObject, InitialTransitionDefinition, InvokeDefinition, MachineContext, Mapper, StateNodeConfig, StateNodeDefinition, StateNodesConfig, TransitionDefinition, TransitionDefinitionMap, TODO, UnknownAction, ParameterizedObject, AnyStateMachine, ProvidedActor, NonReducibleUnknown, EventDescriptor } from "./types.js";
3interface StateNodeOptions<TContext extends MachineContext, TEvent extends EventObject> {
4 _key: string;
5 _parent?: StateNode<TContext, TEvent>;
6 _machine: AnyStateMachine;
7}
8export declare class StateNode<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> {
9 /**
10 * The raw config used to create the machine.
11 */
12 config: StateNodeConfig<TContext, TEvent, TODO, // actors
13 TODO, // actions
14 TODO, // guards
15 TODO, // delays
16 TODO, // tags
17 TODO, // output
18 TODO>;
19 /**
20 * The relative key of the state node, which represents its location in the overall state value.
21 */
22 key: string;
23 /**
24 * The unique ID of the state node.
25 */
26 id: string;
27 /**
28 * The type of this state node:
29 *
30 * - `'atomic'` - no child state nodes
31 * - `'compound'` - nested child state nodes (XOR)
32 * - `'parallel'` - orthogonal nested child state nodes (AND)
33 * - `'history'` - history state node
34 * - `'final'` - final state node
35 */
36 type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
37 /**
38 * The string path from the root machine node to this node.
39 */
40 path: string[];
41 /**
42 * The child state nodes.
43 */
44 states: StateNodesConfig<TContext, TEvent>;
45 /**
46 * The type of history on this state node. Can be:
47 *
48 * - `'shallow'` - recalls only top-level historical state value
49 * - `'deep'` - recalls historical state value at all levels
50 */
51 history: false | 'shallow' | 'deep';
52 /**
53 * The action(s) to be executed upon entering the state node.
54 */
55 entry: UnknownAction[];
56 /**
57 * The action(s) to be executed upon exiting the state node.
58 */
59 exit: UnknownAction[];
60 /**
61 * The parent state node.
62 */
63 parent?: StateNode<TContext, TEvent>;
64 /**
65 * The root machine node.
66 */
67 machine: StateMachine<TContext, TEvent, any, // children
68 any, // actor
69 any, // action
70 any, // guard
71 any, // delay
72 any, // tag
73 any, // input
74 any, // output
75 any, // emitted
76 any>;
77 /**
78 * The meta data associated with this state node, which will be returned in State instances.
79 */
80 meta?: any;
81 /**
82 * The output data sent with the "xstate.done.state._id_" event if this is a final state node.
83 */
84 output?: Mapper<MachineContext, EventObject, unknown, EventObject> | NonReducibleUnknown;
85 /**
86 * The order this state node appears. Corresponds to the implicit document order.
87 */
88 order: number;
89 description?: string;
90 tags: string[];
91 transitions: Map<string, TransitionDefinition<TContext, TEvent>[]>;
92 always?: Array<TransitionDefinition<TContext, TEvent>>;
93 constructor(
94 /**
95 * The raw config used to create the machine.
96 */
97 config: StateNodeConfig<TContext, TEvent, TODO, // actors
98 TODO, // actions
99 TODO, // guards
100 TODO, // delays
101 TODO, // tags
102 TODO, // output
103 TODO>, options: StateNodeOptions<TContext, TEvent>);
104 /**
105 * The well-structured state node definition.
106 */
107 get definition(): StateNodeDefinition<TContext, TEvent>;
108 /**
109 * The logic invoked as actors by this state node.
110 */
111 get invoke(): Array<InvokeDefinition<TContext, TEvent, ProvidedActor, ParameterizedObject, ParameterizedObject, string>>;
112 /**
113 * The mapping of events to transitions.
114 */
115 get on(): TransitionDefinitionMap<TContext, TEvent>;
116 get after(): Array<DelayedTransitionDefinition<TContext, TEvent>>;
117 get initial(): InitialTransitionDefinition<TContext, TEvent>;
118 /**
119 * All the event types accepted by this state node and its descendants.
120 */
121 get events(): Array<EventDescriptor<TEvent>>;
122 /**
123 * All the events that have transitions directly from this state node.
124 *
125 * Excludes any inert events.
126 */
127 get ownEvents(): Array<EventDescriptor<TEvent>>;
128}
129export {};