xstate 5.0.0-beta.40 → 5.0.0-beta.42

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 (46) hide show
  1. package/actions/dist/xstate-actions.cjs.js +3 -3
  2. package/actions/dist/xstate-actions.development.cjs.js +3 -3
  3. package/actions/dist/xstate-actions.development.esm.js +3 -3
  4. package/actions/dist/xstate-actions.esm.js +3 -3
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/declarations/src/State.d.ts +36 -43
  14. package/dist/declarations/src/StateMachine.d.ts +13 -30
  15. package/dist/declarations/src/StateNode.d.ts +2 -2
  16. package/dist/declarations/src/index.d.ts +4 -5
  17. package/dist/declarations/src/interpreter.d.ts +14 -10
  18. package/dist/declarations/src/stateUtils.d.ts +7 -8
  19. package/dist/declarations/src/types.d.ts +114 -22
  20. package/dist/{interpreter-bae5c279.development.cjs.js → interpreter-23e4041c.development.cjs.js} +49 -42
  21. package/dist/{interpreter-ed0fac7e.esm.js → interpreter-3d0c0ff2.esm.js} +49 -40
  22. package/dist/{interpreter-586abde4.cjs.js → interpreter-b6bdd134.cjs.js} +49 -42
  23. package/dist/{interpreter-410d7ca9.development.esm.js → interpreter-f2620ea7.development.esm.js} +49 -40
  24. package/dist/{raise-37f9f3b8.development.esm.js → raise-51ae36e5.development.esm.js} +84 -183
  25. package/dist/{raise-27909189.cjs.js → raise-6b64c553.cjs.js} +81 -181
  26. package/dist/{raise-8325e2df.development.cjs.js → raise-8f482ce9.development.cjs.js} +85 -185
  27. package/dist/{raise-2b2fdec3.esm.js → raise-d2084327.esm.js} +80 -179
  28. package/dist/{send-59f66c58.esm.js → send-4e732fa5.esm.js} +7 -6
  29. package/dist/{send-f6b49072.development.esm.js → send-7a350091.development.esm.js} +7 -6
  30. package/dist/{send-4fdf275e.cjs.js → send-85b562d8.cjs.js} +7 -6
  31. package/dist/{send-c45d0d2c.development.cjs.js → send-cc8f864e.development.cjs.js} +7 -6
  32. package/dist/xstate.cjs.js +27 -56
  33. package/dist/xstate.cjs.mjs +0 -4
  34. package/dist/xstate.development.cjs.js +27 -56
  35. package/dist/xstate.development.cjs.mjs +0 -4
  36. package/dist/xstate.development.esm.js +31 -56
  37. package/dist/xstate.esm.js +31 -56
  38. package/dist/xstate.umd.min.js +1 -1
  39. package/dist/xstate.umd.min.js.map +1 -1
  40. package/guards/dist/xstate-guards.cjs.js +2 -2
  41. package/guards/dist/xstate-guards.development.cjs.js +2 -2
  42. package/guards/dist/xstate-guards.development.esm.js +2 -2
  43. package/guards/dist/xstate-guards.esm.js +2 -2
  44. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  45. package/package.json +1 -1
  46. package/dist/declarations/src/mapState.d.ts +0 -3
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
6
- var interpreter = require('./interpreter-586abde4.cjs.js');
7
- var guards_dist_xstateGuards = require('./raise-27909189.cjs.js');
8
- var send = require('./send-4fdf275e.cjs.js');
6
+ var interpreter = require('./interpreter-b6bdd134.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-6b64c553.cjs.js');
8
+ var send = require('./send-85b562d8.cjs.js');
9
9
  require('../dev/dist/xstate-dev.cjs.js');
10
10
 
11
11
  class SimulatedClock {
@@ -403,7 +403,6 @@ class StateMachine {
403
403
  this.getInitialState = this.getInitialState.bind(this);
404
404
  this.restoreState = this.restoreState.bind(this);
405
405
  this.start = this.start.bind(this);
406
- this.getPersistedState = this.getPersistedState.bind(this);
407
406
  this.root = new StateNode(config, {
408
407
  _key: this.id,
409
408
  _machine: this
@@ -448,27 +447,18 @@ class StateMachine {
448
447
  }
449
448
  });
450
449
  }
451
-
452
- /**
453
- * Resolves the given `state` to a new `State` instance relative to this machine.
454
- *
455
- * This ensures that `.nextEvents` represent the correct values.
456
- *
457
- * @param state The state to resolve
458
- */
459
- resolveState(state) {
460
- const configurationSet = guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, state.value));
461
- const configuration = Array.from(configurationSet);
462
- return this.createState({
463
- ...state,
464
- value: guards_dist_xstateGuards.resolveStateValue(this.root, state.value),
465
- configuration,
466
- status: guards_dist_xstateGuards.isInFinalState(configurationSet, this.root) ? 'done' : state.status
467
- });
468
- }
469
- resolveStateValue(stateValue, ...[context]) {
470
- const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, stateValue);
471
- return this.resolveState(guards_dist_xstateGuards.State.from(resolvedStateValue, context, this));
450
+ resolveState(config) {
451
+ const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
452
+ const configurationSet = guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
453
+ return guards_dist_xstateGuards.createMachineSnapshot({
454
+ configuration: [...configurationSet],
455
+ context: config.context || {},
456
+ children: {},
457
+ status: guards_dist_xstateGuards.isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
458
+ output: config.output,
459
+ error: config.error,
460
+ historyValue: config.historyValue
461
+ }, this);
472
462
  }
473
463
 
474
464
  /**
@@ -481,7 +471,7 @@ class StateMachine {
481
471
  transition(state, event, actorScope) {
482
472
  // TODO: handle error events in a better way
483
473
  if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
484
- return guards_dist_xstateGuards.cloneState(state, {
474
+ return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
485
475
  status: 'error',
486
476
  error: event.data
487
477
  });
@@ -514,15 +504,12 @@ class StateMachine {
514
504
  const {
515
505
  context
516
506
  } = this.config;
517
- const preInitial = this.resolveState(this.createState({
518
- value: {},
519
- // TODO: this is computed in state constructor
507
+ const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
520
508
  context: typeof context !== 'function' && context ? context : {},
521
- meta: undefined,
522
- configuration: guards_dist_xstateGuards.getInitialConfiguration(this.root),
509
+ configuration: [this.root],
523
510
  children: {},
524
511
  status: 'active'
525
- }));
512
+ }, this);
526
513
  if (typeof context === 'function') {
527
514
  const assignment = ({
528
515
  spawn,
@@ -579,11 +566,8 @@ class StateMachine {
579
566
  toJSON() {
580
567
  return this.definition;
581
568
  }
582
- getPersistedState(state) {
583
- return guards_dist_xstateGuards.getPersistedState(state);
584
- }
585
- createState(stateConfig) {
586
- return stateConfig instanceof guards_dist_xstateGuards.State ? stateConfig : new guards_dist_xstateGuards.State(stateConfig, this);
569
+ getPersistedState(state, options) {
570
+ return guards_dist_xstateGuards.getPersistedState(state, options);
587
571
  }
588
572
  restoreState(snapshot, _actorScope) {
589
573
  const children = {};
@@ -592,7 +576,7 @@ class StateMachine {
592
576
  const actorData = snapshotChildren[actorId];
593
577
  const childState = actorData.state;
594
578
  const src = actorData.src;
595
- const logic = src ? interpreter.resolveReferencedActor(this, src)?.src : undefined;
579
+ const logic = typeof src === 'string' ? interpreter.resolveReferencedActor(this, src)?.src : src;
596
580
  if (!logic) {
597
581
  return;
598
582
  }
@@ -606,10 +590,11 @@ class StateMachine {
606
590
  });
607
591
  children[actorId] = actorRef;
608
592
  });
609
- const restoredSnapshot = this.createState(new guards_dist_xstateGuards.State({
593
+ const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
610
594
  ...snapshot,
611
- children
612
- }, this));
595
+ children,
596
+ configuration: Array.from(guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
597
+ }, this);
613
598
  let seen = new Set();
614
599
  function reviveContext(contextPart, children) {
615
600
  if (seen.has(contextPart)) {
@@ -635,7 +620,7 @@ class StateMachine {
635
620
  }
636
621
 
637
622
  const defaultWaitForOptions = {
638
- timeout: 10_000 // 10 seconds
623
+ timeout: Infinity // much more than 10 seconds
639
624
  };
640
625
 
641
626
  /**
@@ -709,16 +694,6 @@ function createMachine(config, implementations) {
709
694
  return new StateMachine(config, implementations);
710
695
  }
711
696
 
712
- function mapState(stateMap, stateId) {
713
- let foundStateId;
714
- for (const mappedStateId of Object.keys(stateMap)) {
715
- if (interpreter.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
716
- foundStateId = mappedStateId;
717
- }
718
- }
719
- return stateMap[foundStateId];
720
- }
721
-
722
697
  exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
723
698
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
724
699
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
@@ -726,14 +701,11 @@ exports.fromObservable = actors_dist_xstateActors.fromObservable;
726
701
  exports.fromPromise = actors_dist_xstateActors.fromPromise;
727
702
  exports.fromTransition = actors_dist_xstateActors.fromTransition;
728
703
  exports.Actor = interpreter.Actor;
729
- exports.ActorStatus = interpreter.ActorStatus;
730
- exports.InterpreterStatus = interpreter.InterpreterStatus;
731
704
  exports.createActor = interpreter.createActor;
732
705
  exports.interpret = interpreter.interpret;
733
706
  exports.matchesState = interpreter.matchesState;
734
707
  exports.pathToStateValue = interpreter.pathToStateValue;
735
708
  exports.toObserver = interpreter.toObserver;
736
- exports.State = guards_dist_xstateGuards.State;
737
709
  exports.and = guards_dist_xstateGuards.and;
738
710
  exports.cancel = guards_dist_xstateGuards.cancel;
739
711
  exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
@@ -756,5 +728,4 @@ exports.SimulatedClock = SimulatedClock;
756
728
  exports.StateMachine = StateMachine;
757
729
  exports.StateNode = StateNode;
758
730
  exports.createMachine = createMachine;
759
- exports.mapState = mapState;
760
731
  exports.waitFor = waitFor;
@@ -1,10 +1,7 @@
1
1
  export {
2
2
  Actor,
3
- ActorStatus,
4
- InterpreterStatus,
5
3
  SimulatedClock,
6
4
  SpecialTargets,
7
- State,
8
5
  StateMachine,
9
6
  StateNode,
10
7
  and,
@@ -24,7 +21,6 @@ export {
24
21
  getStateNodes,
25
22
  interpret,
26
23
  log,
27
- mapState,
28
24
  matchesState,
29
25
  not,
30
26
  or,
@@ -3,9 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
6
- var interpreter = require('./interpreter-bae5c279.development.cjs.js');
7
- var guards_dist_xstateGuards = require('./raise-8325e2df.development.cjs.js');
8
- var send = require('./send-c45d0d2c.development.cjs.js');
6
+ var interpreter = require('./interpreter-23e4041c.development.cjs.js');
7
+ var guards_dist_xstateGuards = require('./raise-8f482ce9.development.cjs.js');
8
+ var send = require('./send-cc8f864e.development.cjs.js');
9
9
  require('../dev/dist/xstate-dev.development.cjs.js');
10
10
 
11
11
  class SimulatedClock {
@@ -403,7 +403,6 @@ class StateMachine {
403
403
  this.getInitialState = this.getInitialState.bind(this);
404
404
  this.restoreState = this.restoreState.bind(this);
405
405
  this.start = this.start.bind(this);
406
- this.getPersistedState = this.getPersistedState.bind(this);
407
406
  this.root = new StateNode(config, {
408
407
  _key: this.id,
409
408
  _machine: this
@@ -451,27 +450,18 @@ class StateMachine {
451
450
  }
452
451
  });
453
452
  }
454
-
455
- /**
456
- * Resolves the given `state` to a new `State` instance relative to this machine.
457
- *
458
- * This ensures that `.nextEvents` represent the correct values.
459
- *
460
- * @param state The state to resolve
461
- */
462
- resolveState(state) {
463
- const configurationSet = guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, state.value));
464
- const configuration = Array.from(configurationSet);
465
- return this.createState({
466
- ...state,
467
- value: guards_dist_xstateGuards.resolveStateValue(this.root, state.value),
468
- configuration,
469
- status: guards_dist_xstateGuards.isInFinalState(configurationSet, this.root) ? 'done' : state.status
470
- });
471
- }
472
- resolveStateValue(stateValue, ...[context]) {
473
- const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, stateValue);
474
- return this.resolveState(guards_dist_xstateGuards.State.from(resolvedStateValue, context, this));
453
+ resolveState(config) {
454
+ const resolvedStateValue = guards_dist_xstateGuards.resolveStateValue(this.root, config.value);
455
+ const configurationSet = guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, resolvedStateValue));
456
+ return guards_dist_xstateGuards.createMachineSnapshot({
457
+ configuration: [...configurationSet],
458
+ context: config.context || {},
459
+ children: {},
460
+ status: guards_dist_xstateGuards.isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
461
+ output: config.output,
462
+ error: config.error,
463
+ historyValue: config.historyValue
464
+ }, this);
475
465
  }
476
466
 
477
467
  /**
@@ -484,7 +474,7 @@ class StateMachine {
484
474
  transition(state, event, actorScope) {
485
475
  // TODO: handle error events in a better way
486
476
  if (interpreter.isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
487
- return guards_dist_xstateGuards.cloneState(state, {
477
+ return guards_dist_xstateGuards.cloneMachineSnapshot(state, {
488
478
  status: 'error',
489
479
  error: event.data
490
480
  });
@@ -517,15 +507,12 @@ class StateMachine {
517
507
  const {
518
508
  context
519
509
  } = this.config;
520
- const preInitial = this.resolveState(this.createState({
521
- value: {},
522
- // TODO: this is computed in state constructor
510
+ const preInitial = guards_dist_xstateGuards.createMachineSnapshot({
523
511
  context: typeof context !== 'function' && context ? context : {},
524
- meta: undefined,
525
- configuration: guards_dist_xstateGuards.getInitialConfiguration(this.root),
512
+ configuration: [this.root],
526
513
  children: {},
527
514
  status: 'active'
528
- }));
515
+ }, this);
529
516
  if (typeof context === 'function') {
530
517
  const assignment = ({
531
518
  spawn,
@@ -582,11 +569,8 @@ class StateMachine {
582
569
  toJSON() {
583
570
  return this.definition;
584
571
  }
585
- getPersistedState(state) {
586
- return guards_dist_xstateGuards.getPersistedState(state);
587
- }
588
- createState(stateConfig) {
589
- return stateConfig instanceof guards_dist_xstateGuards.State ? stateConfig : new guards_dist_xstateGuards.State(stateConfig, this);
572
+ getPersistedState(state, options) {
573
+ return guards_dist_xstateGuards.getPersistedState(state, options);
590
574
  }
591
575
  restoreState(snapshot, _actorScope) {
592
576
  const children = {};
@@ -595,7 +579,7 @@ class StateMachine {
595
579
  const actorData = snapshotChildren[actorId];
596
580
  const childState = actorData.state;
597
581
  const src = actorData.src;
598
- const logic = src ? interpreter.resolveReferencedActor(this, src)?.src : undefined;
582
+ const logic = typeof src === 'string' ? interpreter.resolveReferencedActor(this, src)?.src : src;
599
583
  if (!logic) {
600
584
  return;
601
585
  }
@@ -609,10 +593,11 @@ class StateMachine {
609
593
  });
610
594
  children[actorId] = actorRef;
611
595
  });
612
- const restoredSnapshot = this.createState(new guards_dist_xstateGuards.State({
596
+ const restoredSnapshot = guards_dist_xstateGuards.createMachineSnapshot({
613
597
  ...snapshot,
614
- children
615
- }, this));
598
+ children,
599
+ configuration: Array.from(guards_dist_xstateGuards.getConfiguration(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
600
+ }, this);
616
601
  let seen = new Set();
617
602
  function reviveContext(contextPart, children) {
618
603
  if (seen.has(contextPart)) {
@@ -638,7 +623,7 @@ class StateMachine {
638
623
  }
639
624
 
640
625
  const defaultWaitForOptions = {
641
- timeout: 10_000 // 10 seconds
626
+ timeout: Infinity // much more than 10 seconds
642
627
  };
643
628
 
644
629
  /**
@@ -715,16 +700,6 @@ function createMachine(config, implementations) {
715
700
  return new StateMachine(config, implementations);
716
701
  }
717
702
 
718
- function mapState(stateMap, stateId) {
719
- let foundStateId;
720
- for (const mappedStateId of Object.keys(stateMap)) {
721
- if (interpreter.matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
722
- foundStateId = mappedStateId;
723
- }
724
- }
725
- return stateMap[foundStateId];
726
- }
727
-
728
703
  exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
729
704
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
730
705
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
@@ -732,14 +707,11 @@ exports.fromObservable = actors_dist_xstateActors.fromObservable;
732
707
  exports.fromPromise = actors_dist_xstateActors.fromPromise;
733
708
  exports.fromTransition = actors_dist_xstateActors.fromTransition;
734
709
  exports.Actor = interpreter.Actor;
735
- exports.ActorStatus = interpreter.ActorStatus;
736
- exports.InterpreterStatus = interpreter.InterpreterStatus;
737
710
  exports.createActor = interpreter.createActor;
738
711
  exports.interpret = interpreter.interpret;
739
712
  exports.matchesState = interpreter.matchesState;
740
713
  exports.pathToStateValue = interpreter.pathToStateValue;
741
714
  exports.toObserver = interpreter.toObserver;
742
- exports.State = guards_dist_xstateGuards.State;
743
715
  exports.and = guards_dist_xstateGuards.and;
744
716
  exports.cancel = guards_dist_xstateGuards.cancel;
745
717
  exports.getStateNodes = guards_dist_xstateGuards.getStateNodes;
@@ -762,5 +734,4 @@ exports.SimulatedClock = SimulatedClock;
762
734
  exports.StateMachine = StateMachine;
763
735
  exports.StateNode = StateNode;
764
736
  exports.createMachine = createMachine;
765
- exports.mapState = mapState;
766
737
  exports.waitFor = waitFor;
@@ -1,10 +1,7 @@
1
1
  export {
2
2
  Actor,
3
- ActorStatus,
4
- InterpreterStatus,
5
3
  SimulatedClock,
6
4
  SpecialTargets,
7
- State,
8
5
  StateMachine,
9
6
  StateNode,
10
7
  and,
@@ -24,7 +21,6 @@ export {
24
21
  getStateNodes,
25
22
  interpret,
26
23
  log,
27
- mapState,
28
24
  matchesState,
29
25
  not,
30
26
  or,
@@ -1,10 +1,10 @@
1
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, $ as $$ACTOR_TYPE, e as matchesState } from './interpreter-410d7ca9.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-410d7ca9.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 getInitialStateNodes, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-37f9f3b8.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, C as spawn, y as stateIn, B as stop } from './raise-37f9f3b8.development.esm.js';
6
- import { a as assign } from './send-f6b49072.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-f6b49072.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, $ as $$ACTOR_TYPE } from './interpreter-f2620ea7.development.esm.js';
3
+ export { A as Actor, d as createActor, e as interpret, f as matchesState, p as pathToStateValue, g as toObserver } from './interpreter-f2620ea7.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, r as resolveStateValue, d as getConfiguration, h as getStateNodes, i as createMachineSnapshot, j as isInFinalState, k as cloneMachineSnapshot, l as macrostep, t as transitionNode, n as resolveActionsAndContext, o as microstep, p as getInitialStateNodes, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-51ae36e5.development.esm.js';
5
+ export { v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, C as spawn, y as stateIn, B as stop } from './raise-51ae36e5.development.esm.js';
6
+ import { a as assign } from './send-7a350091.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-7a350091.development.esm.js';
8
8
  import '../dev/dist/xstate-dev.development.esm.js';
9
9
 
10
10
  class SimulatedClock {
@@ -402,7 +402,6 @@ class StateMachine {
402
402
  this.getInitialState = this.getInitialState.bind(this);
403
403
  this.restoreState = this.restoreState.bind(this);
404
404
  this.start = this.start.bind(this);
405
- this.getPersistedState = this.getPersistedState.bind(this);
406
405
  this.root = new StateNode(config, {
407
406
  _key: this.id,
408
407
  _machine: this
@@ -450,27 +449,18 @@ class StateMachine {
450
449
  }
451
450
  });
452
451
  }
453
-
454
- /**
455
- * Resolves the given `state` to a new `State` instance relative to this machine.
456
- *
457
- * This ensures that `.nextEvents` represent the correct values.
458
- *
459
- * @param state The state to resolve
460
- */
461
- resolveState(state) {
462
- const configurationSet = getConfiguration(getStateNodes(this.root, state.value));
463
- const configuration = Array.from(configurationSet);
464
- return this.createState({
465
- ...state,
466
- value: resolveStateValue(this.root, state.value),
467
- configuration,
468
- status: isInFinalState(configurationSet, this.root) ? 'done' : state.status
469
- });
470
- }
471
- resolveStateValue(stateValue, ...[context]) {
472
- const resolvedStateValue = resolveStateValue(this.root, stateValue);
473
- return this.resolveState(State.from(resolvedStateValue, context, this));
452
+ resolveState(config) {
453
+ const resolvedStateValue = resolveStateValue(this.root, config.value);
454
+ const configurationSet = getConfiguration(getStateNodes(this.root, resolvedStateValue));
455
+ return createMachineSnapshot({
456
+ configuration: [...configurationSet],
457
+ context: config.context || {},
458
+ children: {},
459
+ status: isInFinalState(configurationSet, this.root) ? 'done' : config.status || 'active',
460
+ output: config.output,
461
+ error: config.error,
462
+ historyValue: config.historyValue
463
+ }, this);
474
464
  }
475
465
 
476
466
  /**
@@ -483,7 +473,7 @@ class StateMachine {
483
473
  transition(state, event, actorScope) {
484
474
  // TODO: handle error events in a better way
485
475
  if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
486
- return cloneState(state, {
476
+ return cloneMachineSnapshot(state, {
487
477
  status: 'error',
488
478
  error: event.data
489
479
  });
@@ -516,15 +506,12 @@ class StateMachine {
516
506
  const {
517
507
  context
518
508
  } = this.config;
519
- const preInitial = this.resolveState(this.createState({
520
- value: {},
521
- // TODO: this is computed in state constructor
509
+ const preInitial = createMachineSnapshot({
522
510
  context: typeof context !== 'function' && context ? context : {},
523
- meta: undefined,
524
- configuration: getInitialConfiguration(this.root),
511
+ configuration: [this.root],
525
512
  children: {},
526
513
  status: 'active'
527
- }));
514
+ }, this);
528
515
  if (typeof context === 'function') {
529
516
  const assignment = ({
530
517
  spawn,
@@ -581,11 +568,8 @@ class StateMachine {
581
568
  toJSON() {
582
569
  return this.definition;
583
570
  }
584
- getPersistedState(state) {
585
- return getPersistedState(state);
586
- }
587
- createState(stateConfig) {
588
- return stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
571
+ getPersistedState(state, options) {
572
+ return getPersistedState(state, options);
589
573
  }
590
574
  restoreState(snapshot, _actorScope) {
591
575
  const children = {};
@@ -594,7 +578,7 @@ class StateMachine {
594
578
  const actorData = snapshotChildren[actorId];
595
579
  const childState = actorData.state;
596
580
  const src = actorData.src;
597
- const logic = src ? resolveReferencedActor(this, src)?.src : undefined;
581
+ const logic = typeof src === 'string' ? resolveReferencedActor(this, src)?.src : src;
598
582
  if (!logic) {
599
583
  return;
600
584
  }
@@ -608,10 +592,11 @@ class StateMachine {
608
592
  });
609
593
  children[actorId] = actorRef;
610
594
  });
611
- const restoredSnapshot = this.createState(new State({
595
+ const restoredSnapshot = createMachineSnapshot({
612
596
  ...snapshot,
613
- children
614
- }, this));
597
+ children,
598
+ configuration: Array.from(getConfiguration(getStateNodes(this.root, snapshot.value)))
599
+ }, this);
615
600
  let seen = new Set();
616
601
  function reviveContext(contextPart, children) {
617
602
  if (seen.has(contextPart)) {
@@ -637,7 +622,7 @@ class StateMachine {
637
622
  }
638
623
 
639
624
  const defaultWaitForOptions = {
640
- timeout: 10_000 // 10 seconds
625
+ timeout: Infinity // much more than 10 seconds
641
626
  };
642
627
 
643
628
  /**
@@ -714,14 +699,4 @@ function createMachine(config, implementations) {
714
699
  return new StateMachine(config, implementations);
715
700
  }
716
701
 
717
- function mapState(stateMap, stateId) {
718
- let foundStateId;
719
- for (const mappedStateId of Object.keys(stateMap)) {
720
- if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
721
- foundStateId = mappedStateId;
722
- }
723
- }
724
- return stateMap[foundStateId];
725
- }
726
-
727
- export { SimulatedClock, StateMachine, StateNode, createMachine, mapState, waitFor };
702
+ export { SimulatedClock, StateMachine, StateNode, createMachine, waitFor };