xstate 5.0.0-beta.26 → 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 (71) hide show
  1. package/README.md +9 -7
  2. package/actions/dist/xstate-actions.cjs.js +14 -18
  3. package/actions/dist/xstate-actions.cjs.mjs +0 -6
  4. package/actions/dist/xstate-actions.development.cjs.js +14 -18
  5. package/actions/dist/xstate-actions.development.cjs.mjs +0 -6
  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 +439 -14
  11. package/actors/dist/xstate-actors.cjs.mjs +0 -5
  12. package/actors/dist/xstate-actors.development.cjs.js +439 -14
  13. package/actors/dist/xstate-actors.development.cjs.mjs +0 -5
  14. package/actors/dist/xstate-actors.development.esm.js +435 -1
  15. package/actors/dist/xstate-actors.esm.js +435 -1
  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/Machine.d.ts +4 -3
  19. package/dist/declarations/src/State.d.ts +1 -1
  20. package/dist/declarations/src/StateNode.d.ts +3 -12
  21. package/dist/declarations/src/actions/assign.d.ts +11 -11
  22. package/dist/declarations/src/actions/cancel.d.ts +5 -12
  23. package/dist/declarations/src/actions/choose.d.ts +9 -7
  24. package/dist/declarations/src/actions/log.d.ts +5 -20
  25. package/dist/declarations/src/actions/pure.d.ts +11 -9
  26. package/dist/declarations/src/actions/raise.d.ts +6 -5
  27. package/dist/declarations/src/actions/send.d.ts +7 -12
  28. package/dist/declarations/src/actions/stop.d.ts +5 -12
  29. package/dist/declarations/src/actions.d.ts +8 -42
  30. package/dist/declarations/src/actors/index.d.ts +2 -22
  31. package/dist/declarations/src/actors/promise.d.ts +2 -1
  32. package/dist/declarations/src/constants.d.ts +8 -0
  33. package/dist/declarations/src/guards.d.ts +2 -2
  34. package/dist/declarations/src/index.d.ts +11 -18
  35. package/dist/declarations/src/spawn.d.ts +25 -0
  36. package/dist/declarations/src/stateUtils.d.ts +1 -1
  37. package/dist/declarations/src/typegenTypes.d.ts +5 -5
  38. package/dist/declarations/src/types.d.ts +81 -108
  39. package/dist/declarations/src/utils.d.ts +2 -3
  40. package/dist/interpreter-672794ae.cjs.js +792 -0
  41. package/dist/interpreter-a1432c7d.development.cjs.js +800 -0
  42. package/dist/interpreter-a77bb0ec.development.esm.js +765 -0
  43. package/dist/interpreter-b5203bcb.esm.js +757 -0
  44. package/dist/raise-436a57a2.cjs.js +1458 -0
  45. package/dist/raise-74b72ca5.development.cjs.js +1498 -0
  46. package/dist/raise-a60c9290.development.esm.js +1468 -0
  47. package/dist/raise-b9c9a234.esm.js +1428 -0
  48. package/dist/send-35e1a689.cjs.js +349 -0
  49. package/dist/send-4192e7bc.esm.js +339 -0
  50. package/dist/send-e63b7b83.development.esm.js +364 -0
  51. package/dist/send-e8b55d00.development.cjs.js +374 -0
  52. package/dist/xstate.cjs.js +140 -160
  53. package/dist/xstate.cjs.mjs +4 -2
  54. package/dist/xstate.development.cjs.js +140 -160
  55. package/dist/xstate.development.cjs.mjs +4 -2
  56. package/dist/xstate.development.esm.js +75 -95
  57. package/dist/xstate.esm.js +75 -95
  58. package/dist/xstate.umd.min.js +1 -1
  59. package/dist/xstate.umd.min.js.map +1 -1
  60. package/guards/dist/xstate-guards.cjs.js +7 -6
  61. package/guards/dist/xstate-guards.development.cjs.js +7 -6
  62. package/guards/dist/xstate-guards.development.esm.js +2 -1
  63. package/guards/dist/xstate-guards.esm.js +2 -1
  64. package/guards/dist/xstate-guards.umd.min.js +1 -1
  65. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  66. package/package.json +1 -1
  67. package/dist/actions-0971b43d.development.cjs.js +0 -3168
  68. package/dist/actions-319cefe7.cjs.js +0 -3095
  69. package/dist/actions-5943a9db.esm.js +0 -3018
  70. package/dist/actions-cf69419d.development.esm.js +0 -3091
  71. package/dist/declarations/src/constantPrefixes.d.ts +0 -6
@@ -2,9 +2,61 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var actors_dist_xstateActors = require('./actions-319cefe7.cjs.js');
5
+ var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
6
+ var interpreter = require('./interpreter-672794ae.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-436a57a2.cjs.js');
8
+ var send = require('./send-35e1a689.cjs.js');
6
9
  require('../dev/dist/xstate-dev.cjs.js');
7
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
+
8
60
  const EMPTY_OBJECT = {};
9
61
  const toSerializableActon = action => {
10
62
  if (typeof action === 'string') {
@@ -79,7 +131,7 @@ class StateNode {
79
131
  */
80
132
 
81
133
  /**
82
- * 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.
83
135
  */
84
136
 
85
137
  /**
@@ -113,12 +165,12 @@ class StateNode {
113
165
  this.key = options._key;
114
166
  this.machine = options._machine;
115
167
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
116
- this.id = this.config.id || [this.machine.id, ...this.path].join(actors_dist_xstateActors.STATE_DELIMITER);
168
+ this.id = this.config.id || [this.machine.id, ...this.path].join(interpreter.STATE_DELIMITER);
117
169
  this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
118
170
  this.description = this.config.description;
119
171
  this.order = this.machine.idMap.size;
120
172
  this.machine.idMap.set(this.id, this);
121
- this.states = this.config.states ? actors_dist_xstateActors.mapValues(this.config.states, (stateConfig, key) => {
173
+ this.states = this.config.states ? interpreter.mapValues(this.config.states, (stateConfig, key) => {
122
174
  const stateNode = new StateNode(stateConfig, {
123
175
  _parent: this,
124
176
  _key: key,
@@ -132,16 +184,16 @@ class StateNode {
132
184
 
133
185
  // History config
134
186
  this.history = this.config.history === true ? 'shallow' : this.config.history || false;
135
- this.entry = actors_dist_xstateActors.toArray(this.config.entry).slice();
136
- this.exit = actors_dist_xstateActors.toArray(this.config.exit).slice();
187
+ this.entry = interpreter.toArray(this.config.entry).slice();
188
+ this.exit = interpreter.toArray(this.config.exit).slice();
137
189
  this.meta = this.config.meta;
138
190
  this.output = this.type === 'final' ? this.config.output : undefined;
139
- this.tags = actors_dist_xstateActors.toArray(config.tags).slice();
191
+ this.tags = interpreter.toArray(config.tags).slice();
140
192
  }
141
193
  _initialize() {
142
- this.transitions = actors_dist_xstateActors.formatTransitions(this);
194
+ this.transitions = guards_dist_xstateGuards.formatTransitions(this);
143
195
  if (this.config.always) {
144
- this.always = actors_dist_xstateActors.toTransitionConfigArray(this.config.always).map(t => actors_dist_xstateActors.formatTransition(this, actors_dist_xstateActors.NULL_EVENT, t));
196
+ this.always = interpreter.toTransitionConfigArray(this.config.always).map(t => guards_dist_xstateGuards.formatTransition(this, interpreter.NULL_EVENT, t));
145
197
  }
146
198
  Object.keys(this.states).forEach(key => {
147
199
  this.states[key]._initialize();
@@ -171,7 +223,7 @@ class StateNode {
171
223
  })
172
224
  } : undefined,
173
225
  history: this.history,
174
- states: actors_dist_xstateActors.mapValues(this.states, state => {
226
+ states: interpreter.mapValues(this.states, state => {
175
227
  return state.definition;
176
228
  }),
177
229
  on: this.on,
@@ -197,15 +249,12 @@ class StateNode {
197
249
  * The logic invoked as actors by this state node.
198
250
  */
199
251
  get invoke() {
200
- return actors_dist_xstateActors.memo(this, 'invoke', () => actors_dist_xstateActors.toArray(this.config.invoke).map((invocable, i) => {
201
- const generatedId = actors_dist_xstateActors.createInvokeId(this.id, i);
202
- const invokeConfig = actors_dist_xstateActors.toInvokeConfig(invocable, generatedId);
203
- const resolvedId = invokeConfig.id || generatedId;
204
- const src = invokeConfig.src;
252
+ return guards_dist_xstateGuards.memo(this, 'invoke', () => interpreter.toArray(this.config.invoke).map((invokeConfig, i) => {
205
253
  const {
254
+ src,
206
255
  systemId
207
256
  } = invokeConfig;
208
-
257
+ const resolvedId = invokeConfig.id || interpreter.createInvokeId(this.id, i);
209
258
  // TODO: resolving should not happen here
210
259
  const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
211
260
  if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
@@ -241,7 +290,7 @@ class StateNode {
241
290
  * The mapping of events to transitions.
242
291
  */
243
292
  get on() {
244
- return actors_dist_xstateActors.memo(this, 'on', () => {
293
+ return guards_dist_xstateGuards.memo(this, 'on', () => {
245
294
  const transitions = this.transitions;
246
295
  return [...transitions].flatMap(([descriptor, t]) => t.map(t => [descriptor, t])).reduce((map, [descriptor, transition]) => {
247
296
  map[descriptor] = map[descriptor] || [];
@@ -251,16 +300,16 @@ class StateNode {
251
300
  });
252
301
  }
253
302
  get after() {
254
- return actors_dist_xstateActors.memo(this, 'delayedTransitions', () => actors_dist_xstateActors.getDelayedTransitions(this));
303
+ return guards_dist_xstateGuards.memo(this, 'delayedTransitions', () => guards_dist_xstateGuards.getDelayedTransitions(this));
255
304
  }
256
305
  get initial() {
257
- return actors_dist_xstateActors.memo(this, 'initial', () => actors_dist_xstateActors.formatInitialTransition(this, this.config.initial || []));
306
+ return guards_dist_xstateGuards.memo(this, 'initial', () => guards_dist_xstateGuards.formatInitialTransition(this, this.config.initial || []));
258
307
  }
259
308
  next(state, event) {
260
309
  const eventType = event.type;
261
310
  const actions = [];
262
311
  let selectedTransition;
263
- const candidates = actors_dist_xstateActors.memo(this, `candidates-${eventType}`, () => actors_dist_xstateActors.getCandidates(this, eventType));
312
+ const candidates = guards_dist_xstateGuards.memo(this, `candidates-${eventType}`, () => guards_dist_xstateGuards.getCandidates(this, eventType));
264
313
  for (const candidate of candidates) {
265
314
  const {
266
315
  guard
@@ -268,7 +317,7 @@ class StateNode {
268
317
  const resolvedContext = state.context;
269
318
  let guardPassed = false;
270
319
  try {
271
- guardPassed = !guard || actors_dist_xstateActors.evaluateGuard(guard, resolvedContext, event, state);
320
+ guardPassed = !guard || guards_dist_xstateGuards.evaluateGuard(guard, resolvedContext, event, state);
272
321
  } catch (err) {
273
322
  const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
274
323
  throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
@@ -282,33 +331,11 @@ class StateNode {
282
331
  return selectedTransition ? [selectedTransition] : undefined;
283
332
  }
284
333
 
285
- /**
286
- * The target state value of the history state node, if it exists. This represents the
287
- * default state value to transition to if no history value exists yet.
288
- */
289
- get target() {
290
- if (this.type === 'history') {
291
- const historyConfig = this.config;
292
- return historyConfig.target;
293
- }
294
- return undefined;
295
- }
296
-
297
- /**
298
- * All the state node IDs of this state node and its descendant state nodes.
299
- */
300
- get stateIds() {
301
- const childStateIds = actors_dist_xstateActors.flatten(Object.keys(this.states).map(stateKey => {
302
- return this.states[stateKey].stateIds;
303
- }));
304
- return [this.id].concat(childStateIds);
305
- }
306
-
307
334
  /**
308
335
  * All the event types accepted by this state node and its descendants.
309
336
  */
310
337
  get events() {
311
- return actors_dist_xstateActors.memo(this, 'events', () => {
338
+ return guards_dist_xstateGuards.memo(this, 'events', () => {
312
339
  const {
313
340
  states
314
341
  } = this;
@@ -434,18 +461,18 @@ class StateMachine {
434
461
  * @param state The state to resolve
435
462
  */
436
463
  resolveState(state) {
437
- const configurationSet = actors_dist_xstateActors.getConfiguration(actors_dist_xstateActors.getStateNodes(this.root, state.value));
464
+ const configurationSet = guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, state.value));
438
465
  const configuration = Array.from(configurationSet);
439
466
  return this.createState({
440
467
  ...state,
441
- value: actors_dist_xstateActors.resolveStateValue(this.root, state.value),
468
+ value: guards_dist_xstateGuards.resolveStateValue(this.root, state.value),
442
469
  configuration,
443
- done: actors_dist_xstateActors.isInFinalState(configuration)
470
+ done: guards_dist_xstateGuards.isInFinalState(configuration)
444
471
  });
445
472
  }
446
473
  resolveStateValue(stateValue, ...[context]) {
447
- const resolvedStateValue = actors_dist_xstateActors.resolveStateValue(this.root, stateValue);
448
- return this.resolveState(actors_dist_xstateActors.State.from(resolvedStateValue, context, this));
474
+ const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, stateValue);
475
+ return this.resolveState(guards_dist_xstateGuards.State.from(resolvedStateValue, context, this));
449
476
  }
450
477
 
451
478
  /**
@@ -457,14 +484,14 @@ class StateMachine {
457
484
  */
458
485
  transition(state, event, actorCtx) {
459
486
  // TODO: handle error events in a better way
460
- if (actors_dist_xstateActors.isErrorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
461
- return actors_dist_xstateActors.cloneState(state, {
487
+ if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
488
+ return guards_dist_xstateGuards.cloneState(state, {
462
489
  error: event.data
463
490
  });
464
491
  }
465
492
  const {
466
493
  state: nextState
467
- } = actors_dist_xstateActors.macrostep(state, event, actorCtx);
494
+ } = guards_dist_xstateGuards.macrostep(state, event, actorCtx);
468
495
  return nextState;
469
496
  }
470
497
 
@@ -476,10 +503,10 @@ class StateMachine {
476
503
  * @param event The received event
477
504
  */
478
505
  microstep(state, event, actorCtx) {
479
- return actors_dist_xstateActors.macrostep(state, event, actorCtx).microstates;
506
+ return guards_dist_xstateGuards.macrostep(state, event, actorCtx).microstates;
480
507
  }
481
508
  getTransitionData(state, event) {
482
- return actors_dist_xstateActors.transitionNode(this.root, state.value, state, event) || [];
509
+ return guards_dist_xstateGuards.transitionNode(this.root, state.value, state, event) || [];
483
510
  }
484
511
 
485
512
  /**
@@ -495,7 +522,7 @@ class StateMachine {
495
522
  // TODO: this is computed in state constructor
496
523
  context: typeof context !== 'function' && context ? context : {},
497
524
  meta: undefined,
498
- configuration: actors_dist_xstateActors.getInitialConfiguration(this.root),
525
+ configuration: guards_dist_xstateGuards.getInitialConfiguration(this.root),
499
526
  children: {}
500
527
  }));
501
528
  if (typeof context === 'function') {
@@ -506,7 +533,7 @@ class StateMachine {
506
533
  spawn,
507
534
  input: event.input
508
535
  });
509
- return actors_dist_xstateActors.resolveActionsAndContext([actors_dist_xstateActors.assign(assignment)], initEvent, preInitial, actorCtx);
536
+ return guards_dist_xstateGuards.resolveActionsAndContext([send.assign(assignment)], initEvent, preInitial, actorCtx);
510
537
  }
511
538
  return preInitial;
512
539
  }
@@ -515,11 +542,11 @@ class StateMachine {
515
542
  * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
516
543
  */
517
544
  getInitialState(actorCtx, input) {
518
- const initEvent = actors_dist_xstateActors.createInitEvent(input); // TODO: fix;
545
+ const initEvent = interpreter.createInitEvent(input); // TODO: fix;
519
546
 
520
547
  const preInitialState = this.getPreInitialState(actorCtx, initEvent);
521
- const nextState = actors_dist_xstateActors.microstep([{
522
- target: [...preInitialState.configuration].filter(actors_dist_xstateActors.isAtomicStateNode),
548
+ const nextState = guards_dist_xstateGuards.microstep([{
549
+ target: [...preInitialState.configuration].filter(guards_dist_xstateGuards.isAtomicStateNode),
523
550
  source: this.root,
524
551
  reenter: true,
525
552
  actions: [],
@@ -528,7 +555,7 @@ class StateMachine {
528
555
  }], preInitialState, actorCtx, initEvent, true);
529
556
  const {
530
557
  state: macroState
531
- } = actors_dist_xstateActors.macrostep(nextState, initEvent, actorCtx);
558
+ } = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorCtx);
532
559
  return macroState;
533
560
  }
534
561
  start(state) {
@@ -539,14 +566,14 @@ class StateMachine {
539
566
  });
540
567
  }
541
568
  getStateNodeById(stateId) {
542
- const fullPath = stateId.split(actors_dist_xstateActors.STATE_DELIMITER);
569
+ const fullPath = stateId.split(interpreter.STATE_DELIMITER);
543
570
  const relativePath = fullPath.slice(1);
544
- const resolvedStateId = actors_dist_xstateActors.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
571
+ const resolvedStateId = guards_dist_xstateGuards.isStateId(fullPath[0]) ? fullPath[0].slice(STATE_IDENTIFIER.length) : fullPath[0];
545
572
  const stateNode = this.idMap.get(resolvedStateId);
546
573
  if (!stateNode) {
547
574
  throw new Error(`Child state node '#${resolvedStateId}' does not exist on machine '${this.id}'`);
548
575
  }
549
- return actors_dist_xstateActors.getStateNodeByPath(stateNode, relativePath);
576
+ return guards_dist_xstateGuards.getStateNodeByPath(stateNode, relativePath);
550
577
  }
551
578
  get definition() {
552
579
  return this.root.definition;
@@ -555,10 +582,10 @@ class StateMachine {
555
582
  return this.definition;
556
583
  }
557
584
  getPersistedState(state) {
558
- return actors_dist_xstateActors.getPersistedState(state);
585
+ return guards_dist_xstateGuards.getPersistedState(state);
559
586
  }
560
587
  createState(stateConfig) {
561
- return stateConfig instanceof actors_dist_xstateActors.State ? stateConfig : new actors_dist_xstateActors.State(stateConfig, this);
588
+ return stateConfig instanceof guards_dist_xstateGuards.State ? stateConfig : new guards_dist_xstateGuards.State(stateConfig, this);
562
589
  }
563
590
  getStatus(state) {
564
591
  return state.error ? {
@@ -577,18 +604,18 @@ class StateMachine {
577
604
  const actorData = state.children[actorId];
578
605
  const childState = actorData.state;
579
606
  const src = actorData.src;
580
- const logic = src ? actors_dist_xstateActors.resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
607
+ const logic = src ? interpreter.resolveReferencedActor(this.implementations.actors[src])?.src : undefined;
581
608
  if (!logic) {
582
609
  return;
583
610
  }
584
611
  const actorState = logic.restoreState?.(childState, _actorCtx);
585
- const actorRef = actors_dist_xstateActors.createActor(logic, {
612
+ const actorRef = interpreter.createActor(logic, {
586
613
  id: actorId,
587
614
  state: actorState
588
615
  });
589
616
  children[actorId] = actorRef;
590
617
  });
591
- const restoredState = this.createState(new actors_dist_xstateActors.State({
618
+ const restoredState = this.createState(new guards_dist_xstateGuards.State({
592
619
  ...state,
593
620
  children
594
621
  }, this));
@@ -604,9 +631,9 @@ class StateMachine {
604
631
  if (children[id]) {
605
632
  return;
606
633
  }
607
- const referenced = actors_dist_xstateActors.resolveReferencedActor(this.implementations.actors[src]);
634
+ const referenced = interpreter.resolveReferencedActor(this.implementations.actors[src]);
608
635
  if (referenced) {
609
- const actorRef = actors_dist_xstateActors.createActor(referenced.src, {
636
+ const actorRef = interpreter.createActor(referenced.src, {
610
637
  id,
611
638
  parent: _actorCtx?.self,
612
639
  input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
@@ -622,69 +649,6 @@ class StateMachine {
622
649
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
623
650
  }
624
651
 
625
- function createMachine(config, implementations) {
626
- return new StateMachine(config, implementations);
627
- }
628
-
629
- function mapState(stateMap, stateId) {
630
- let foundStateId;
631
- for (const mappedStateId of Object.keys(stateMap)) {
632
- if (actors_dist_xstateActors.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
633
- foundStateId = mappedStateId;
634
- }
635
- }
636
- return stateMap[foundStateId];
637
- }
638
-
639
- class SimulatedClock {
640
- constructor() {
641
- this.timeouts = new Map();
642
- this._now = 0;
643
- this._id = 0;
644
- }
645
- now() {
646
- return this._now;
647
- }
648
- getId() {
649
- return this._id++;
650
- }
651
- setTimeout(fn, timeout) {
652
- const id = this.getId();
653
- this.timeouts.set(id, {
654
- start: this.now(),
655
- timeout,
656
- fn
657
- });
658
- return id;
659
- }
660
- clearTimeout(id) {
661
- this.timeouts.delete(id);
662
- }
663
- set(time) {
664
- if (this._now > time) {
665
- throw new Error('Unable to travel back in time');
666
- }
667
- this._now = time;
668
- this.flushTimeouts();
669
- }
670
- flushTimeouts() {
671
- [...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
672
- const endA = timeoutA.start + timeoutA.timeout;
673
- const endB = timeoutB.start + timeoutB.timeout;
674
- return endB > endA ? -1 : 1;
675
- }).forEach(([id, timeout]) => {
676
- if (this.now() - timeout.start >= timeout.timeout) {
677
- this.timeouts.delete(id);
678
- timeout.fn.call(null);
679
- }
680
- });
681
- }
682
- increment(ms) {
683
- this._now += ms;
684
- this.flushTimeouts();
685
- }
686
- }
687
-
688
652
  const defaultWaitForOptions = {
689
653
  timeout: 10_000 // 10 seconds
690
654
  };
@@ -756,38 +720,54 @@ function waitFor(actorRef, predicate, options) {
756
720
  });
757
721
  }
758
722
 
759
- exports.Actor = actors_dist_xstateActors.Actor;
760
- exports.ActorStatus = actors_dist_xstateActors.ActorStatus;
761
- exports.ConstantPrefix = actors_dist_xstateActors.ConstantPrefix;
762
- exports.InterpreterStatus = actors_dist_xstateActors.InterpreterStatus;
763
- exports.SpecialTargets = actors_dist_xstateActors.SpecialTargets;
764
- exports.State = actors_dist_xstateActors.State;
765
- exports.and = actors_dist_xstateActors.and;
766
- exports.assign = actors_dist_xstateActors.assign;
767
- exports.cancel = actors_dist_xstateActors.cancel;
768
- exports.choose = actors_dist_xstateActors.choose;
769
- exports.createActor = actors_dist_xstateActors.createActor;
770
- exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
771
- exports.forwardTo = actors_dist_xstateActors.forwardTo;
723
+ function createMachine(config, implementations) {
724
+ return new StateMachine(config, implementations);
725
+ }
726
+
727
+ function mapState(stateMap, stateId) {
728
+ let foundStateId;
729
+ for (const mappedStateId of Object.keys(stateMap)) {
730
+ if (interpreter.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
731
+ foundStateId = mappedStateId;
732
+ }
733
+ }
734
+ return stateMap[foundStateId];
735
+ }
736
+
737
+ exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
772
738
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
773
739
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
774
740
  exports.fromObservable = actors_dist_xstateActors.fromObservable;
775
741
  exports.fromPromise = actors_dist_xstateActors.fromPromise;
776
742
  exports.fromTransition = actors_dist_xstateActors.fromTransition;
777
- exports.getStateNodes = actors_dist_xstateActors.getStateNodes;
778
- exports.interpret = actors_dist_xstateActors.interpret;
779
- exports.log = actors_dist_xstateActors.log;
780
- exports.matchesState = actors_dist_xstateActors.matchesState;
781
- exports.not = actors_dist_xstateActors.not;
782
- exports.or = actors_dist_xstateActors.or;
783
- exports.pathToStateValue = actors_dist_xstateActors.pathToStateValue;
784
- exports.pure = actors_dist_xstateActors.pure;
785
- exports.raise = actors_dist_xstateActors.raise;
786
- exports.sendParent = actors_dist_xstateActors.sendParent;
787
- exports.sendTo = actors_dist_xstateActors.sendTo;
788
- exports.stateIn = actors_dist_xstateActors.stateIn;
789
- exports.stop = actors_dist_xstateActors.stop;
790
- exports.toObserver = actors_dist_xstateActors.toObserver;
743
+ exports.isActorRef = actors_dist_xstateActors.isActorRef;
744
+ exports.toActorRef = actors_dist_xstateActors.toActorRef;
745
+ exports.Actor = interpreter.Actor;
746
+ exports.ActorStatus = interpreter.ActorStatus;
747
+ exports.InterpreterStatus = interpreter.InterpreterStatus;
748
+ exports.createActor = interpreter.createActor;
749
+ exports.interpret = interpreter.interpret;
750
+ exports.matchesState = interpreter.matchesState;
751
+ exports.pathToStateValue = interpreter.pathToStateValue;
752
+ exports.toObserver = interpreter.toObserver;
753
+ exports.State = guards_dist_xstateGuards.State;
754
+ exports.and = guards_dist_xstateGuards.and;
755
+ exports.cancel = guards_dist_xstateGuards.cancel;
756
+ exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
757
+ exports.not = guards_dist_xstateGuards.not;
758
+ exports.or = guards_dist_xstateGuards.or;
759
+ exports.raise = guards_dist_xstateGuards.raise;
760
+ exports.stateIn = guards_dist_xstateGuards.stateIn;
761
+ exports.stop = guards_dist_xstateGuards.stop;
762
+ exports.SpecialTargets = send.SpecialTargets;
763
+ exports.assign = send.assign;
764
+ exports.choose = send.choose;
765
+ exports.escalate = send.escalate;
766
+ exports.forwardTo = send.forwardTo;
767
+ exports.log = send.log;
768
+ exports.pure = send.pure;
769
+ exports.sendParent = send.sendParent;
770
+ exports.sendTo = send.sendTo;
791
771
  exports.SimulatedClock = SimulatedClock;
792
772
  exports.StateMachine = StateMachine;
793
773
  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.cjs.js";