xstate 5.0.0-beta.27 → 5.0.0-beta.29

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 (67) hide show
  1. package/README.md +9 -7
  2. package/actions/dist/xstate-actions.cjs.js +11 -17
  3. package/actions/dist/xstate-actions.cjs.mjs +0 -8
  4. package/actions/dist/xstate-actions.development.cjs.js +11 -17
  5. package/actions/dist/xstate-actions.development.cjs.mjs +0 -8
  6. package/actions/dist/xstate-actions.development.esm.js +3 -1
  7. package/actions/dist/xstate-actions.esm.js +3 -1
  8. package/actions/dist/xstate-actions.umd.min.js +1 -1
  9. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  10. package/actors/dist/xstate-actors.cjs.js +395 -28
  11. package/actors/dist/xstate-actors.cjs.mjs +1 -3
  12. package/actors/dist/xstate-actors.development.cjs.js +395 -28
  13. package/actors/dist/xstate-actors.development.cjs.mjs +1 -3
  14. package/actors/dist/xstate-actors.development.esm.js +389 -21
  15. package/actors/dist/xstate-actors.esm.js +389 -21
  16. package/actors/dist/xstate-actors.umd.min.js +1 -1
  17. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  18. package/dist/declarations/src/StateNode.d.ts +3 -3
  19. package/dist/declarations/src/actions/assign.d.ts +9 -4
  20. package/dist/declarations/src/actions/cancel.d.ts +4 -4
  21. package/dist/declarations/src/actions/choose.d.ts +5 -4
  22. package/dist/declarations/src/actions/log.d.ts +4 -4
  23. package/dist/declarations/src/actions/pure.d.ts +6 -5
  24. package/dist/declarations/src/actions/raise.d.ts +2 -2
  25. package/dist/declarations/src/actions/send.d.ts +7 -7
  26. package/dist/declarations/src/actions/stop.d.ts +4 -4
  27. package/dist/declarations/src/actions.d.ts +8 -44
  28. package/dist/declarations/src/actors/callback.d.ts +2 -2
  29. package/dist/declarations/src/actors/index.d.ts +3 -5
  30. package/dist/declarations/src/constants.d.ts +1 -0
  31. package/dist/declarations/src/index.d.ts +9 -16
  32. package/dist/declarations/src/spawn.d.ts +25 -0
  33. package/dist/declarations/src/stateUtils.d.ts +1 -1
  34. package/dist/declarations/src/typegenTypes.d.ts +4 -4
  35. package/dist/declarations/src/types.d.ts +92 -122
  36. package/dist/declarations/src/utils.d.ts +2 -2
  37. package/dist/interpreter-498891b2.esm.js +741 -0
  38. package/dist/interpreter-6e7909c8.development.esm.js +749 -0
  39. package/dist/interpreter-c357bc50.cjs.js +773 -0
  40. package/dist/interpreter-e2c6a579.development.cjs.js +781 -0
  41. package/dist/{actions-9754d2ca.development.esm.js → raise-03e57569.cjs.js} +130 -1307
  42. package/dist/{actions-d1dba4ac.cjs.js → raise-59f2c242.esm.js} +65 -1267
  43. package/dist/{actions-020463e9.esm.js → raise-e778a828.development.esm.js} +109 -1203
  44. package/dist/{actions-ca622922.development.cjs.js → raise-f751dfac.development.cjs.js} +101 -1306
  45. package/dist/send-42c83fb2.development.esm.js +364 -0
  46. package/dist/send-51717e53.cjs.js +349 -0
  47. package/dist/send-f53778f6.development.cjs.js +374 -0
  48. package/dist/send-fff224db.esm.js +339 -0
  49. package/dist/xstate.cjs.js +114 -112
  50. package/dist/xstate.cjs.mjs +2 -2
  51. package/dist/xstate.development.cjs.js +114 -112
  52. package/dist/xstate.development.cjs.mjs +2 -2
  53. package/dist/xstate.development.esm.js +78 -74
  54. package/dist/xstate.esm.js +78 -74
  55. package/dist/xstate.umd.min.js +1 -1
  56. package/dist/xstate.umd.min.js.map +1 -1
  57. package/guards/dist/xstate-guards.cjs.js +2 -1
  58. package/guards/dist/xstate-guards.development.cjs.js +2 -1
  59. package/guards/dist/xstate-guards.development.esm.js +2 -1
  60. package/guards/dist/xstate-guards.esm.js +2 -1
  61. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/declarations/src/constantPrefixes.d.ts +0 -6
  64. package/dist/promise-2ad94e3b.development.esm.js +0 -406
  65. package/dist/promise-3b7e3357.development.cjs.js +0 -412
  66. package/dist/promise-5b07c38e.esm.js +0 -406
  67. package/dist/promise-7a8c1768.cjs.js +0 -412
@@ -2,12 +2,63 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var guards_dist_xstateGuards = require('./actions-ca622922.development.cjs.js');
6
- var promise = require('./promise-3b7e3357.development.cjs.js');
5
+ var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
6
+ var interpreter = require('./interpreter-e2c6a579.development.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-f751dfac.development.cjs.js');
8
+ var send = require('./send-f53778f6.development.cjs.js');
7
9
  require('../dev/dist/xstate-dev.development.cjs.js');
8
10
 
11
+ class SimulatedClock {
12
+ constructor() {
13
+ this.timeouts = new Map();
14
+ this._now = 0;
15
+ this._id = 0;
16
+ }
17
+ now() {
18
+ return this._now;
19
+ }
20
+ getId() {
21
+ return this._id++;
22
+ }
23
+ setTimeout(fn, timeout) {
24
+ const id = this.getId();
25
+ this.timeouts.set(id, {
26
+ start: this.now(),
27
+ timeout,
28
+ fn
29
+ });
30
+ return id;
31
+ }
32
+ clearTimeout(id) {
33
+ this.timeouts.delete(id);
34
+ }
35
+ set(time) {
36
+ if (this._now > time) {
37
+ throw new Error('Unable to travel back in time');
38
+ }
39
+ this._now = time;
40
+ this.flushTimeouts();
41
+ }
42
+ flushTimeouts() {
43
+ [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
44
+ const endA = timeoutA.start + timeoutA.timeout;
45
+ const endB = timeoutB.start + timeoutB.timeout;
46
+ return endB > endA ? -1 : 1;
47
+ }).forEach(([id, timeout]) => {
48
+ if (this.now() - timeout.start >= timeout.timeout) {
49
+ this.timeouts.delete(id);
50
+ timeout.fn.call(null);
51
+ }
52
+ });
53
+ }
54
+ increment(ms) {
55
+ this._now += ms;
56
+ this.flushTimeouts();
57
+ }
58
+ }
59
+
9
60
  const EMPTY_OBJECT = {};
10
- const toSerializableActon = action => {
61
+ const toSerializableAction = action => {
11
62
  if (typeof action === 'string') {
12
63
  return {
13
64
  type: action
@@ -80,7 +131,7 @@ class StateNode {
80
131
  */
81
132
 
82
133
  /**
83
- * The output data sent with the "done.state._id_" event if this is a final state node.
134
+ * The output data sent with the "xstate.done.state._id_" event if this is a final state node.
84
135
  */
85
136
 
86
137
  /**
@@ -114,12 +165,12 @@ class StateNode {
114
165
  this.key = options._key;
115
166
  this.machine = options._machine;
116
167
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
117
- this.id = this.config.id || [this.machine.id, ...this.path].join(guards_dist_xstateGuards.STATE_DELIMITER);
168
+ this.id = this.config.id || [this.machine.id, ...this.path].join(interpreter.STATE_DELIMITER);
118
169
  this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
119
170
  this.description = this.config.description;
120
171
  this.order = this.machine.idMap.size;
121
172
  this.machine.idMap.set(this.id, this);
122
- this.states = this.config.states ? guards_dist_xstateGuards.mapValues(this.config.states, (stateConfig, key) => {
173
+ this.states = this.config.states ? interpreter.mapValues(this.config.states, (stateConfig, key) => {
123
174
  const stateNode = new StateNode(stateConfig, {
124
175
  _parent: this,
125
176
  _key: key,
@@ -133,16 +184,16 @@ class StateNode {
133
184
 
134
185
  // History config
135
186
  this.history = this.config.history === true ? 'shallow' : this.config.history || false;
136
- this.entry = guards_dist_xstateGuards.toArray(this.config.entry).slice();
137
- this.exit = guards_dist_xstateGuards.toArray(this.config.exit).slice();
187
+ this.entry = interpreter.toArray(this.config.entry).slice();
188
+ this.exit = interpreter.toArray(this.config.exit).slice();
138
189
  this.meta = this.config.meta;
139
190
  this.output = this.type === 'final' ? this.config.output : undefined;
140
- this.tags = guards_dist_xstateGuards.toArray(config.tags).slice();
191
+ this.tags = interpreter.toArray(config.tags).slice();
141
192
  }
142
193
  _initialize() {
143
194
  this.transitions = guards_dist_xstateGuards.formatTransitions(this);
144
195
  if (this.config.always) {
145
- this.always = guards_dist_xstateGuards.toTransitionConfigArray(this.config.always).map(t => guards_dist_xstateGuards.formatTransition(this, guards_dist_xstateGuards.NULL_EVENT, t));
196
+ this.always = interpreter.toTransitionConfigArray(this.config.always).map(t => guards_dist_xstateGuards.formatTransition(this, interpreter.NULL_EVENT, t));
146
197
  }
147
198
  Object.keys(this.states).forEach(key => {
148
199
  this.states[key]._initialize();
@@ -161,27 +212,27 @@ class StateNode {
161
212
  initial: this.initial ? {
162
213
  target: this.initial.target,
163
214
  source: this,
164
- actions: this.initial.actions.map(toSerializableActon),
215
+ actions: this.initial.actions.map(toSerializableAction),
165
216
  eventType: null,
166
217
  reenter: false,
167
218
  toJSON: () => ({
168
219
  target: this.initial.target.map(t => `#${t.id}`),
169
220
  source: `#${this.id}`,
170
- actions: this.initial.actions.map(toSerializableActon),
221
+ actions: this.initial.actions.map(toSerializableAction),
171
222
  eventType: null
172
223
  })
173
224
  } : undefined,
174
225
  history: this.history,
175
- states: guards_dist_xstateGuards.mapValues(this.states, state => {
226
+ states: interpreter.mapValues(this.states, state => {
176
227
  return state.definition;
177
228
  }),
178
229
  on: this.on,
179
230
  transitions: [...this.transitions.values()].flat().map(t => ({
180
231
  ...t,
181
- actions: t.actions.map(toSerializableActon)
232
+ actions: t.actions.map(toSerializableAction)
182
233
  })),
183
- entry: this.entry.map(toSerializableActon),
184
- exit: this.exit.map(toSerializableActon),
234
+ entry: this.entry.map(toSerializableAction),
235
+ exit: this.exit.map(toSerializableAction),
185
236
  meta: this.meta,
186
237
  order: this.order || -1,
187
238
  output: this.output,
@@ -198,12 +249,12 @@ class StateNode {
198
249
  * The logic invoked as actors by this state node.
199
250
  */
200
251
  get invoke() {
201
- return guards_dist_xstateGuards.memo(this, 'invoke', () => guards_dist_xstateGuards.toArray(this.config.invoke).map((invokeConfig, i) => {
252
+ return guards_dist_xstateGuards.memo(this, 'invoke', () => interpreter.toArray(this.config.invoke).map((invokeConfig, i) => {
202
253
  const {
203
254
  src,
204
255
  systemId
205
256
  } = invokeConfig;
206
- const resolvedId = invokeConfig.id || guards_dist_xstateGuards.createInvokeId(this.id, i);
257
+ const resolvedId = invokeConfig.id || interpreter.createInvokeId(this.id, i);
207
258
  // TODO: resolving should not happen here
208
259
  const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
209
260
  if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
@@ -433,7 +484,7 @@ class StateMachine {
433
484
  */
434
485
  transition(state, event, actorCtx) {
435
486
  // TODO: handle error events in a better way
436
- if (guards_dist_xstateGuards.isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
487
+ if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
437
488
  return guards_dist_xstateGuards.cloneState(state, {
438
489
  error: event.data
439
490
  });
@@ -482,7 +533,7 @@ class StateMachine {
482
533
  spawn,
483
534
  input: event.input
484
535
  });
485
- return guards_dist_xstateGuards.resolveActionsAndContext([guards_dist_xstateGuards.assign(assignment)], initEvent, preInitial, actorCtx);
536
+ return guards_dist_xstateGuards.resolveActionsAndContext([send.assign(assignment)], initEvent, preInitial, actorCtx);
486
537
  }
487
538
  return preInitial;
488
539
  }
@@ -491,7 +542,7 @@ class StateMachine {
491
542
  * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
492
543
  */
493
544
  getInitialState(actorCtx, input) {
494
- const initEvent = guards_dist_xstateGuards.createInitEvent(input); // TODO: fix;
545
+ const initEvent = interpreter.createInitEvent(input); // TODO: fix;
495
546
 
496
547
  const preInitialState = this.getPreInitialState(actorCtx, initEvent);
497
548
  const nextState = guards_dist_xstateGuards.microstep([{
@@ -515,7 +566,7 @@ class StateMachine {
515
566
  });
516
567
  }
517
568
  getStateNodeById(stateId) {
518
- const fullPath = stateId.split(guards_dist_xstateGuards.STATE_DELIMITER);
569
+ const fullPath = stateId.split(interpreter.STATE_DELIMITER);
519
570
  const relativePath = fullPath.slice(1);
520
571
  const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
521
572
  const stateNode = this.idMap.get(resolvedStateId);
@@ -553,12 +604,12 @@ class StateMachine {
553
604
  const actorData = state.children[actorId];
554
605
  const childState = actorData.state;
555
606
  const src = actorData.src;
556
- const logic = src ? guards_dist_xstateGuards.resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
607
+ const logic = src ? interpreter.resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
557
608
  if (!logic) {
558
609
  return;
559
610
  }
560
611
  const actorState = logic.restoreState?.(childState, _actorCtx);
561
- const actorRef = guards_dist_xstateGuards.createActor(logic, {
612
+ const actorRef = interpreter.createActor(logic, {
562
613
  id: actorId,
563
614
  state: actorState
564
615
  });
@@ -580,9 +631,9 @@ class StateMachine {
580
631
  if (children[id]) {
581
632
  return;
582
633
  }
583
- const referenced = guards_dist_xstateGuards.resolveReferencedActor(this.implementations.actors[src]);
634
+ const referenced = interpreter.resolveReferencedActor(this.implementations.actors[src]);
584
635
  if (referenced) {
585
- const actorRef = guards_dist_xstateGuards.createActor(referenced.src, {
636
+ const actorRef = interpreter.createActor(referenced.src, {
586
637
  id,
587
638
  parent: _actorCtx?.self,
588
639
  input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
@@ -598,69 +649,6 @@ class StateMachine {
598
649
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
599
650
  }
600
651
 
601
- function createMachine(config, implementations) {
602
- return new StateMachine(config, implementations);
603
- }
604
-
605
- function mapState(stateMap, stateId) {
606
- let foundStateId;
607
- for (const mappedStateId of Object.keys(stateMap)) {
608
- if (guards_dist_xstateGuards.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
609
- foundStateId = mappedStateId;
610
- }
611
- }
612
- return stateMap[foundStateId];
613
- }
614
-
615
- class SimulatedClock {
616
- constructor() {
617
- this.timeouts = new Map();
618
- this._now = 0;
619
- this._id = 0;
620
- }
621
- now() {
622
- return this._now;
623
- }
624
- getId() {
625
- return this._id++;
626
- }
627
- setTimeout(fn, timeout) {
628
- const id = this.getId();
629
- this.timeouts.set(id, {
630
- start: this.now(),
631
- timeout,
632
- fn
633
- });
634
- return id;
635
- }
636
- clearTimeout(id) {
637
- this.timeouts.delete(id);
638
- }
639
- set(time) {
640
- if (this._now > time) {
641
- throw new Error('Unable to travel back in time');
642
- }
643
- this._now = time;
644
- this.flushTimeouts();
645
- }
646
- flushTimeouts() {
647
- [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
648
- const endA = timeoutA.start + timeoutA.timeout;
649
- const endB = timeoutB.start + timeoutB.timeout;
650
- return endB > endA ? -1 : 1;
651
- }).forEach(([id, timeout]) => {
652
- if (this.now() - timeout.start >= timeout.timeout) {
653
- this.timeouts.delete(id);
654
- timeout.fn.call(null);
655
- }
656
- });
657
- }
658
- increment(ms) {
659
- this._now += ms;
660
- this.flushTimeouts();
661
- }
662
- }
663
-
664
652
  const defaultWaitForOptions = {
665
653
  timeout: 10_000 // 10 seconds
666
654
  };
@@ -735,38 +723,52 @@ function waitFor(actorRef, predicate, options) {
735
723
  });
736
724
  }
737
725
 
738
- exports.Actor = guards_dist_xstateGuards.Actor;
739
- exports.ActorStatus = guards_dist_xstateGuards.ActorStatus;
740
- exports.ConstantPrefix = guards_dist_xstateGuards.ConstantPrefix;
741
- exports.InterpreterStatus = guards_dist_xstateGuards.InterpreterStatus;
742
- exports.SpecialTargets = guards_dist_xstateGuards.SpecialTargets;
726
+ function createMachine(config, implementations) {
727
+ return new StateMachine(config, implementations);
728
+ }
729
+
730
+ function mapState(stateMap, stateId) {
731
+ let foundStateId;
732
+ for (const mappedStateId of Object.keys(stateMap)) {
733
+ if (interpreter.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
734
+ foundStateId = mappedStateId;
735
+ }
736
+ }
737
+ return stateMap[foundStateId];
738
+ }
739
+
740
+ exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
741
+ exports.fromCallback = actors_dist_xstateActors.fromCallback;
742
+ exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
743
+ exports.fromObservable = actors_dist_xstateActors.fromObservable;
744
+ exports.fromPromise = actors_dist_xstateActors.fromPromise;
745
+ exports.fromTransition = actors_dist_xstateActors.fromTransition;
746
+ exports.Actor = interpreter.Actor;
747
+ exports.ActorStatus = interpreter.ActorStatus;
748
+ exports.InterpreterStatus = interpreter.InterpreterStatus;
749
+ exports.createActor = interpreter.createActor;
750
+ exports.interpret = interpreter.interpret;
751
+ exports.matchesState = interpreter.matchesState;
752
+ exports.pathToStateValue = interpreter.pathToStateValue;
753
+ exports.toObserver = interpreter.toObserver;
743
754
  exports.State = guards_dist_xstateGuards.State;
744
755
  exports.and = guards_dist_xstateGuards.and;
745
- exports.assign = guards_dist_xstateGuards.assign;
746
756
  exports.cancel = guards_dist_xstateGuards.cancel;
747
- exports.choose = guards_dist_xstateGuards.choose;
748
- exports.createActor = guards_dist_xstateGuards.createActor;
749
- exports.doneInvoke = guards_dist_xstateGuards.doneInvoke;
750
- exports.forwardTo = guards_dist_xstateGuards.forwardTo;
751
757
  exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
752
- exports.interpret = guards_dist_xstateGuards.interpret;
753
- exports.log = guards_dist_xstateGuards.log;
754
- exports.matchesState = guards_dist_xstateGuards.matchesState;
755
758
  exports.not = guards_dist_xstateGuards.not;
756
759
  exports.or = guards_dist_xstateGuards.or;
757
- exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
758
- exports.pure = guards_dist_xstateGuards.pure;
759
760
  exports.raise = guards_dist_xstateGuards.raise;
760
- exports.sendParent = guards_dist_xstateGuards.sendParent;
761
- exports.sendTo = guards_dist_xstateGuards.sendTo;
762
761
  exports.stateIn = guards_dist_xstateGuards.stateIn;
763
762
  exports.stop = guards_dist_xstateGuards.stop;
764
- exports.toObserver = guards_dist_xstateGuards.toObserver;
765
- exports.fromCallback = promise.fromCallback;
766
- exports.fromEventObservable = promise.fromEventObservable;
767
- exports.fromObservable = promise.fromObservable;
768
- exports.fromPromise = promise.fromPromise;
769
- exports.fromTransition = promise.fromTransition;
763
+ exports.SpecialTargets = send.SpecialTargets;
764
+ exports.assign = send.assign;
765
+ exports.choose = send.choose;
766
+ exports.escalate = send.escalate;
767
+ exports.forwardTo = send.forwardTo;
768
+ exports.log = send.log;
769
+ exports.pure = send.pure;
770
+ exports.sendParent = send.sendParent;
771
+ exports.sendTo = send.sendTo;
770
772
  exports.SimulatedClock = SimulatedClock;
771
773
  exports.StateMachine = StateMachine;
772
774
  exports.StateNode = StateNode;
@@ -1,7 +1,6 @@
1
1
  export {
2
2
  Actor,
3
3
  ActorStatus,
4
- ConstantPrefix,
5
4
  InterpreterStatus,
6
5
  SimulatedClock,
7
6
  SpecialTargets,
@@ -13,8 +12,9 @@ export {
13
12
  cancel,
14
13
  choose,
15
14
  createActor,
15
+ createEmptyActor,
16
16
  createMachine,
17
- doneInvoke,
17
+ escalate,
18
18
  forwardTo,
19
19
  fromCallback,
20
20
  fromEventObservable,
@@ -1,10 +1,63 @@
1
- import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as createInvokeId, g as getDelayedTransitions, h as formatInitialTransition, i as getCandidates, j as getConfiguration, k as getStateNodes, r as resolveStateValue, l as isInFinalState, n as State, o as isErrorEvent, p as cloneState, q as macrostep, s as transitionNode, u as getInitialConfiguration, v as resolveActionsAndContext, w as assign, x as createInitEvent, y as microstep, z as isAtomicStateNode, A as isStateId, B as getStateNodeByPath, C as getPersistedState, D as resolveReferencedActor, E as createActor, F as matchesState } from './actions-9754d2ca.development.esm.js';
2
- export { G as Actor, H as ActorStatus, a0 as ConstantPrefix, K as InterpreterStatus, a1 as SpecialTargets, n as State, Y as and, w as assign, L as cancel, M as choose, E as createActor, I as doneInvoke, R as forwardTo, k as getStateNodes, J as interpret, O as log, F as matchesState, Z as not, _ as or, W as pathToStateValue, P as pure, Q as raise, T as sendParent, U as sendTo, $ as stateIn, V as stop, X as toObserver } from './actions-9754d2ca.development.esm.js';
3
- export { f as fromCallback, a as fromEventObservable, b as fromObservable, c as fromPromise, d as fromTransition } from './promise-2ad94e3b.development.esm.js';
1
+ export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
2
+ import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-6e7909c8.development.esm.js';
3
+ export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-6e7909c8.development.esm.js';
4
+ import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-e778a828.development.esm.js';
5
+ export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-e778a828.development.esm.js';
6
+ import { a as assign } from './send-42c83fb2.development.esm.js';
7
+ export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-42c83fb2.development.esm.js';
4
8
  import '../dev/dist/xstate-dev.development.esm.js';
5
9
 
10
+ class SimulatedClock {
11
+ constructor() {
12
+ this.timeouts = new Map();
13
+ this._now = 0;
14
+ this._id = 0;
15
+ }
16
+ now() {
17
+ return this._now;
18
+ }
19
+ getId() {
20
+ return this._id++;
21
+ }
22
+ setTimeout(fn, timeout) {
23
+ const id = this.getId();
24
+ this.timeouts.set(id, {
25
+ start: this.now(),
26
+ timeout,
27
+ fn
28
+ });
29
+ return id;
30
+ }
31
+ clearTimeout(id) {
32
+ this.timeouts.delete(id);
33
+ }
34
+ set(time) {
35
+ if (this._now > time) {
36
+ throw new Error('Unable to travel back in time');
37
+ }
38
+ this._now = time;
39
+ this.flushTimeouts();
40
+ }
41
+ flushTimeouts() {
42
+ [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
43
+ const endA = timeoutA.start + timeoutA.timeout;
44
+ const endB = timeoutB.start + timeoutB.timeout;
45
+ return endB > endA ? -1 : 1;
46
+ }).forEach(([id, timeout]) => {
47
+ if (this.now() - timeout.start >= timeout.timeout) {
48
+ this.timeouts.delete(id);
49
+ timeout.fn.call(null);
50
+ }
51
+ });
52
+ }
53
+ increment(ms) {
54
+ this._now += ms;
55
+ this.flushTimeouts();
56
+ }
57
+ }
58
+
6
59
  const EMPTY_OBJECT = {};
7
- const toSerializableActon = action => {
60
+ const toSerializableAction = action => {
8
61
  if (typeof action === 'string') {
9
62
  return {
10
63
  type: action
@@ -77,7 +130,7 @@ class StateNode {
77
130
  */
78
131
 
79
132
  /**
80
- * The output data sent with the "done.state._id_" event if this is a final state node.
133
+ * The output data sent with the "xstate.done.state._id_" event if this is a final state node.
81
134
  */
82
135
 
83
136
  /**
@@ -158,13 +211,13 @@ class StateNode {
158
211
  initial: this.initial ? {
159
212
  target: this.initial.target,
160
213
  source: this,
161
- actions: this.initial.actions.map(toSerializableActon),
214
+ actions: this.initial.actions.map(toSerializableAction),
162
215
  eventType: null,
163
216
  reenter: false,
164
217
  toJSON: () => ({
165
218
  target: this.initial.target.map(t => `#${t.id}`),
166
219
  source: `#${this.id}`,
167
- actions: this.initial.actions.map(toSerializableActon),
220
+ actions: this.initial.actions.map(toSerializableAction),
168
221
  eventType: null
169
222
  })
170
223
  } : undefined,
@@ -175,10 +228,10 @@ class StateNode {
175
228
  on: this.on,
176
229
  transitions: [...this.transitions.values()].flat().map(t => ({
177
230
  ...t,
178
- actions: t.actions.map(toSerializableActon)
231
+ actions: t.actions.map(toSerializableAction)
179
232
  })),
180
- entry: this.entry.map(toSerializableActon),
181
- exit: this.exit.map(toSerializableActon),
233
+ entry: this.entry.map(toSerializableAction),
234
+ exit: this.exit.map(toSerializableAction),
182
235
  meta: this.meta,
183
236
  order: this.order || -1,
184
237
  output: this.output,
@@ -430,7 +483,7 @@ class StateMachine {
430
483
  */
431
484
  transition(state, event, actorCtx) {
432
485
  // TODO: handle error events in a better way
433
- if (isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
486
+ if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
434
487
  return cloneState(state, {
435
488
  error: event.data
436
489
  });
@@ -595,69 +648,6 @@ class StateMachine {
595
648
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
596
649
  }
597
650
 
598
- function createMachine(config, implementations) {
599
- return new StateMachine(config, implementations);
600
- }
601
-
602
- function mapState(stateMap, stateId) {
603
- let foundStateId;
604
- for (const mappedStateId of Object.keys(stateMap)) {
605
- if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
606
- foundStateId = mappedStateId;
607
- }
608
- }
609
- return stateMap[foundStateId];
610
- }
611
-
612
- class SimulatedClock {
613
- constructor() {
614
- this.timeouts = new Map();
615
- this._now = 0;
616
- this._id = 0;
617
- }
618
- now() {
619
- return this._now;
620
- }
621
- getId() {
622
- return this._id++;
623
- }
624
- setTimeout(fn, timeout) {
625
- const id = this.getId();
626
- this.timeouts.set(id, {
627
- start: this.now(),
628
- timeout,
629
- fn
630
- });
631
- return id;
632
- }
633
- clearTimeout(id) {
634
- this.timeouts.delete(id);
635
- }
636
- set(time) {
637
- if (this._now > time) {
638
- throw new Error('Unable to travel back in time');
639
- }
640
- this._now = time;
641
- this.flushTimeouts();
642
- }
643
- flushTimeouts() {
644
- [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
645
- const endA = timeoutA.start + timeoutA.timeout;
646
- const endB = timeoutB.start + timeoutB.timeout;
647
- return endB > endA ? -1 : 1;
648
- }).forEach(([id, timeout]) => {
649
- if (this.now() - timeout.start >= timeout.timeout) {
650
- this.timeouts.delete(id);
651
- timeout.fn.call(null);
652
- }
653
- });
654
- }
655
- increment(ms) {
656
- this._now += ms;
657
- this.flushTimeouts();
658
- }
659
- }
660
-
661
651
  const defaultWaitForOptions = {
662
652
  timeout: 10_000 // 10 seconds
663
653
  };
@@ -732,4 +722,18 @@ function waitFor(actorRef, predicate, options) {
732
722
  });
733
723
  }
734
724
 
725
+ function createMachine(config, implementations) {
726
+ return new StateMachine(config, implementations);
727
+ }
728
+
729
+ function mapState(stateMap, stateId) {
730
+ let foundStateId;
731
+ for (const mappedStateId of Object.keys(stateMap)) {
732
+ if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
733
+ foundStateId = mappedStateId;
734
+ }
735
+ }
736
+ return stateMap[foundStateId];
737
+ }
738
+
735
739
  export { SimulatedClock, StateMachine, StateNode, createMachine, mapState, waitFor };