xstate 5.0.0-beta.33 → 5.0.0-beta.35

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 (41) hide show
  1. package/README.md +1 -1
  2. package/actions/dist/xstate-actions.cjs.js +3 -3
  3. package/actions/dist/xstate-actions.development.cjs.js +3 -3
  4. package/actions/dist/xstate-actions.development.esm.js +3 -3
  5. package/actions/dist/xstate-actions.esm.js +3 -3
  6. package/actions/dist/xstate-actions.umd.min.js +1 -1
  7. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  8. package/actors/dist/xstate-actors.cjs.js +3 -3
  9. package/actors/dist/xstate-actors.development.cjs.js +3 -3
  10. package/actors/dist/xstate-actors.development.esm.js +3 -3
  11. package/actors/dist/xstate-actors.esm.js +3 -3
  12. package/actors/dist/xstate-actors.umd.min.js +1 -1
  13. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  14. package/dist/declarations/src/index.d.ts +1 -0
  15. package/dist/declarations/src/interpreter.d.ts +3 -1
  16. package/dist/declarations/src/stateUtils.d.ts +6 -5
  17. package/dist/declarations/src/types.d.ts +3 -5
  18. package/dist/{interpreter-825f3d6e.development.esm.js → interpreter-5c4e6634.development.esm.js} +67 -65
  19. package/dist/{interpreter-054e9fb7.cjs.js → interpreter-69605bf0.cjs.js} +67 -65
  20. package/dist/{interpreter-0c630f66.development.cjs.js → interpreter-d3567419.development.cjs.js} +67 -65
  21. package/dist/{interpreter-03737810.esm.js → interpreter-de5217bc.esm.js} +67 -65
  22. package/dist/{raise-987c242e.cjs.js → raise-0ff57677.cjs.js} +142 -124
  23. package/dist/{raise-4c6a5a96.development.cjs.js → raise-26e4d83c.development.cjs.js} +145 -124
  24. package/dist/{raise-2d92eae8.esm.js → raise-511399cc.esm.js} +142 -124
  25. package/dist/{raise-46f122aa.development.esm.js → raise-cdcdf834.development.esm.js} +145 -124
  26. package/dist/{send-bd1bd0e3.cjs.js → send-19ffc568.cjs.js} +16 -8
  27. package/dist/{send-4d5b92dc.development.esm.js → send-1de74f4d.development.esm.js} +16 -8
  28. package/dist/{send-0edee2b4.esm.js → send-211a2a94.esm.js} +16 -8
  29. package/dist/{send-0e8675c8.development.cjs.js → send-894c4b18.development.cjs.js} +16 -8
  30. package/dist/xstate.cjs.js +28 -9
  31. package/dist/xstate.development.cjs.js +28 -9
  32. package/dist/xstate.development.esm.js +31 -12
  33. package/dist/xstate.esm.js +31 -12
  34. package/dist/xstate.umd.min.js +1 -1
  35. package/dist/xstate.umd.min.js.map +1 -1
  36. package/guards/dist/xstate-guards.cjs.js +2 -2
  37. package/guards/dist/xstate-guards.development.cjs.js +2 -2
  38. package/guards/dist/xstate-guards.development.esm.js +2 -2
  39. package/guards/dist/xstate-guards.esm.js +2 -2
  40. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  41. package/package.json +1 -1
@@ -9,62 +9,6 @@ const XSTATE_INIT = 'xstate.init';
9
9
  const XSTATE_ERROR = 'xstate.error';
10
10
  const XSTATE_STOP = 'xstate.stop';
11
11
 
12
- /**
13
- * Returns an event that represents an implicit event that
14
- * is sent after the specified `delay`.
15
- *
16
- * @param delayRef The delay in milliseconds
17
- * @param id The state node ID where this event is handled
18
- */
19
- function createAfterEvent(delayRef, id) {
20
- const idSuffix = id ? `#${id}` : '';
21
- return {
22
- type: `xstate.after(${delayRef})${idSuffix}`
23
- };
24
- }
25
-
26
- /**
27
- * Returns an event that represents that a final state node
28
- * has been reached in the parent state node.
29
- *
30
- * @param id The final state node's parent state node `id`
31
- * @param output The data to pass into the event
32
- */
33
- function createDoneStateEvent(id, output) {
34
- return {
35
- type: `xstate.done.state.${id}`,
36
- output
37
- };
38
- }
39
-
40
- /**
41
- * Returns an event that represents that an invoked service has terminated.
42
- *
43
- * An invoked service is terminated when it has reached a top-level final state node,
44
- * but not when it is canceled.
45
- *
46
- * @param invokeId The invoked service ID
47
- * @param output The data to pass into the event
48
- */
49
- function createDoneActorEvent(invokeId, output) {
50
- return {
51
- type: `xstate.done.actor.${invokeId}`,
52
- output
53
- };
54
- }
55
- function createErrorActorEvent(id, data) {
56
- return {
57
- type: `xstate.error.actor.${id}`,
58
- data
59
- };
60
- }
61
- function createInitEvent(input) {
62
- return {
63
- type: XSTATE_INIT,
64
- input
65
- };
66
- }
67
-
68
12
  class Mailbox {
69
13
  constructor(_process) {
70
14
  this._process = _process;
@@ -132,6 +76,62 @@ class Mailbox {
132
76
  }
133
77
  }
134
78
 
79
+ /**
80
+ * Returns an event that represents an implicit event that
81
+ * is sent after the specified `delay`.
82
+ *
83
+ * @param delayRef The delay in milliseconds
84
+ * @param id The state node ID where this event is handled
85
+ */
86
+ function createAfterEvent(delayRef, id) {
87
+ const idSuffix = id ? `#${id}` : '';
88
+ return {
89
+ type: `xstate.after(${delayRef})${idSuffix}`
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Returns an event that represents that a final state node
95
+ * has been reached in the parent state node.
96
+ *
97
+ * @param id The final state node's parent state node `id`
98
+ * @param output The data to pass into the event
99
+ */
100
+ function createDoneStateEvent(id, output) {
101
+ return {
102
+ type: `xstate.done.state.${id}`,
103
+ output
104
+ };
105
+ }
106
+
107
+ /**
108
+ * Returns an event that represents that an invoked service has terminated.
109
+ *
110
+ * An invoked service is terminated when it has reached a top-level final state node,
111
+ * but not when it is canceled.
112
+ *
113
+ * @param invokeId The invoked service ID
114
+ * @param output The data to pass into the event
115
+ */
116
+ function createDoneActorEvent(invokeId, output) {
117
+ return {
118
+ type: `xstate.done.actor.${invokeId}`,
119
+ output
120
+ };
121
+ }
122
+ function createErrorActorEvent(id, data) {
123
+ return {
124
+ type: `xstate.error.actor.${id}`,
125
+ data
126
+ };
127
+ }
128
+ function createInitEvent(input) {
129
+ return {
130
+ type: XSTATE_INIT,
131
+ input
132
+ };
133
+ }
134
+
135
135
  /**
136
136
  * This function makes sure that unhandled errors are thrown in a separate macrotask.
137
137
  * It allows those errors to be detected by global error handlers and reported to bug tracking services
@@ -343,6 +343,7 @@ function resolveReferencedActor(referenced) {
343
343
  } : referenced : undefined;
344
344
  }
345
345
 
346
+ const $$ACTOR_TYPE = 1;
346
347
  let ActorStatus = /*#__PURE__*/function (ActorStatus) {
347
348
  ActorStatus[ActorStatus["NotStarted"] = 0] = "NotStarted";
348
349
  ActorStatus[ActorStatus["Running"] = 1] = "Running";
@@ -560,7 +561,7 @@ class Actor {
560
561
  const status = this._state.status;
561
562
  switch (status) {
562
563
  case 'done':
563
- // a state machine can be "done" upon intialization (it could reach a final state using initial microsteps)
564
+ // a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
564
565
  // we still need to complete observers, flush deferreds etc
565
566
  this.update(this._state, initEvent);
566
567
  // fallthrough
@@ -723,14 +724,14 @@ class Actor {
723
724
  }
724
725
 
725
726
  // TODO: make private (and figure out a way to do this within the machine)
726
- delaySend({
727
- event,
728
- id,
729
- delay,
730
- to
731
- }) {
727
+ delaySend(params) {
728
+ const {
729
+ event,
730
+ id,
731
+ delay
732
+ } = params;
732
733
  const timerId = this.clock.setTimeout(() => {
733
- this.system._relay(this, to ?? this, event);
734
+ this.system._relay(this, params.to ?? this, event);
734
735
  }, delay);
735
736
 
736
737
  // TODO: consider the rehydration story here
@@ -755,6 +756,7 @@ class Actor {
755
756
  }
756
757
  toJSON() {
757
758
  return {
759
+ xstate$$type: $$ACTOR_TYPE,
758
760
  id: this.id
759
761
  };
760
762
  }
@@ -792,4 +794,4 @@ const interpret = createActor;
792
794
  * @deprecated Use `Actor` instead.
793
795
  */
794
796
 
795
- export { Actor as A, InterpreterStatus as I, NULL_EVENT as N, STATE_DELIMITER as S, WILDCARD as W, XSTATE_INIT as X, toTransitionConfigArray as a, createInitEvent as b, createInvokeId as c, createActor as d, matchesState as e, ActorStatus as f, interpret as g, toObserver as h, isErrorActorEvent as i, XSTATE_STOP as j, createErrorActorEvent as k, toStateValue as l, mapValues as m, STATE_IDENTIFIER as n, normalizeTarget as o, pathToStateValue as p, toStatePath as q, resolveReferencedActor as r, createDoneStateEvent as s, toArray as t, resolveOutput as u, isArray as v, createAfterEvent as w, flatten as x, XSTATE_ERROR as y };
797
+ export { $$ACTOR_TYPE as $, Actor as A, InterpreterStatus as I, NULL_EVENT as N, STATE_DELIMITER as S, WILDCARD as W, XSTATE_STOP as X, toTransitionConfigArray as a, createInitEvent as b, createInvokeId as c, createActor as d, matchesState as e, ActorStatus as f, interpret as g, toObserver as h, isErrorActorEvent as i, createErrorActorEvent as j, toStateValue as k, STATE_IDENTIFIER as l, mapValues as m, normalizeTarget as n, toStatePath as o, pathToStateValue as p, createDoneStateEvent as q, resolveReferencedActor as r, resolveOutput as s, toArray as t, XSTATE_INIT as u, createAfterEvent as v, flatten as w, XSTATE_ERROR as x };
@@ -11,62 +11,6 @@ const XSTATE_INIT = 'xstate.init';
11
11
  const XSTATE_ERROR = 'xstate.error';
12
12
  const XSTATE_STOP = 'xstate.stop';
13
13
 
14
- /**
15
- * Returns an event that represents an implicit event that
16
- * is sent after the specified `delay`.
17
- *
18
- * @param delayRef The delay in milliseconds
19
- * @param id The state node ID where this event is handled
20
- */
21
- function createAfterEvent(delayRef, id) {
22
- const idSuffix = id ? `#${id}` : '';
23
- return {
24
- type: `xstate.after(${delayRef})${idSuffix}`
25
- };
26
- }
27
-
28
- /**
29
- * Returns an event that represents that a final state node
30
- * has been reached in the parent state node.
31
- *
32
- * @param id The final state node's parent state node `id`
33
- * @param output The data to pass into the event
34
- */
35
- function createDoneStateEvent(id, output) {
36
- return {
37
- type: `xstate.done.state.${id}`,
38
- output
39
- };
40
- }
41
-
42
- /**
43
- * Returns an event that represents that an invoked service has terminated.
44
- *
45
- * An invoked service is terminated when it has reached a top-level final state node,
46
- * but not when it is canceled.
47
- *
48
- * @param invokeId The invoked service ID
49
- * @param output The data to pass into the event
50
- */
51
- function createDoneActorEvent(invokeId, output) {
52
- return {
53
- type: `xstate.done.actor.${invokeId}`,
54
- output
55
- };
56
- }
57
- function createErrorActorEvent(id, data) {
58
- return {
59
- type: `xstate.error.actor.${id}`,
60
- data
61
- };
62
- }
63
- function createInitEvent(input) {
64
- return {
65
- type: XSTATE_INIT,
66
- input
67
- };
68
- }
69
-
70
14
  class Mailbox {
71
15
  constructor(_process) {
72
16
  this._process = _process;
@@ -134,6 +78,62 @@ class Mailbox {
134
78
  }
135
79
  }
136
80
 
81
+ /**
82
+ * Returns an event that represents an implicit event that
83
+ * is sent after the specified `delay`.
84
+ *
85
+ * @param delayRef The delay in milliseconds
86
+ * @param id The state node ID where this event is handled
87
+ */
88
+ function createAfterEvent(delayRef, id) {
89
+ const idSuffix = id ? `#${id}` : '';
90
+ return {
91
+ type: `xstate.after(${delayRef})${idSuffix}`
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Returns an event that represents that a final state node
97
+ * has been reached in the parent state node.
98
+ *
99
+ * @param id The final state node's parent state node `id`
100
+ * @param output The data to pass into the event
101
+ */
102
+ function createDoneStateEvent(id, output) {
103
+ return {
104
+ type: `xstate.done.state.${id}`,
105
+ output
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Returns an event that represents that an invoked service has terminated.
111
+ *
112
+ * An invoked service is terminated when it has reached a top-level final state node,
113
+ * but not when it is canceled.
114
+ *
115
+ * @param invokeId The invoked service ID
116
+ * @param output The data to pass into the event
117
+ */
118
+ function createDoneActorEvent(invokeId, output) {
119
+ return {
120
+ type: `xstate.done.actor.${invokeId}`,
121
+ output
122
+ };
123
+ }
124
+ function createErrorActorEvent(id, data) {
125
+ return {
126
+ type: `xstate.error.actor.${id}`,
127
+ data
128
+ };
129
+ }
130
+ function createInitEvent(input) {
131
+ return {
132
+ type: XSTATE_INIT,
133
+ input
134
+ };
135
+ }
136
+
137
137
  /**
138
138
  * This function makes sure that unhandled errors are thrown in a separate macrotask.
139
139
  * It allows those errors to be detected by global error handlers and reported to bug tracking services
@@ -342,6 +342,7 @@ function resolveReferencedActor(referenced) {
342
342
  } : referenced : undefined;
343
343
  }
344
344
 
345
+ const $$ACTOR_TYPE = 1;
345
346
  let ActorStatus = /*#__PURE__*/function (ActorStatus) {
346
347
  ActorStatus[ActorStatus["NotStarted"] = 0] = "NotStarted";
347
348
  ActorStatus[ActorStatus["Running"] = 1] = "Running";
@@ -559,7 +560,7 @@ class Actor {
559
560
  const status = this._state.status;
560
561
  switch (status) {
561
562
  case 'done':
562
- // a state machine can be "done" upon intialization (it could reach a final state using initial microsteps)
563
+ // a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
563
564
  // we still need to complete observers, flush deferreds etc
564
565
  this.update(this._state, initEvent);
565
566
  // fallthrough
@@ -714,14 +715,14 @@ class Actor {
714
715
  }
715
716
 
716
717
  // TODO: make private (and figure out a way to do this within the machine)
717
- delaySend({
718
- event,
719
- id,
720
- delay,
721
- to
722
- }) {
718
+ delaySend(params) {
719
+ const {
720
+ event,
721
+ id,
722
+ delay
723
+ } = params;
723
724
  const timerId = this.clock.setTimeout(() => {
724
- this.system._relay(this, to ?? this, event);
725
+ this.system._relay(this, params.to ?? this, event);
725
726
  }, delay);
726
727
 
727
728
  // TODO: consider the rehydration story here
@@ -746,6 +747,7 @@ class Actor {
746
747
  }
747
748
  toJSON() {
748
749
  return {
750
+ xstate$$type: $$ACTOR_TYPE,
749
751
  id: this.id
750
752
  };
751
753
  }
@@ -783,6 +785,7 @@ const interpret = createActor;
783
785
  * @deprecated Use `Actor` instead.
784
786
  */
785
787
 
788
+ exports.$$ACTOR_TYPE = $$ACTOR_TYPE;
786
789
  exports.Actor = Actor;
787
790
  exports.ActorStatus = ActorStatus;
788
791
  exports.InterpreterStatus = InterpreterStatus;
@@ -801,7 +804,6 @@ exports.createInitEvent = createInitEvent;
801
804
  exports.createInvokeId = createInvokeId;
802
805
  exports.flatten = flatten;
803
806
  exports.interpret = interpret;
804
- exports.isArray = isArray;
805
807
  exports.isErrorActorEvent = isErrorActorEvent;
806
808
  exports.mapValues = mapValues;
807
809
  exports.matchesState = matchesState;
@@ -11,62 +11,6 @@ const XSTATE_INIT = 'xstate.init';
11
11
  const XSTATE_ERROR = 'xstate.error';
12
12
  const XSTATE_STOP = 'xstate.stop';
13
13
 
14
- /**
15
- * Returns an event that represents an implicit event that
16
- * is sent after the specified `delay`.
17
- *
18
- * @param delayRef The delay in milliseconds
19
- * @param id The state node ID where this event is handled
20
- */
21
- function createAfterEvent(delayRef, id) {
22
- const idSuffix = id ? `#${id}` : '';
23
- return {
24
- type: `xstate.after(${delayRef})${idSuffix}`
25
- };
26
- }
27
-
28
- /**
29
- * Returns an event that represents that a final state node
30
- * has been reached in the parent state node.
31
- *
32
- * @param id The final state node's parent state node `id`
33
- * @param output The data to pass into the event
34
- */
35
- function createDoneStateEvent(id, output) {
36
- return {
37
- type: `xstate.done.state.${id}`,
38
- output
39
- };
40
- }
41
-
42
- /**
43
- * Returns an event that represents that an invoked service has terminated.
44
- *
45
- * An invoked service is terminated when it has reached a top-level final state node,
46
- * but not when it is canceled.
47
- *
48
- * @param invokeId The invoked service ID
49
- * @param output The data to pass into the event
50
- */
51
- function createDoneActorEvent(invokeId, output) {
52
- return {
53
- type: `xstate.done.actor.${invokeId}`,
54
- output
55
- };
56
- }
57
- function createErrorActorEvent(id, data) {
58
- return {
59
- type: `xstate.error.actor.${id}`,
60
- data
61
- };
62
- }
63
- function createInitEvent(input) {
64
- return {
65
- type: XSTATE_INIT,
66
- input
67
- };
68
- }
69
-
70
14
  class Mailbox {
71
15
  constructor(_process) {
72
16
  this._process = _process;
@@ -134,6 +78,62 @@ class Mailbox {
134
78
  }
135
79
  }
136
80
 
81
+ /**
82
+ * Returns an event that represents an implicit event that
83
+ * is sent after the specified `delay`.
84
+ *
85
+ * @param delayRef The delay in milliseconds
86
+ * @param id The state node ID where this event is handled
87
+ */
88
+ function createAfterEvent(delayRef, id) {
89
+ const idSuffix = id ? `#${id}` : '';
90
+ return {
91
+ type: `xstate.after(${delayRef})${idSuffix}`
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Returns an event that represents that a final state node
97
+ * has been reached in the parent state node.
98
+ *
99
+ * @param id The final state node's parent state node `id`
100
+ * @param output The data to pass into the event
101
+ */
102
+ function createDoneStateEvent(id, output) {
103
+ return {
104
+ type: `xstate.done.state.${id}`,
105
+ output
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Returns an event that represents that an invoked service has terminated.
111
+ *
112
+ * An invoked service is terminated when it has reached a top-level final state node,
113
+ * but not when it is canceled.
114
+ *
115
+ * @param invokeId The invoked service ID
116
+ * @param output The data to pass into the event
117
+ */
118
+ function createDoneActorEvent(invokeId, output) {
119
+ return {
120
+ type: `xstate.done.actor.${invokeId}`,
121
+ output
122
+ };
123
+ }
124
+ function createErrorActorEvent(id, data) {
125
+ return {
126
+ type: `xstate.error.actor.${id}`,
127
+ data
128
+ };
129
+ }
130
+ function createInitEvent(input) {
131
+ return {
132
+ type: XSTATE_INIT,
133
+ input
134
+ };
135
+ }
136
+
137
137
  /**
138
138
  * This function makes sure that unhandled errors are thrown in a separate macrotask.
139
139
  * It allows those errors to be detected by global error handlers and reported to bug tracking services
@@ -345,6 +345,7 @@ function resolveReferencedActor(referenced) {
345
345
  } : referenced : undefined;
346
346
  }
347
347
 
348
+ const $$ACTOR_TYPE = 1;
348
349
  let ActorStatus = /*#__PURE__*/function (ActorStatus) {
349
350
  ActorStatus[ActorStatus["NotStarted"] = 0] = "NotStarted";
350
351
  ActorStatus[ActorStatus["Running"] = 1] = "Running";
@@ -562,7 +563,7 @@ class Actor {
562
563
  const status = this._state.status;
563
564
  switch (status) {
564
565
  case 'done':
565
- // a state machine can be "done" upon intialization (it could reach a final state using initial microsteps)
566
+ // a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
566
567
  // we still need to complete observers, flush deferreds etc
567
568
  this.update(this._state, initEvent);
568
569
  // fallthrough
@@ -725,14 +726,14 @@ class Actor {
725
726
  }
726
727
 
727
728
  // TODO: make private (and figure out a way to do this within the machine)
728
- delaySend({
729
- event,
730
- id,
731
- delay,
732
- to
733
- }) {
729
+ delaySend(params) {
730
+ const {
731
+ event,
732
+ id,
733
+ delay
734
+ } = params;
734
735
  const timerId = this.clock.setTimeout(() => {
735
- this.system._relay(this, to ?? this, event);
736
+ this.system._relay(this, params.to ?? this, event);
736
737
  }, delay);
737
738
 
738
739
  // TODO: consider the rehydration story here
@@ -757,6 +758,7 @@ class Actor {
757
758
  }
758
759
  toJSON() {
759
760
  return {
761
+ xstate$$type: $$ACTOR_TYPE,
760
762
  id: this.id
761
763
  };
762
764
  }
@@ -794,6 +796,7 @@ const interpret = createActor;
794
796
  * @deprecated Use `Actor` instead.
795
797
  */
796
798
 
799
+ exports.$$ACTOR_TYPE = $$ACTOR_TYPE;
797
800
  exports.Actor = Actor;
798
801
  exports.ActorStatus = ActorStatus;
799
802
  exports.InterpreterStatus = InterpreterStatus;
@@ -812,7 +815,6 @@ exports.createInitEvent = createInitEvent;
812
815
  exports.createInvokeId = createInvokeId;
813
816
  exports.flatten = flatten;
814
817
  exports.interpret = interpret;
815
- exports.isArray = isArray;
816
818
  exports.isErrorActorEvent = isErrorActorEvent;
817
819
  exports.mapValues = mapValues;
818
820
  exports.matchesState = matchesState;