xstate 5.0.0-beta.52 → 5.0.0-beta.54

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 +2 -3
  2. package/actions/dist/xstate-actions.cjs.mjs +0 -1
  3. package/actions/dist/xstate-actions.development.cjs.js +2 -3
  4. package/actions/dist/xstate-actions.development.cjs.mjs +0 -1
  5. package/actions/dist/xstate-actions.development.esm.js +2 -2
  6. package/actions/dist/xstate-actions.esm.js +2 -2
  7. package/actions/dist/xstate-actions.umd.min.js +1 -1
  8. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  9. package/actors/dist/xstate-actors.cjs.js +17 -17
  10. package/actors/dist/xstate-actors.development.cjs.js +17 -17
  11. package/actors/dist/xstate-actors.development.esm.js +17 -17
  12. package/actors/dist/xstate-actors.esm.js +17 -17
  13. package/actors/dist/xstate-actors.umd.min.js +1 -1
  14. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  15. package/dist/declarations/src/State.d.ts +2 -2
  16. package/dist/declarations/src/StateMachine.d.ts +4 -4
  17. package/dist/declarations/src/StateNode.d.ts +1 -1
  18. package/dist/declarations/src/actions/send.d.ts +1 -9
  19. package/dist/declarations/src/actions.d.ts +1 -1
  20. package/dist/declarations/src/actors/transition.d.ts +1 -1
  21. package/dist/declarations/src/guards.d.ts +1 -1
  22. package/dist/declarations/src/interpreter.d.ts +5 -5
  23. package/dist/declarations/src/stateUtils.d.ts +9 -9
  24. package/dist/declarations/src/types.d.ts +15 -11
  25. package/dist/{log-d160285c.development.cjs.js → log-516ee274.development.cjs.js} +23 -40
  26. package/dist/{log-3d815f5e.cjs.js → log-5b24d580.cjs.js} +23 -40
  27. package/dist/{log-826c9895.development.esm.js → log-5ebdc815.development.esm.js} +24 -40
  28. package/dist/{log-6bc0e1e7.esm.js → log-ee8cb6d6.esm.js} +24 -40
  29. package/dist/{raise-9dd3e757.development.cjs.js → raise-57f3c654.development.cjs.js} +130 -130
  30. package/dist/{raise-367eeb6f.cjs.js → raise-5f22d333.cjs.js} +130 -130
  31. package/dist/{raise-f71460d6.esm.js → raise-6f820d79.esm.js} +130 -130
  32. package/dist/{raise-1caefe80.development.esm.js → raise-a6c478f8.development.esm.js} +130 -130
  33. package/dist/xstate.cjs.js +17 -18
  34. package/dist/xstate.cjs.mjs +0 -1
  35. package/dist/xstate.development.cjs.js +17 -18
  36. package/dist/xstate.development.cjs.mjs +0 -1
  37. package/dist/xstate.development.esm.js +19 -19
  38. package/dist/xstate.esm.js +19 -19
  39. package/dist/xstate.umd.min.js +1 -1
  40. package/dist/xstate.umd.min.js.map +1 -1
  41. package/guards/dist/xstate-guards.cjs.js +1 -1
  42. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  43. package/guards/dist/xstate-guards.development.esm.js +1 -1
  44. package/guards/dist/xstate-guards.esm.js +1 -1
  45. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  46. package/package.json +1 -1
@@ -100,10 +100,10 @@ function createDoneActorEvent(invokeId, output) {
100
100
  output
101
101
  };
102
102
  }
103
- function createErrorActorEvent(id, data) {
103
+ function createErrorActorEvent(id, error) {
104
104
  return {
105
105
  type: `xstate.error.actor.${id}`,
106
- data
106
+ error
107
107
  };
108
108
  }
109
109
  function createInitEvent(input) {
@@ -354,7 +354,7 @@ class Actor {
354
354
  /**
355
355
  * The current internal state of the actor.
356
356
  */
357
- this._state = void 0;
357
+ this._snapshot = void 0;
358
358
  /**
359
359
  * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
360
360
  */
@@ -444,19 +444,19 @@ class Actor {
444
444
  this._systemId = systemId;
445
445
  this.system._set(systemId, this);
446
446
  }
447
- this._initState(options?.state);
448
- if (systemId && this._state.status !== 'active') {
447
+ this._initState(options?.snapshot ?? options?.state);
448
+ if (systemId && this._snapshot.status !== 'active') {
449
449
  this.system._unregister(this);
450
450
  }
451
451
  }
452
452
  _initState(persistedState) {
453
453
  try {
454
- this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
454
+ this._snapshot = persistedState ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
455
455
  } catch (err) {
456
- // if we get here then it means that we assign a value to this._state that is not of the correct type
456
+ // if we get here then it means that we assign a value to this._snapshot that is not of the correct type
457
457
  // we can't get the true `TSnapshot & { status: 'error'; }`, it's impossible
458
458
  // so right now this is a lie of sorts
459
- this._state = {
459
+ this._snapshot = {
460
460
  status: 'error',
461
461
  output: undefined,
462
462
  error: err
@@ -465,7 +465,7 @@ class Actor {
465
465
  }
466
466
  update(snapshot, event) {
467
467
  // Update state
468
- this._state = snapshot;
468
+ this._snapshot = snapshot;
469
469
 
470
470
  // Execute deferred effects
471
471
  let deferredFn;
@@ -479,14 +479,14 @@ class Actor {
479
479
  // no "builtin deferred" should actually throw an error since they are either safe
480
480
  // or the control flow is passed through the mailbox and errors should be caught by the `_process` used by the mailbox
481
481
  this._deferred.length = 0;
482
- this._state = {
482
+ this._snapshot = {
483
483
  ...snapshot,
484
484
  status: 'error',
485
485
  error: err
486
486
  };
487
487
  }
488
488
  }
489
- switch (this._state.status) {
489
+ switch (this._snapshot.status) {
490
490
  case 'active':
491
491
  for (const observer of this.observers) {
492
492
  try {
@@ -512,13 +512,13 @@ class Actor {
512
512
  }
513
513
  this._stopProcedure();
514
514
  this._complete();
515
- this._doneEvent = createDoneActorEvent(this.id, this._state.output);
515
+ this._doneEvent = createDoneActorEvent(this.id, this._snapshot.output);
516
516
  if (this._parent) {
517
517
  this.system._relay(this, this._parent, this._doneEvent);
518
518
  }
519
519
  break;
520
520
  case 'error':
521
- this._error(this._state.error);
521
+ this._error(this._snapshot.error);
522
522
  break;
523
523
  }
524
524
  this.system._sendInspectionEvent({
@@ -631,24 +631,24 @@ class Actor {
631
631
  actorRef: this,
632
632
  event: initEvent
633
633
  });
634
- const status = this._state.status;
634
+ const status = this._snapshot.status;
635
635
  switch (status) {
636
636
  case 'done':
637
637
  // a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
638
638
  // we still need to complete observers, flush deferreds etc
639
- this.update(this._state, initEvent);
639
+ this.update(this._snapshot, initEvent);
640
640
  // TODO: rethink cleanup of observers, mailbox, etc
641
641
  return this;
642
642
  case 'error':
643
- this._error(this._state.error);
643
+ this._error(this._snapshot.error);
644
644
  return this;
645
645
  }
646
646
  if (this.logic.start) {
647
647
  try {
648
- this.logic.start(this._state, this._actorScope);
648
+ this.logic.start(this._snapshot, this._actorScope);
649
649
  } catch (err) {
650
- this._state = {
651
- ...this._state,
650
+ this._snapshot = {
651
+ ...this._snapshot,
652
652
  status: 'error',
653
653
  error: err
654
654
  };
@@ -660,7 +660,7 @@ class Actor {
660
660
  // TODO: this notifies all subscribers but usually this is redundant
661
661
  // there is no real change happening here
662
662
  // we need to rethink if this needs to be refactored
663
- this.update(this._state, initEvent);
663
+ this.update(this._snapshot, initEvent);
664
664
  if (this.options.devTools) {
665
665
  this.attachDevTools();
666
666
  }
@@ -671,7 +671,7 @@ class Actor {
671
671
  let nextState;
672
672
  let caughtError;
673
673
  try {
674
- nextState = this.logic.transition(this._state, event, this._actorScope);
674
+ nextState = this.logic.transition(this._snapshot, event, this._actorScope);
675
675
  } catch (err) {
676
676
  // we wrap it in a box so we can rethrow it later even if falsy value gets caught here
677
677
  caughtError = {
@@ -682,8 +682,8 @@ class Actor {
682
682
  const {
683
683
  err
684
684
  } = caughtError;
685
- this._state = {
686
- ...this._state,
685
+ this._snapshot = {
686
+ ...this._snapshot,
687
687
  status: 'error',
688
688
  error: err
689
689
  };
@@ -871,8 +871,8 @@ class Actor {
871
871
  * @see https://stately.ai/docs/persistence
872
872
  */
873
873
 
874
- getPersistedState(options) {
875
- return this.logic.getPersistedState(this._state, options);
874
+ getPersistedSnapshot(options) {
875
+ return this.logic.getPersistedSnapshot(this._snapshot, options);
876
876
  }
877
877
  [symbolObservable]() {
878
878
  return this;
@@ -890,10 +890,10 @@ class Actor {
890
890
  * Note that some actors, such as callback actors generated with `fromCallback`, will not emit snapshots.
891
891
  *
892
892
  * @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
893
- * @see {@link Actor.getPersistedState} to persist the internal state of an actor (which is more than just a snapshot).
893
+ * @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
894
894
  */
895
895
  getSnapshot() {
896
- return this._state;
896
+ return this._snapshot;
897
897
  }
898
898
  }
899
899
 
@@ -946,11 +946,11 @@ const interpret = createActor;
946
946
  * @deprecated Use `Actor` instead.
947
947
  */
948
948
 
949
- function resolveCancel(_, state, actionArgs, actionParams, {
949
+ function resolveCancel(_, snapshot, actionArgs, actionParams, {
950
950
  sendId
951
951
  }) {
952
952
  const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
953
- return [state, resolvedSendId];
953
+ return [snapshot, resolvedSendId];
954
954
  }
955
955
  function executeCancel(actorScope, resolvedSendId) {
956
956
  actorScope.self.cancel(resolvedSendId);
@@ -975,14 +975,14 @@ function cancel(sendId) {
975
975
  return cancel;
976
976
  }
977
977
 
978
- function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
978
+ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
979
979
  id,
980
980
  systemId,
981
981
  src,
982
982
  input,
983
983
  syncSnapshot
984
984
  }) {
985
- const logic = typeof src === 'string' ? resolveReferencedActor(state.machine, src) : src;
985
+ const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
986
986
  const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
987
987
  let actorRef;
988
988
  if (logic) {
@@ -993,7 +993,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
993
993
  syncSnapshot,
994
994
  systemId,
995
995
  input: typeof input === 'function' ? input({
996
- context: state.context,
996
+ context: snapshot.context,
997
997
  event: actionArgs.event,
998
998
  self: actorScope?.self
999
999
  }) : input
@@ -1002,9 +1002,9 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
1002
1002
  if (!actorRef) {
1003
1003
  console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
1004
1004
  }
1005
- return [cloneMachineSnapshot(state, {
1005
+ return [cloneMachineSnapshot(snapshot, {
1006
1006
  children: {
1007
- ...state.children,
1007
+ ...snapshot.children,
1008
1008
  [resolvedId]: actorRef
1009
1009
  }
1010
1010
  }), {
@@ -1037,7 +1037,7 @@ function spawnChild(...[src, {
1037
1037
  throw new Error(`This isn't supposed to be called`);
1038
1038
  }
1039
1039
  }
1040
- spawnChild.type = 'xstate.spawnChild';
1040
+ spawnChild.type = 'snapshot.spawnChild';
1041
1041
  spawnChild.id = id;
1042
1042
  spawnChild.systemId = systemId;
1043
1043
  spawnChild.src = src;
@@ -1048,19 +1048,19 @@ function spawnChild(...[src, {
1048
1048
  return spawnChild;
1049
1049
  }
1050
1050
 
1051
- function resolveStop(_, state, args, actionParams, {
1051
+ function resolveStop(_, snapshot, args, actionParams, {
1052
1052
  actorRef
1053
1053
  }) {
1054
1054
  const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
1055
- const resolvedActorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
1056
- let children = state.children;
1055
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
1056
+ let children = snapshot.children;
1057
1057
  if (resolvedActorRef) {
1058
1058
  children = {
1059
1059
  ...children
1060
1060
  };
1061
1061
  delete children[resolvedActorRef.id];
1062
1062
  }
1063
- return [cloneMachineSnapshot(state, {
1063
+ return [cloneMachineSnapshot(snapshot, {
1064
1064
  children
1065
1065
  }), resolvedActorRef];
1066
1066
  }
@@ -1113,14 +1113,14 @@ function stopChild(actorRef) {
1113
1113
  */
1114
1114
  const stop = stopChild;
1115
1115
 
1116
- function checkStateIn(state, _, {
1116
+ function checkStateIn(snapshot, _, {
1117
1117
  stateValue
1118
1118
  }) {
1119
1119
  if (typeof stateValue === 'string' && isStateId(stateValue)) {
1120
- const target = state.machine.getStateNodeById(stateValue);
1121
- return state._nodes.some(sn => sn === target);
1120
+ const target = snapshot.machine.getStateNodeById(stateValue);
1121
+ return snapshot._nodes.some(sn => sn === target);
1122
1122
  }
1123
- return state.matches(stateValue);
1123
+ return snapshot.matches(stateValue);
1124
1124
  }
1125
1125
  function stateIn(stateValue) {
1126
1126
  function stateIn(args, params) {
@@ -1132,13 +1132,13 @@ function stateIn(stateValue) {
1132
1132
  stateIn.stateValue = stateValue;
1133
1133
  return stateIn;
1134
1134
  }
1135
- function checkNot(state, {
1135
+ function checkNot(snapshot, {
1136
1136
  context,
1137
1137
  event
1138
1138
  }, {
1139
1139
  guards
1140
1140
  }) {
1141
- return !evaluateGuard(guards[0], context, event, state);
1141
+ return !evaluateGuard(guards[0], context, event, snapshot);
1142
1142
  }
1143
1143
  function not(guard) {
1144
1144
  function not(args, params) {
@@ -1150,13 +1150,13 @@ function not(guard) {
1150
1150
  not.guards = [guard];
1151
1151
  return not;
1152
1152
  }
1153
- function checkAnd(state, {
1153
+ function checkAnd(snapshot, {
1154
1154
  context,
1155
1155
  event
1156
1156
  }, {
1157
1157
  guards
1158
1158
  }) {
1159
- return guards.every(guard => evaluateGuard(guard, context, event, state));
1159
+ return guards.every(guard => evaluateGuard(guard, context, event, snapshot));
1160
1160
  }
1161
1161
  function and(guards) {
1162
1162
  function and(args, params) {
@@ -1168,13 +1168,13 @@ function and(guards) {
1168
1168
  and.guards = guards;
1169
1169
  return and;
1170
1170
  }
1171
- function checkOr(state, {
1171
+ function checkOr(snapshot, {
1172
1172
  context,
1173
1173
  event
1174
1174
  }, {
1175
1175
  guards
1176
1176
  }) {
1177
- return guards.some(guard => evaluateGuard(guard, context, event, state));
1177
+ return guards.some(guard => evaluateGuard(guard, context, event, snapshot));
1178
1178
  }
1179
1179
  function or(guards) {
1180
1180
  function or(args, params) {
@@ -1188,17 +1188,17 @@ function or(guards) {
1188
1188
  }
1189
1189
 
1190
1190
  // TODO: throw on cycles (depth check should be enough)
1191
- function evaluateGuard(guard, context, event, state) {
1191
+ function evaluateGuard(guard, context, event, snapshot) {
1192
1192
  const {
1193
1193
  machine
1194
- } = state;
1194
+ } = snapshot;
1195
1195
  const isInline = typeof guard === 'function';
1196
1196
  const resolved = isInline ? guard : machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
1197
1197
  if (!isInline && !resolved) {
1198
1198
  throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
1199
1199
  }
1200
1200
  if (typeof resolved !== 'function') {
1201
- return evaluateGuard(resolved, context, event, state);
1201
+ return evaluateGuard(resolved, context, event, snapshot);
1202
1202
  }
1203
1203
  const guardArgs = {
1204
1204
  context,
@@ -1215,7 +1215,7 @@ function evaluateGuard(guard, context, event, state) {
1215
1215
  return resolved(guardArgs, guardParams);
1216
1216
  }
1217
1217
  const builtinGuard = resolved;
1218
- return builtinGuard.check(state, guardArgs, resolved // this holds all params
1218
+ return builtinGuard.check(snapshot, guardArgs, resolved // this holds all params
1219
1219
  );
1220
1220
  }
1221
1221
 
@@ -1615,24 +1615,24 @@ function getStateNodes(stateNode, stateValue) {
1615
1615
  return allSubStateNodes.concat(subStateNodes);
1616
1616
  }, []));
1617
1617
  }
1618
- function transitionAtomicNode(stateNode, stateValue, state, event) {
1618
+ function transitionAtomicNode(stateNode, stateValue, snapshot, event) {
1619
1619
  const childStateNode = getStateNode(stateNode, stateValue);
1620
- const next = childStateNode.next(state, event);
1620
+ const next = childStateNode.next(snapshot, event);
1621
1621
  if (!next || !next.length) {
1622
- return stateNode.next(state, event);
1622
+ return stateNode.next(snapshot, event);
1623
1623
  }
1624
1624
  return next;
1625
1625
  }
1626
- function transitionCompoundNode(stateNode, stateValue, state, event) {
1626
+ function transitionCompoundNode(stateNode, stateValue, snapshot, event) {
1627
1627
  const subStateKeys = Object.keys(stateValue);
1628
1628
  const childStateNode = getStateNode(stateNode, subStateKeys[0]);
1629
- const next = transitionNode(childStateNode, stateValue[subStateKeys[0]], state, event);
1629
+ const next = transitionNode(childStateNode, stateValue[subStateKeys[0]], snapshot, event);
1630
1630
  if (!next || !next.length) {
1631
- return stateNode.next(state, event);
1631
+ return stateNode.next(snapshot, event);
1632
1632
  }
1633
1633
  return next;
1634
1634
  }
1635
- function transitionParallelNode(stateNode, stateValue, state, event) {
1635
+ function transitionParallelNode(stateNode, stateValue, snapshot, event) {
1636
1636
  const allInnerTransitions = [];
1637
1637
  for (const subStateKey of Object.keys(stateValue)) {
1638
1638
  const subStateValue = stateValue[subStateKey];
@@ -1640,29 +1640,29 @@ function transitionParallelNode(stateNode, stateValue, state, event) {
1640
1640
  continue;
1641
1641
  }
1642
1642
  const subStateNode = getStateNode(stateNode, subStateKey);
1643
- const innerTransitions = transitionNode(subStateNode, subStateValue, state, event);
1643
+ const innerTransitions = transitionNode(subStateNode, subStateValue, snapshot, event);
1644
1644
  if (innerTransitions) {
1645
1645
  allInnerTransitions.push(...innerTransitions);
1646
1646
  }
1647
1647
  }
1648
1648
  if (!allInnerTransitions.length) {
1649
- return stateNode.next(state, event);
1649
+ return stateNode.next(snapshot, event);
1650
1650
  }
1651
1651
  return allInnerTransitions;
1652
1652
  }
1653
- function transitionNode(stateNode, stateValue, state, event) {
1653
+ function transitionNode(stateNode, stateValue, snapshot, event) {
1654
1654
  // leaf node
1655
1655
  if (typeof stateValue === 'string') {
1656
- return transitionAtomicNode(stateNode, stateValue, state, event);
1656
+ return transitionAtomicNode(stateNode, stateValue, snapshot, event);
1657
1657
  }
1658
1658
 
1659
1659
  // compound node
1660
1660
  if (Object.keys(stateValue).length === 1) {
1661
- return transitionCompoundNode(stateNode, stateValue, state, event);
1661
+ return transitionCompoundNode(stateNode, stateValue, snapshot, event);
1662
1662
  }
1663
1663
 
1664
1664
  // parallel node
1665
- return transitionParallelNode(stateNode, stateValue, state, event);
1665
+ return transitionParallelNode(stateNode, stateValue, snapshot, event);
1666
1666
  }
1667
1667
  function getHistoryNodes(stateNode) {
1668
1668
  return Object.keys(stateNode.states).map(key => stateNode.states[key]).filter(sn => sn.type === 'history');
@@ -1794,14 +1794,14 @@ function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
1794
1794
  /**
1795
1795
  * https://www.w3.org/TR/scxml/#microstepProcedure
1796
1796
  */
1797
- function microstep(transitions, currentState, actorScope, event, isInitial, internalQueue) {
1797
+ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, internalQueue) {
1798
1798
  if (!transitions.length) {
1799
- return currentState;
1799
+ return currentSnapshot;
1800
1800
  }
1801
- const mutStateNodeSet = new Set(currentState._nodes);
1802
- let historyValue = currentState.historyValue;
1801
+ const mutStateNodeSet = new Set(currentSnapshot._nodes);
1802
+ let historyValue = currentSnapshot.historyValue;
1803
1803
  const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
1804
- let nextState = currentState;
1804
+ let nextState = currentSnapshot;
1805
1805
 
1806
1806
  // Exit states
1807
1807
  if (!isInitial) {
@@ -1818,7 +1818,7 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
1818
1818
  nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
1819
1819
  }
1820
1820
  try {
1821
- if (historyValue === currentState.historyValue && areStateNodeCollectionsEqual(currentState._nodes, mutStateNodeSet)) {
1821
+ if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
1822
1822
  return nextState;
1823
1823
  }
1824
1824
  return cloneMachineSnapshot(nextState, {
@@ -1831,15 +1831,15 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
1831
1831
  throw e;
1832
1832
  }
1833
1833
  }
1834
- function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode) {
1834
+ function getMachineOutput(snapshot, event, actorScope, rootNode, rootCompletionNode) {
1835
1835
  if (!rootNode.output) {
1836
1836
  return;
1837
1837
  }
1838
- const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
1839
- return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
1838
+ const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, snapshot.context, event, actorScope.self) : undefined);
1839
+ return resolveOutput(rootNode.output, snapshot.context, doneStateEvent, actorScope.self);
1840
1840
  }
1841
- function enterStates(currentState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
1842
- let nextState = currentState;
1841
+ function enterStates(currentSnapshot, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
1842
+ let nextSnapshot = currentSnapshot;
1843
1843
  const statesToEnter = new Set();
1844
1844
  // those are states that were directly targeted or indirectly targeted by the explicit target
1845
1845
  // in other words, those are states for which initial actions should be executed
@@ -1849,7 +1849,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1849
1849
 
1850
1850
  // In the initial state, the root state node is "entered".
1851
1851
  if (isInitial) {
1852
- statesForDefaultEntry.add(currentState.machine.root);
1852
+ statesForDefaultEntry.add(currentSnapshot.machine.root);
1853
1853
  }
1854
1854
  const completedNodes = new Set();
1855
1855
  for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
@@ -1868,13 +1868,13 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1868
1868
  const initialActions = stateNodeToEnter.initial.actions;
1869
1869
  actions.push(...initialActions);
1870
1870
  }
1871
- nextState = resolveActionsAndContext(nextState, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
1871
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
1872
1872
  if (stateNodeToEnter.type === 'final') {
1873
1873
  const parent = stateNodeToEnter.parent;
1874
1874
  let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
1875
1875
  let rootCompletionNode = ancestorMarker || stateNodeToEnter;
1876
1876
  if (parent?.type === 'compound') {
1877
- internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
1877
+ internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextSnapshot.context, event, actorScope.self) : undefined));
1878
1878
  }
1879
1879
  while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
1880
1880
  completedNodes.add(ancestorMarker);
@@ -1885,13 +1885,13 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1885
1885
  if (ancestorMarker) {
1886
1886
  continue;
1887
1887
  }
1888
- nextState = cloneMachineSnapshot(nextState, {
1888
+ nextSnapshot = cloneMachineSnapshot(nextSnapshot, {
1889
1889
  status: 'done',
1890
- output: getMachineOutput(nextState, event, actorScope, nextState.machine.root, rootCompletionNode)
1890
+ output: getMachineOutput(nextSnapshot, event, actorScope, nextSnapshot.machine.root, rootCompletionNode)
1891
1891
  });
1892
1892
  }
1893
1893
  }
1894
- return nextState;
1894
+ return nextSnapshot;
1895
1895
  }
1896
1896
  function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
1897
1897
  for (const t of transitions) {
@@ -1986,8 +1986,8 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
1986
1986
  function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1987
1987
  addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
1988
1988
  }
1989
- function exitStates(currentState, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
1990
- let nextState = currentState;
1989
+ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
1990
+ let nextSnapshot = currentSnapshot;
1991
1991
  const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
1992
1992
  statesToExit.sort((a, b) => b.order - a.order);
1993
1993
  let changedHistory;
@@ -2010,16 +2010,16 @@ function exitStates(currentState, event, actorScope, transitions, mutStateNodeSe
2010
2010
  }
2011
2011
  }
2012
2012
  for (const s of statesToExit) {
2013
- nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
2013
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
2014
2014
  mutStateNodeSet.delete(s);
2015
2015
  }
2016
- return [nextState, changedHistory || historyValue];
2016
+ return [nextSnapshot, changedHistory || historyValue];
2017
2017
  }
2018
- function resolveActionsAndContextWorker(currentState, event, actorScope, actions, extra, retries) {
2018
+ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, extra, retries) {
2019
2019
  const {
2020
2020
  machine
2021
- } = currentState;
2022
- let intermediateState = currentState;
2021
+ } = currentSnapshot;
2022
+ let intermediateSnapshot = currentSnapshot;
2023
2023
  for (const action of actions) {
2024
2024
  const isInline = typeof action === 'function';
2025
2025
  const resolvedAction = isInline ? action :
@@ -2031,13 +2031,13 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
2031
2031
  continue;
2032
2032
  }
2033
2033
  const actionArgs = {
2034
- context: intermediateState.context,
2034
+ context: intermediateSnapshot.context,
2035
2035
  event,
2036
2036
  self: actorScope?.self,
2037
2037
  system: actorScope?.system
2038
2038
  };
2039
2039
  const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
2040
- context: intermediateState.context,
2040
+ context: intermediateSnapshot.context,
2041
2041
  event
2042
2042
  }) : action.params : undefined;
2043
2043
  if (!('resolve' in resolvedAction)) {
@@ -2051,10 +2051,10 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
2051
2051
  continue;
2052
2052
  }
2053
2053
  const builtinAction = resolvedAction;
2054
- const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateState, actionArgs, actionParams, resolvedAction,
2054
+ const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateSnapshot, actionArgs, actionParams, resolvedAction,
2055
2055
  // this holds all params
2056
2056
  extra);
2057
- intermediateState = nextState;
2057
+ intermediateSnapshot = nextState;
2058
2058
  if ('retryResolve' in builtinAction) {
2059
2059
  retries?.push([builtinAction, params]);
2060
2060
  }
@@ -2066,14 +2066,14 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
2066
2066
  }
2067
2067
  }
2068
2068
  if (actions) {
2069
- intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorScope, actions, extra, retries);
2069
+ intermediateSnapshot = resolveActionsAndContextWorker(intermediateSnapshot, event, actorScope, actions, extra, retries);
2070
2070
  }
2071
2071
  }
2072
- return intermediateState;
2072
+ return intermediateSnapshot;
2073
2073
  }
2074
- function resolveActionsAndContext(currentState, event, actorScope, actions, internalQueue, deferredActorIds) {
2074
+ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, internalQueue, deferredActorIds) {
2075
2075
  const retries = deferredActorIds ? [] : undefined;
2076
- const nextState = resolveActionsAndContextWorker(currentState, event, actorScope, actions, {
2076
+ const nextState = resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, {
2077
2077
  internalQueue,
2078
2078
  deferredActorIds
2079
2079
  }, retries);
@@ -2082,21 +2082,21 @@ function resolveActionsAndContext(currentState, event, actorScope, actions, inte
2082
2082
  });
2083
2083
  return nextState;
2084
2084
  }
2085
- function macrostep(state, event, actorScope, internalQueue = []) {
2085
+ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2086
2086
  if (event.type === WILDCARD) {
2087
2087
  throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
2088
2088
  }
2089
- let nextState = state;
2089
+ let nextSnapshot = snapshot;
2090
2090
  const states = [];
2091
2091
 
2092
2092
  // Handle stop event
2093
2093
  if (event.type === XSTATE_STOP) {
2094
- nextState = cloneMachineSnapshot(stopChildren(nextState, event, actorScope), {
2094
+ nextSnapshot = cloneMachineSnapshot(stopChildren(nextSnapshot, event, actorScope), {
2095
2095
  status: 'stopped'
2096
2096
  });
2097
- states.push(nextState);
2097
+ states.push(nextSnapshot);
2098
2098
  return {
2099
- state: nextState,
2099
+ snapshot: nextSnapshot,
2100
2100
  microstates: states
2101
2101
  };
2102
2102
  }
@@ -2107,47 +2107,47 @@ function macrostep(state, event, actorScope, internalQueue = []) {
2107
2107
  if (nextEvent.type !== XSTATE_INIT) {
2108
2108
  const currentEvent = nextEvent;
2109
2109
  const isErr = isErrorActorEvent(currentEvent);
2110
- const transitions = selectTransitions(currentEvent, nextState);
2110
+ const transitions = selectTransitions(currentEvent, nextSnapshot);
2111
2111
  if (isErr && !transitions.length) {
2112
2112
  // TODO: we should likely only allow transitions selected by very explicit descriptors
2113
2113
  // `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
2114
2114
  // similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
2115
- nextState = cloneMachineSnapshot(state, {
2115
+ nextSnapshot = cloneMachineSnapshot(snapshot, {
2116
2116
  status: 'error',
2117
- error: currentEvent.data
2117
+ error: currentEvent.error
2118
2118
  });
2119
- states.push(nextState);
2119
+ states.push(nextSnapshot);
2120
2120
  return {
2121
- state: nextState,
2121
+ snapshot: nextSnapshot,
2122
2122
  microstates: states
2123
2123
  };
2124
2124
  }
2125
- nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
2126
- states.push(nextState);
2125
+ nextSnapshot = microstep(transitions, snapshot, actorScope, nextEvent, false, internalQueue);
2126
+ states.push(nextSnapshot);
2127
2127
  }
2128
2128
  let shouldSelectEventlessTransitions = true;
2129
- while (nextState.status === 'active') {
2130
- let enabledTransitions = shouldSelectEventlessTransitions ? selectEventlessTransitions(nextState, nextEvent) : [];
2129
+ while (nextSnapshot.status === 'active') {
2130
+ let enabledTransitions = shouldSelectEventlessTransitions ? selectEventlessTransitions(nextSnapshot, nextEvent) : [];
2131
2131
 
2132
2132
  // eventless transitions should always be selected after selecting *regular* transitions
2133
2133
  // by assigning `undefined` to `previousState` we ensure that `shouldSelectEventlessTransitions` gets always computed to true in such a case
2134
- const previousState = enabledTransitions.length ? nextState : undefined;
2134
+ const previousState = enabledTransitions.length ? nextSnapshot : undefined;
2135
2135
  if (!enabledTransitions.length) {
2136
2136
  if (!internalQueue.length) {
2137
2137
  break;
2138
2138
  }
2139
2139
  nextEvent = internalQueue.shift();
2140
- enabledTransitions = selectTransitions(nextEvent, nextState);
2140
+ enabledTransitions = selectTransitions(nextEvent, nextSnapshot);
2141
2141
  }
2142
- nextState = microstep(enabledTransitions, nextState, actorScope, nextEvent, false, internalQueue);
2143
- shouldSelectEventlessTransitions = nextState !== previousState;
2144
- states.push(nextState);
2142
+ nextSnapshot = microstep(enabledTransitions, nextSnapshot, actorScope, nextEvent, false, internalQueue);
2143
+ shouldSelectEventlessTransitions = nextSnapshot !== previousState;
2144
+ states.push(nextSnapshot);
2145
2145
  }
2146
- if (nextState.status !== 'active') {
2147
- stopChildren(nextState, nextEvent, actorScope);
2146
+ if (nextSnapshot.status !== 'active') {
2147
+ stopChildren(nextSnapshot, nextEvent, actorScope);
2148
2148
  }
2149
2149
  return {
2150
- state: nextState,
2150
+ snapshot: nextSnapshot,
2151
2151
  microstates: states
2152
2152
  };
2153
2153
  }
@@ -2248,13 +2248,13 @@ function createMachineSnapshot(config, machine) {
2248
2248
  toJSON: machineSnapshotToJSON
2249
2249
  };
2250
2250
  }
2251
- function cloneMachineSnapshot(state, config = {}) {
2251
+ function cloneMachineSnapshot(snapshot, config = {}) {
2252
2252
  return createMachineSnapshot({
2253
- ...state,
2253
+ ...snapshot,
2254
2254
  ...config
2255
- }, state.machine);
2255
+ }, snapshot.machine);
2256
2256
  }
2257
- function getPersistedState(state, options) {
2257
+ function getPersistedSnapshot(snapshot, options) {
2258
2258
  const {
2259
2259
  _nodes: nodes,
2260
2260
  tags,
@@ -2267,7 +2267,7 @@ function getPersistedState(state, options) {
2267
2267
  getMeta,
2268
2268
  toJSON,
2269
2269
  ...jsonValues
2270
- } = state;
2270
+ } = snapshot;
2271
2271
  const childrenJson = {};
2272
2272
  for (const id in children) {
2273
2273
  const child = children[id];
@@ -2275,7 +2275,7 @@ function getPersistedState(state, options) {
2275
2275
  throw new Error('An inline child actor cannot be persisted.');
2276
2276
  }
2277
2277
  childrenJson[id] = {
2278
- state: child.getPersistedState(options),
2278
+ snapshot: child.getPersistedSnapshot(options),
2279
2279
  src: child.src,
2280
2280
  systemId: child._systemId,
2281
2281
  syncSnapshot: child._syncSnapshot
@@ -2315,14 +2315,14 @@ function persistContext(contextPart) {
2315
2315
  return copy ?? contextPart;
2316
2316
  }
2317
2317
 
2318
- function resolveRaise(_, state, args, actionParams, {
2318
+ function resolveRaise(_, snapshot, args, actionParams, {
2319
2319
  event: eventOrExpr,
2320
2320
  id,
2321
2321
  delay
2322
2322
  }, {
2323
2323
  internalQueue
2324
2324
  }) {
2325
- const delaysMap = state.machine.implementations.delays;
2325
+ const delaysMap = snapshot.machine.implementations.delays;
2326
2326
  if (typeof eventOrExpr === 'string') {
2327
2327
  throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2328
2328
  }
@@ -2337,7 +2337,7 @@ function resolveRaise(_, state, args, actionParams, {
2337
2337
  if (typeof resolvedDelay !== 'number') {
2338
2338
  internalQueue.push(resolvedEvent);
2339
2339
  }
2340
- return [state, {
2340
+ return [snapshot, {
2341
2341
  event: resolvedEvent,
2342
2342
  id,
2343
2343
  delay: resolvedDelay
@@ -2394,7 +2394,7 @@ exports.getAllStateNodes = getAllStateNodes;
2394
2394
  exports.getCandidates = getCandidates;
2395
2395
  exports.getDelayedTransitions = getDelayedTransitions;
2396
2396
  exports.getInitialStateNodes = getInitialStateNodes;
2397
- exports.getPersistedState = getPersistedState;
2397
+ exports.getPersistedSnapshot = getPersistedSnapshot;
2398
2398
  exports.getStateNodeByPath = getStateNodeByPath;
2399
2399
  exports.getStateNodes = getStateNodes;
2400
2400
  exports.interpret = interpret;