xstate 4.20.0 → 4.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.d.ts +6 -5
  6. package/es/Actor.js +22 -7
  7. package/es/Machine.d.ts +10 -5
  8. package/es/Machine.js +3 -6
  9. package/es/State.js +3 -5
  10. package/es/StateNode.d.ts +4 -3
  11. package/es/StateNode.js +34 -28
  12. package/es/_virtual/_tslib.js +59 -73
  13. package/es/actionTypes.js +3 -2
  14. package/es/actions.d.ts +1 -1
  15. package/es/actions.js +51 -37
  16. package/es/behaviors.d.ts +37 -0
  17. package/es/behaviors.js +65 -0
  18. package/es/constants.js +2 -1
  19. package/es/devTools.js +1 -1
  20. package/es/environment.js +2 -1
  21. package/es/index.js +3 -1
  22. package/es/interpreter.d.ts +15 -8
  23. package/es/interpreter.js +48 -22
  24. package/es/invokeUtils.js +4 -3
  25. package/es/mapState.js +1 -1
  26. package/es/match.js +1 -1
  27. package/es/model.d.ts +2 -36
  28. package/es/model.types.d.ts +37 -0
  29. package/es/registry.js +2 -1
  30. package/es/scheduler.js +2 -1
  31. package/es/schema.js +1 -1
  32. package/es/serviceScope.js +1 -3
  33. package/es/stateUtils.d.ts +1 -0
  34. package/es/stateUtils.js +14 -8
  35. package/es/types.d.ts +35 -9
  36. package/es/types.js +1 -1
  37. package/es/utils.d.ts +3 -2
  38. package/es/utils.js +4 -40
  39. package/lib/Actor.d.ts +25 -24
  40. package/lib/Actor.js +87 -53
  41. package/lib/Machine.d.ts +17 -12
  42. package/lib/Machine.js +14 -14
  43. package/lib/SimulatedClock.d.ts +16 -16
  44. package/lib/State.d.ts +108 -108
  45. package/lib/State.js +246 -236
  46. package/lib/StateNode.d.ts +279 -278
  47. package/lib/StateNode.js +1535 -1350
  48. package/lib/_virtual/_tslib.js +81 -0
  49. package/lib/actionTypes.d.ts +19 -19
  50. package/lib/actionTypes.js +43 -23
  51. package/lib/actions.d.ts +138 -138
  52. package/lib/actions.js +465 -387
  53. package/lib/behaviors.d.ts +37 -0
  54. package/lib/behaviors.js +69 -0
  55. package/lib/constants.d.ts +5 -5
  56. package/lib/constants.js +13 -7
  57. package/lib/devTools.d.ts +15 -15
  58. package/lib/devTools.js +37 -26
  59. package/lib/each.d.ts +3 -3
  60. package/lib/environment.d.ts +1 -1
  61. package/lib/environment.js +7 -4
  62. package/lib/index.d.ts +30 -30
  63. package/lib/index.js +67 -57
  64. package/lib/interpreter.d.ts +205 -198
  65. package/lib/interpreter.js +1307 -1052
  66. package/lib/invoke.d.ts +10 -10
  67. package/lib/invokeUtils.d.ts +6 -6
  68. package/lib/invokeUtils.js +40 -37
  69. package/lib/json.d.ts +30 -30
  70. package/lib/mapState.d.ts +3 -3
  71. package/lib/mapState.js +31 -32
  72. package/lib/match.d.ts +8 -8
  73. package/lib/match.js +33 -47
  74. package/lib/model.d.ts +4 -38
  75. package/lib/model.js +5 -1
  76. package/lib/model.types.d.ts +37 -0
  77. package/lib/model.types.js +2 -0
  78. package/lib/patterns.d.ts +13 -13
  79. package/lib/registry.d.ts +8 -8
  80. package/lib/registry.js +21 -18
  81. package/lib/scheduler.d.ts +16 -16
  82. package/lib/scheduler.js +79 -70
  83. package/lib/schema.d.ts +1 -1
  84. package/lib/schema.js +6 -4
  85. package/lib/scxml.d.ts +5 -5
  86. package/lib/serviceScope.d.ts +3 -3
  87. package/lib/serviceScope.js +16 -12
  88. package/lib/stateUtils.d.ts +14 -13
  89. package/lib/stateUtils.js +232 -190
  90. package/lib/types.d.ts +928 -902
  91. package/lib/types.js +29 -29
  92. package/lib/utils.d.ts +68 -67
  93. package/lib/utils.js +530 -529
  94. package/package.json +5 -5
package/lib/State.d.ts CHANGED
@@ -1,109 +1,109 @@
1
- import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef } from './types';
2
- import { StateNode } from './StateNode';
3
- export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
4
- export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
5
- value: any;
6
- context: TContext;
7
- }>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
8
- export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
9
- export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
10
- value: any;
11
- context: TContext;
12
- }> {
13
- value: StateValue;
14
- context: TContext;
15
- historyValue?: HistoryValue | undefined;
16
- history?: State<TContext, TEvent, TStateSchema, TTypestate>;
17
- actions: Array<ActionObject<TContext, TEvent>>;
18
- activities: ActivityMap;
19
- meta: any;
20
- events: TEvent[];
21
- event: TEvent;
22
- _event: SCXML.Event<TEvent>;
23
- _sessionid: string | null;
24
- /**
25
- * Indicates whether the state has changed from the previous state. A state is considered "changed" if:
26
- *
27
- * - Its value is not equal to its previous value, or:
28
- * - It has any new actions (side-effects) to execute.
29
- *
30
- * An initial state (with no history) will return `undefined`.
31
- */
32
- changed: boolean | undefined;
33
- /**
34
- * Indicates whether the state is a final state.
35
- */
36
- done: boolean | undefined;
37
- /**
38
- * The enabled state nodes representative of the state value.
39
- */
40
- configuration: Array<StateNode<TContext, any, TEvent, any>>;
41
- /**
42
- * The next events that will cause a transition from the current state.
43
- */
44
- nextEvents: EventType[];
45
- /**
46
- * The transition definitions that resulted in this state.
47
- */
48
- transitions: Array<TransitionDefinition<TContext, TEvent>>;
49
- /**
50
- * An object mapping actor IDs to spawned actors/invoked services.
51
- */
52
- children: Record<string, ActorRef<any>>;
53
- tags: Set<string>;
54
- /**
55
- * Creates a new State instance for the given `stateValue` and `context`.
56
- * @param stateValue
57
- * @param context
58
- */
59
- static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
60
- /**
61
- * Creates a new State instance for the given `config`.
62
- * @param config The state config
63
- */
64
- static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE>;
65
- /**
66
- * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
67
- * @param stateValue
68
- * @param context
69
- */
70
- static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context: TC): State<TC, TE>;
71
- /**
72
- * Creates a new State instance.
73
- * @param value The state value
74
- * @param context The extended state
75
- * @param historyValue The tree representing historical values of the state nodes
76
- * @param history The previous state
77
- * @param actions An array of action objects to execute as side-effects
78
- * @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
79
- * @param meta
80
- * @param events Internal event queue. Should be empty with run-to-completion semantics.
81
- * @param configuration
82
- */
83
- constructor(config: StateConfig<TContext, TEvent>);
84
- /**
85
- * Returns an array of all the string leaf state node paths.
86
- * @param stateValue
87
- * @param delimiter The character(s) that separate each subpath in the string state node path.
88
- */
89
- toStrings(stateValue?: StateValue, delimiter?: string): string[];
90
- toJSON(): Omit<this, "configuration" | "transitions" | "tags"> & {
91
- tags: string[];
92
- };
93
- /**
94
- * Whether the current state value is a subset of the given parent state value.
95
- * @param parentStateValue
96
- */
97
- matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
98
- value: TSV;
99
- context: any;
100
- } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
101
- value: TSV;
102
- };
103
- /**
104
- * Whether the current state configuration has a state node with the specified `tag`.
105
- * @param tag
106
- */
107
- hasTag(tag: string): boolean;
108
- }
1
+ import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef } from './types';
2
+ import { StateNode } from './StateNode';
3
+ export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
4
+ export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
5
+ value: any;
6
+ context: TContext;
7
+ }>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
8
+ export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
9
+ export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
10
+ value: any;
11
+ context: TContext;
12
+ }> {
13
+ value: StateValue;
14
+ context: TContext;
15
+ historyValue?: HistoryValue | undefined;
16
+ history?: State<TContext, TEvent, TStateSchema, TTypestate>;
17
+ actions: Array<ActionObject<TContext, TEvent>>;
18
+ activities: ActivityMap;
19
+ meta: any;
20
+ events: TEvent[];
21
+ event: TEvent;
22
+ _event: SCXML.Event<TEvent>;
23
+ _sessionid: string | null;
24
+ /**
25
+ * Indicates whether the state has changed from the previous state. A state is considered "changed" if:
26
+ *
27
+ * - Its value is not equal to its previous value, or:
28
+ * - It has any new actions (side-effects) to execute.
29
+ *
30
+ * An initial state (with no history) will return `undefined`.
31
+ */
32
+ changed: boolean | undefined;
33
+ /**
34
+ * Indicates whether the state is a final state.
35
+ */
36
+ done: boolean | undefined;
37
+ /**
38
+ * The enabled state nodes representative of the state value.
39
+ */
40
+ configuration: Array<StateNode<TContext, any, TEvent, any>>;
41
+ /**
42
+ * The next events that will cause a transition from the current state.
43
+ */
44
+ nextEvents: EventType[];
45
+ /**
46
+ * The transition definitions that resulted in this state.
47
+ */
48
+ transitions: Array<TransitionDefinition<TContext, TEvent>>;
49
+ /**
50
+ * An object mapping actor IDs to spawned actors/invoked services.
51
+ */
52
+ children: Record<string, ActorRef<any>>;
53
+ tags: Set<string>;
54
+ /**
55
+ * Creates a new State instance for the given `stateValue` and `context`.
56
+ * @param stateValue
57
+ * @param context
58
+ */
59
+ static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
60
+ /**
61
+ * Creates a new State instance for the given `config`.
62
+ * @param config The state config
63
+ */
64
+ static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE>;
65
+ /**
66
+ * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
67
+ * @param stateValue
68
+ * @param context
69
+ */
70
+ static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context: TC): State<TC, TE>;
71
+ /**
72
+ * Creates a new State instance.
73
+ * @param value The state value
74
+ * @param context The extended state
75
+ * @param historyValue The tree representing historical values of the state nodes
76
+ * @param history The previous state
77
+ * @param actions An array of action objects to execute as side-effects
78
+ * @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
79
+ * @param meta
80
+ * @param events Internal event queue. Should be empty with run-to-completion semantics.
81
+ * @param configuration
82
+ */
83
+ constructor(config: StateConfig<TContext, TEvent>);
84
+ /**
85
+ * Returns an array of all the string leaf state node paths.
86
+ * @param stateValue
87
+ * @param delimiter The character(s) that separate each subpath in the string state node path.
88
+ */
89
+ toStrings(stateValue?: StateValue, delimiter?: string): string[];
90
+ toJSON(): Omit<this, "configuration" | "transitions" | "tags"> & {
91
+ tags: string[];
92
+ };
93
+ /**
94
+ * Whether the current state value is a subset of the given parent state value.
95
+ * @param parentStateValue
96
+ */
97
+ matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
98
+ value: TSV;
99
+ context: any;
100
+ } extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
101
+ value: TSV;
102
+ };
103
+ /**
104
+ * Whether the current state configuration has a state node with the specified `tag`.
105
+ * @param tag
106
+ */
107
+ hasTag(tag: string): boolean;
108
+ }
109
109
  //# sourceMappingURL=State.d.ts.map