UNPKG

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