xstate 5.0.0-beta.27 → 5.0.0-beta.28

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 (59) 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 +413 -11
  11. package/actors/dist/xstate-actors.development.cjs.js +413 -11
  12. package/actors/dist/xstate-actors.development.esm.js +405 -4
  13. package/actors/dist/xstate-actors.esm.js +405 -4
  14. package/actors/dist/xstate-actors.umd.min.js +1 -1
  15. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  16. package/dist/declarations/src/StateNode.d.ts +3 -3
  17. package/dist/declarations/src/actions/assign.d.ts +8 -3
  18. package/dist/declarations/src/actions/choose.d.ts +4 -3
  19. package/dist/declarations/src/actions/pure.d.ts +5 -4
  20. package/dist/declarations/src/actions.d.ts +8 -44
  21. package/dist/declarations/src/actors/index.d.ts +2 -2
  22. package/dist/declarations/src/constants.d.ts +1 -0
  23. package/dist/declarations/src/index.d.ts +9 -16
  24. package/dist/declarations/src/spawn.d.ts +25 -0
  25. package/dist/declarations/src/stateUtils.d.ts +1 -1
  26. package/dist/declarations/src/typegenTypes.d.ts +4 -4
  27. package/dist/declarations/src/types.d.ts +72 -94
  28. package/dist/declarations/src/utils.d.ts +2 -2
  29. package/dist/interpreter-672794ae.cjs.js +792 -0
  30. package/dist/interpreter-a1432c7d.development.cjs.js +800 -0
  31. package/dist/interpreter-a77bb0ec.development.esm.js +765 -0
  32. package/dist/interpreter-b5203bcb.esm.js +757 -0
  33. package/dist/{actions-9754d2ca.development.esm.js → raise-436a57a2.cjs.js} +130 -1307
  34. package/dist/{actions-ca622922.development.cjs.js → raise-74b72ca5.development.cjs.js} +101 -1306
  35. package/dist/{actions-020463e9.esm.js → raise-a60c9290.development.esm.js} +109 -1203
  36. package/dist/{actions-d1dba4ac.cjs.js → raise-b9c9a234.esm.js} +65 -1267
  37. package/dist/send-35e1a689.cjs.js +349 -0
  38. package/dist/send-4192e7bc.esm.js +339 -0
  39. package/dist/send-e63b7b83.development.esm.js +364 -0
  40. package/dist/send-e8b55d00.development.cjs.js +374 -0
  41. package/dist/xstate.cjs.js +110 -106
  42. package/dist/xstate.cjs.mjs +4 -2
  43. package/dist/xstate.development.cjs.js +110 -106
  44. package/dist/xstate.development.cjs.mjs +4 -2
  45. package/dist/xstate.development.esm.js +72 -68
  46. package/dist/xstate.esm.js +72 -68
  47. package/dist/xstate.umd.min.js +1 -1
  48. package/dist/xstate.umd.min.js.map +1 -1
  49. package/guards/dist/xstate-guards.cjs.js +2 -1
  50. package/guards/dist/xstate-guards.development.cjs.js +2 -1
  51. package/guards/dist/xstate-guards.development.esm.js +2 -1
  52. package/guards/dist/xstate-guards.esm.js +2 -1
  53. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  54. package/package.json +1 -1
  55. package/dist/declarations/src/constantPrefixes.d.ts +0 -6
  56. package/dist/promise-2ad94e3b.development.esm.js +0 -406
  57. package/dist/promise-3b7e3357.development.cjs.js +0 -412
  58. package/dist/promise-5b07c38e.esm.js +0 -406
  59. package/dist/promise-7a8c1768.cjs.js +0 -412
@@ -2,10 +2,61 @@
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-a1432c7d.development.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-74b72ca5.development.cjs.js');
8
+ var send = require('./send-e8b55d00.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
61
  const toSerializableActon = action => {
11
62
  if (typeof action === 'string') {
@@ -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();
@@ -172,7 +223,7 @@ class StateNode {
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,
@@ -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,54 @@ 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.isActorRef = actors_dist_xstateActors.isActorRef;
747
+ exports.toActorRef = actors_dist_xstateActors.toActorRef;
748
+ exports.Actor = interpreter.Actor;
749
+ exports.ActorStatus = interpreter.ActorStatus;
750
+ exports.InterpreterStatus = interpreter.InterpreterStatus;
751
+ exports.createActor = interpreter.createActor;
752
+ exports.interpret = interpreter.interpret;
753
+ exports.matchesState = interpreter.matchesState;
754
+ exports.pathToStateValue = interpreter.pathToStateValue;
755
+ exports.toObserver = interpreter.toObserver;
743
756
  exports.State = guards_dist_xstateGuards.State;
744
757
  exports.and = guards_dist_xstateGuards.and;
745
- exports.assign = guards_dist_xstateGuards.assign;
746
758
  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
759
  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
760
  exports.not = guards_dist_xstateGuards.not;
756
761
  exports.or = guards_dist_xstateGuards.or;
757
- exports.pathToStateValue = guards_dist_xstateGuards.pathToStateValue;
758
- exports.pure = guards_dist_xstateGuards.pure;
759
762
  exports.raise = guards_dist_xstateGuards.raise;
760
- exports.sendParent = guards_dist_xstateGuards.sendParent;
761
- exports.sendTo = guards_dist_xstateGuards.sendTo;
762
763
  exports.stateIn = guards_dist_xstateGuards.stateIn;
763
764
  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;
765
+ exports.SpecialTargets = send.SpecialTargets;
766
+ exports.assign = send.assign;
767
+ exports.choose = send.choose;
768
+ exports.escalate = send.escalate;
769
+ exports.forwardTo = send.forwardTo;
770
+ exports.log = send.log;
771
+ exports.pure = send.pure;
772
+ exports.sendParent = send.sendParent;
773
+ exports.sendTo = send.sendTo;
770
774
  exports.SimulatedClock = SimulatedClock;
771
775
  exports.StateMachine = StateMachine;
772
776
  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,
@@ -23,6 +23,7 @@ export {
23
23
  fromTransition,
24
24
  getStateNodes,
25
25
  interpret,
26
+ isActorRef,
26
27
  log,
27
28
  mapState,
28
29
  matchesState,
@@ -35,6 +36,7 @@ export {
35
36
  sendTo,
36
37
  stateIn,
37
38
  stop,
39
+ toActorRef,
38
40
  toObserver,
39
41
  waitFor
40
42
  } from "./xstate.development.cjs.js";
@@ -1,8 +1,61 @@
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, isActorRef, toActorRef } 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-a77bb0ec.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-a77bb0ec.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-a60c9290.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-a60c9290.development.esm.js';
6
+ import { a as assign } from './send-e63b7b83.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-e63b7b83.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
60
  const toSerializableActon = action => {
8
61
  if (typeof action === 'string') {
@@ -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
  /**
@@ -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 };