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
@@ -98,10 +98,10 @@ function createDoneActorEvent(invokeId, output) {
98
98
  output
99
99
  };
100
100
  }
101
- function createErrorActorEvent(id, data) {
101
+ function createErrorActorEvent(id, error) {
102
102
  return {
103
103
  type: `xstate.error.actor.${id}`,
104
- data
104
+ error
105
105
  };
106
106
  }
107
107
  function createInitEvent(input) {
@@ -349,7 +349,7 @@ class Actor {
349
349
  /**
350
350
  * The current internal state of the actor.
351
351
  */
352
- this._state = void 0;
352
+ this._snapshot = void 0;
353
353
  /**
354
354
  * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
355
355
  */
@@ -439,19 +439,19 @@ class Actor {
439
439
  this._systemId = systemId;
440
440
  this.system._set(systemId, this);
441
441
  }
442
- this._initState(options?.state);
443
- if (systemId && this._state.status !== 'active') {
442
+ this._initState(options?.snapshot ?? options?.state);
443
+ if (systemId && this._snapshot.status !== 'active') {
444
444
  this.system._unregister(this);
445
445
  }
446
446
  }
447
447
  _initState(persistedState) {
448
448
  try {
449
- this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
449
+ this._snapshot = persistedState ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
450
450
  } catch (err) {
451
- // if we get here then it means that we assign a value to this._state that is not of the correct type
451
+ // if we get here then it means that we assign a value to this._snapshot that is not of the correct type
452
452
  // we can't get the true `TSnapshot & { status: 'error'; }`, it's impossible
453
453
  // so right now this is a lie of sorts
454
- this._state = {
454
+ this._snapshot = {
455
455
  status: 'error',
456
456
  output: undefined,
457
457
  error: err
@@ -460,7 +460,7 @@ class Actor {
460
460
  }
461
461
  update(snapshot, event) {
462
462
  // Update state
463
- this._state = snapshot;
463
+ this._snapshot = snapshot;
464
464
 
465
465
  // Execute deferred effects
466
466
  let deferredFn;
@@ -474,14 +474,14 @@ class Actor {
474
474
  // no "builtin deferred" should actually throw an error since they are either safe
475
475
  // or the control flow is passed through the mailbox and errors should be caught by the `_process` used by the mailbox
476
476
  this._deferred.length = 0;
477
- this._state = {
477
+ this._snapshot = {
478
478
  ...snapshot,
479
479
  status: 'error',
480
480
  error: err
481
481
  };
482
482
  }
483
483
  }
484
- switch (this._state.status) {
484
+ switch (this._snapshot.status) {
485
485
  case 'active':
486
486
  for (const observer of this.observers) {
487
487
  try {
@@ -507,13 +507,13 @@ class Actor {
507
507
  }
508
508
  this._stopProcedure();
509
509
  this._complete();
510
- this._doneEvent = createDoneActorEvent(this.id, this._state.output);
510
+ this._doneEvent = createDoneActorEvent(this.id, this._snapshot.output);
511
511
  if (this._parent) {
512
512
  this.system._relay(this, this._parent, this._doneEvent);
513
513
  }
514
514
  break;
515
515
  case 'error':
516
- this._error(this._state.error);
516
+ this._error(this._snapshot.error);
517
517
  break;
518
518
  }
519
519
  this.system._sendInspectionEvent({
@@ -626,24 +626,24 @@ class Actor {
626
626
  actorRef: this,
627
627
  event: initEvent
628
628
  });
629
- const status = this._state.status;
629
+ const status = this._snapshot.status;
630
630
  switch (status) {
631
631
  case 'done':
632
632
  // a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
633
633
  // we still need to complete observers, flush deferreds etc
634
- this.update(this._state, initEvent);
634
+ this.update(this._snapshot, initEvent);
635
635
  // TODO: rethink cleanup of observers, mailbox, etc
636
636
  return this;
637
637
  case 'error':
638
- this._error(this._state.error);
638
+ this._error(this._snapshot.error);
639
639
  return this;
640
640
  }
641
641
  if (this.logic.start) {
642
642
  try {
643
- this.logic.start(this._state, this._actorScope);
643
+ this.logic.start(this._snapshot, this._actorScope);
644
644
  } catch (err) {
645
- this._state = {
646
- ...this._state,
645
+ this._snapshot = {
646
+ ...this._snapshot,
647
647
  status: 'error',
648
648
  error: err
649
649
  };
@@ -655,7 +655,7 @@ class Actor {
655
655
  // TODO: this notifies all subscribers but usually this is redundant
656
656
  // there is no real change happening here
657
657
  // we need to rethink if this needs to be refactored
658
- this.update(this._state, initEvent);
658
+ this.update(this._snapshot, initEvent);
659
659
  if (this.options.devTools) {
660
660
  this.attachDevTools();
661
661
  }
@@ -666,7 +666,7 @@ class Actor {
666
666
  let nextState;
667
667
  let caughtError;
668
668
  try {
669
- nextState = this.logic.transition(this._state, event, this._actorScope);
669
+ nextState = this.logic.transition(this._snapshot, event, this._actorScope);
670
670
  } catch (err) {
671
671
  // we wrap it in a box so we can rethrow it later even if falsy value gets caught here
672
672
  caughtError = {
@@ -677,8 +677,8 @@ class Actor {
677
677
  const {
678
678
  err
679
679
  } = caughtError;
680
- this._state = {
681
- ...this._state,
680
+ this._snapshot = {
681
+ ...this._snapshot,
682
682
  status: 'error',
683
683
  error: err
684
684
  };
@@ -858,8 +858,8 @@ class Actor {
858
858
  * @see https://stately.ai/docs/persistence
859
859
  */
860
860
 
861
- getPersistedState(options) {
862
- return this.logic.getPersistedState(this._state, options);
861
+ getPersistedSnapshot(options) {
862
+ return this.logic.getPersistedSnapshot(this._snapshot, options);
863
863
  }
864
864
  [symbolObservable]() {
865
865
  return this;
@@ -877,10 +877,10 @@ class Actor {
877
877
  * Note that some actors, such as callback actors generated with `fromCallback`, will not emit snapshots.
878
878
  *
879
879
  * @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
880
- * @see {@link Actor.getPersistedState} to persist the internal state of an actor (which is more than just a snapshot).
880
+ * @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
881
881
  */
882
882
  getSnapshot() {
883
- return this._state;
883
+ return this._snapshot;
884
884
  }
885
885
  }
886
886
 
@@ -933,11 +933,11 @@ const interpret = createActor;
933
933
  * @deprecated Use `Actor` instead.
934
934
  */
935
935
 
936
- function resolveCancel(_, state, actionArgs, actionParams, {
936
+ function resolveCancel(_, snapshot, actionArgs, actionParams, {
937
937
  sendId
938
938
  }) {
939
939
  const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
940
- return [state, resolvedSendId];
940
+ return [snapshot, resolvedSendId];
941
941
  }
942
942
  function executeCancel(actorScope, resolvedSendId) {
943
943
  actorScope.self.cancel(resolvedSendId);
@@ -959,14 +959,14 @@ function cancel(sendId) {
959
959
  return cancel;
960
960
  }
961
961
 
962
- function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
962
+ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
963
963
  id,
964
964
  systemId,
965
965
  src,
966
966
  input,
967
967
  syncSnapshot
968
968
  }) {
969
- const logic = typeof src === 'string' ? resolveReferencedActor(state.machine, src) : src;
969
+ const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
970
970
  const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
971
971
  let actorRef;
972
972
  if (logic) {
@@ -977,15 +977,15 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
977
977
  syncSnapshot,
978
978
  systemId,
979
979
  input: typeof input === 'function' ? input({
980
- context: state.context,
980
+ context: snapshot.context,
981
981
  event: actionArgs.event,
982
982
  self: actorScope?.self
983
983
  }) : input
984
984
  });
985
985
  }
986
- return [cloneMachineSnapshot(state, {
986
+ return [cloneMachineSnapshot(snapshot, {
987
987
  children: {
988
- ...state.children,
988
+ ...snapshot.children,
989
989
  [resolvedId]: actorRef
990
990
  }
991
991
  }), {
@@ -1015,7 +1015,7 @@ function spawnChild(...[src, {
1015
1015
  } = {}]) {
1016
1016
  function spawnChild(args, params) {
1017
1017
  }
1018
- spawnChild.type = 'xstate.spawnChild';
1018
+ spawnChild.type = 'snapshot.spawnChild';
1019
1019
  spawnChild.id = id;
1020
1020
  spawnChild.systemId = systemId;
1021
1021
  spawnChild.src = src;
@@ -1026,19 +1026,19 @@ function spawnChild(...[src, {
1026
1026
  return spawnChild;
1027
1027
  }
1028
1028
 
1029
- function resolveStop(_, state, args, actionParams, {
1029
+ function resolveStop(_, snapshot, args, actionParams, {
1030
1030
  actorRef
1031
1031
  }) {
1032
1032
  const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
1033
- const resolvedActorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
1034
- let children = state.children;
1033
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
1034
+ let children = snapshot.children;
1035
1035
  if (resolvedActorRef) {
1036
1036
  children = {
1037
1037
  ...children
1038
1038
  };
1039
1039
  delete children[resolvedActorRef.id];
1040
1040
  }
1041
- return [cloneMachineSnapshot(state, {
1041
+ return [cloneMachineSnapshot(snapshot, {
1042
1042
  children
1043
1043
  }), resolvedActorRef];
1044
1044
  }
@@ -1088,14 +1088,14 @@ function stopChild(actorRef) {
1088
1088
  */
1089
1089
  const stop = stopChild;
1090
1090
 
1091
- function checkStateIn(state, _, {
1091
+ function checkStateIn(snapshot, _, {
1092
1092
  stateValue
1093
1093
  }) {
1094
1094
  if (typeof stateValue === 'string' && isStateId(stateValue)) {
1095
- const target = state.machine.getStateNodeById(stateValue);
1096
- return state._nodes.some(sn => sn === target);
1095
+ const target = snapshot.machine.getStateNodeById(stateValue);
1096
+ return snapshot._nodes.some(sn => sn === target);
1097
1097
  }
1098
- return state.matches(stateValue);
1098
+ return snapshot.matches(stateValue);
1099
1099
  }
1100
1100
  function stateIn(stateValue) {
1101
1101
  function stateIn(args, params) {
@@ -1105,13 +1105,13 @@ function stateIn(stateValue) {
1105
1105
  stateIn.stateValue = stateValue;
1106
1106
  return stateIn;
1107
1107
  }
1108
- function checkNot(state, {
1108
+ function checkNot(snapshot, {
1109
1109
  context,
1110
1110
  event
1111
1111
  }, {
1112
1112
  guards
1113
1113
  }) {
1114
- return !evaluateGuard(guards[0], context, event, state);
1114
+ return !evaluateGuard(guards[0], context, event, snapshot);
1115
1115
  }
1116
1116
  function not(guard) {
1117
1117
  function not(args, params) {
@@ -1121,13 +1121,13 @@ function not(guard) {
1121
1121
  not.guards = [guard];
1122
1122
  return not;
1123
1123
  }
1124
- function checkAnd(state, {
1124
+ function checkAnd(snapshot, {
1125
1125
  context,
1126
1126
  event
1127
1127
  }, {
1128
1128
  guards
1129
1129
  }) {
1130
- return guards.every(guard => evaluateGuard(guard, context, event, state));
1130
+ return guards.every(guard => evaluateGuard(guard, context, event, snapshot));
1131
1131
  }
1132
1132
  function and(guards) {
1133
1133
  function and(args, params) {
@@ -1137,13 +1137,13 @@ function and(guards) {
1137
1137
  and.guards = guards;
1138
1138
  return and;
1139
1139
  }
1140
- function checkOr(state, {
1140
+ function checkOr(snapshot, {
1141
1141
  context,
1142
1142
  event
1143
1143
  }, {
1144
1144
  guards
1145
1145
  }) {
1146
- return guards.some(guard => evaluateGuard(guard, context, event, state));
1146
+ return guards.some(guard => evaluateGuard(guard, context, event, snapshot));
1147
1147
  }
1148
1148
  function or(guards) {
1149
1149
  function or(args, params) {
@@ -1155,17 +1155,17 @@ function or(guards) {
1155
1155
  }
1156
1156
 
1157
1157
  // TODO: throw on cycles (depth check should be enough)
1158
- function evaluateGuard(guard, context, event, state) {
1158
+ function evaluateGuard(guard, context, event, snapshot) {
1159
1159
  const {
1160
1160
  machine
1161
- } = state;
1161
+ } = snapshot;
1162
1162
  const isInline = typeof guard === 'function';
1163
1163
  const resolved = isInline ? guard : machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
1164
1164
  if (!isInline && !resolved) {
1165
1165
  throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
1166
1166
  }
1167
1167
  if (typeof resolved !== 'function') {
1168
- return evaluateGuard(resolved, context, event, state);
1168
+ return evaluateGuard(resolved, context, event, snapshot);
1169
1169
  }
1170
1170
  const guardArgs = {
1171
1171
  context,
@@ -1182,7 +1182,7 @@ function evaluateGuard(guard, context, event, state) {
1182
1182
  return resolved(guardArgs, guardParams);
1183
1183
  }
1184
1184
  const builtinGuard = resolved;
1185
- return builtinGuard.check(state, guardArgs, resolved // this holds all params
1185
+ return builtinGuard.check(snapshot, guardArgs, resolved // this holds all params
1186
1186
  );
1187
1187
  }
1188
1188
 
@@ -1571,24 +1571,24 @@ function getStateNodes(stateNode, stateValue) {
1571
1571
  return allSubStateNodes.concat(subStateNodes);
1572
1572
  }, []));
1573
1573
  }
1574
- function transitionAtomicNode(stateNode, stateValue, state, event) {
1574
+ function transitionAtomicNode(stateNode, stateValue, snapshot, event) {
1575
1575
  const childStateNode = getStateNode(stateNode, stateValue);
1576
- const next = childStateNode.next(state, event);
1576
+ const next = childStateNode.next(snapshot, event);
1577
1577
  if (!next || !next.length) {
1578
- return stateNode.next(state, event);
1578
+ return stateNode.next(snapshot, event);
1579
1579
  }
1580
1580
  return next;
1581
1581
  }
1582
- function transitionCompoundNode(stateNode, stateValue, state, event) {
1582
+ function transitionCompoundNode(stateNode, stateValue, snapshot, event) {
1583
1583
  const subStateKeys = Object.keys(stateValue);
1584
1584
  const childStateNode = getStateNode(stateNode, subStateKeys[0]);
1585
- const next = transitionNode(childStateNode, stateValue[subStateKeys[0]], state, event);
1585
+ const next = transitionNode(childStateNode, stateValue[subStateKeys[0]], snapshot, event);
1586
1586
  if (!next || !next.length) {
1587
- return stateNode.next(state, event);
1587
+ return stateNode.next(snapshot, event);
1588
1588
  }
1589
1589
  return next;
1590
1590
  }
1591
- function transitionParallelNode(stateNode, stateValue, state, event) {
1591
+ function transitionParallelNode(stateNode, stateValue, snapshot, event) {
1592
1592
  const allInnerTransitions = [];
1593
1593
  for (const subStateKey of Object.keys(stateValue)) {
1594
1594
  const subStateValue = stateValue[subStateKey];
@@ -1596,29 +1596,29 @@ function transitionParallelNode(stateNode, stateValue, state, event) {
1596
1596
  continue;
1597
1597
  }
1598
1598
  const subStateNode = getStateNode(stateNode, subStateKey);
1599
- const innerTransitions = transitionNode(subStateNode, subStateValue, state, event);
1599
+ const innerTransitions = transitionNode(subStateNode, subStateValue, snapshot, event);
1600
1600
  if (innerTransitions) {
1601
1601
  allInnerTransitions.push(...innerTransitions);
1602
1602
  }
1603
1603
  }
1604
1604
  if (!allInnerTransitions.length) {
1605
- return stateNode.next(state, event);
1605
+ return stateNode.next(snapshot, event);
1606
1606
  }
1607
1607
  return allInnerTransitions;
1608
1608
  }
1609
- function transitionNode(stateNode, stateValue, state, event) {
1609
+ function transitionNode(stateNode, stateValue, snapshot, event) {
1610
1610
  // leaf node
1611
1611
  if (typeof stateValue === 'string') {
1612
- return transitionAtomicNode(stateNode, stateValue, state, event);
1612
+ return transitionAtomicNode(stateNode, stateValue, snapshot, event);
1613
1613
  }
1614
1614
 
1615
1615
  // compound node
1616
1616
  if (Object.keys(stateValue).length === 1) {
1617
- return transitionCompoundNode(stateNode, stateValue, state, event);
1617
+ return transitionCompoundNode(stateNode, stateValue, snapshot, event);
1618
1618
  }
1619
1619
 
1620
1620
  // parallel node
1621
- return transitionParallelNode(stateNode, stateValue, state, event);
1621
+ return transitionParallelNode(stateNode, stateValue, snapshot, event);
1622
1622
  }
1623
1623
  function getHistoryNodes(stateNode) {
1624
1624
  return Object.keys(stateNode.states).map(key => stateNode.states[key]).filter(sn => sn.type === 'history');
@@ -1750,14 +1750,14 @@ function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
1750
1750
  /**
1751
1751
  * https://www.w3.org/TR/scxml/#microstepProcedure
1752
1752
  */
1753
- function microstep(transitions, currentState, actorScope, event, isInitial, internalQueue) {
1753
+ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, internalQueue) {
1754
1754
  if (!transitions.length) {
1755
- return currentState;
1755
+ return currentSnapshot;
1756
1756
  }
1757
- const mutStateNodeSet = new Set(currentState._nodes);
1758
- let historyValue = currentState.historyValue;
1757
+ const mutStateNodeSet = new Set(currentSnapshot._nodes);
1758
+ let historyValue = currentSnapshot.historyValue;
1759
1759
  const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
1760
- let nextState = currentState;
1760
+ let nextState = currentSnapshot;
1761
1761
 
1762
1762
  // Exit states
1763
1763
  if (!isInitial) {
@@ -1774,7 +1774,7 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
1774
1774
  nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
1775
1775
  }
1776
1776
  try {
1777
- if (historyValue === currentState.historyValue && areStateNodeCollectionsEqual(currentState._nodes, mutStateNodeSet)) {
1777
+ if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
1778
1778
  return nextState;
1779
1779
  }
1780
1780
  return cloneMachineSnapshot(nextState, {
@@ -1787,15 +1787,15 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
1787
1787
  throw e;
1788
1788
  }
1789
1789
  }
1790
- function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode) {
1790
+ function getMachineOutput(snapshot, event, actorScope, rootNode, rootCompletionNode) {
1791
1791
  if (!rootNode.output) {
1792
1792
  return;
1793
1793
  }
1794
- const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
1795
- return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
1794
+ const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, snapshot.context, event, actorScope.self) : undefined);
1795
+ return resolveOutput(rootNode.output, snapshot.context, doneStateEvent, actorScope.self);
1796
1796
  }
1797
- function enterStates(currentState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
1798
- let nextState = currentState;
1797
+ function enterStates(currentSnapshot, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
1798
+ let nextSnapshot = currentSnapshot;
1799
1799
  const statesToEnter = new Set();
1800
1800
  // those are states that were directly targeted or indirectly targeted by the explicit target
1801
1801
  // in other words, those are states for which initial actions should be executed
@@ -1805,7 +1805,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1805
1805
 
1806
1806
  // In the initial state, the root state node is "entered".
1807
1807
  if (isInitial) {
1808
- statesForDefaultEntry.add(currentState.machine.root);
1808
+ statesForDefaultEntry.add(currentSnapshot.machine.root);
1809
1809
  }
1810
1810
  const completedNodes = new Set();
1811
1811
  for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
@@ -1824,13 +1824,13 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1824
1824
  const initialActions = stateNodeToEnter.initial.actions;
1825
1825
  actions.push(...initialActions);
1826
1826
  }
1827
- nextState = resolveActionsAndContext(nextState, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
1827
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
1828
1828
  if (stateNodeToEnter.type === 'final') {
1829
1829
  const parent = stateNodeToEnter.parent;
1830
1830
  let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
1831
1831
  let rootCompletionNode = ancestorMarker || stateNodeToEnter;
1832
1832
  if (parent?.type === 'compound') {
1833
- internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
1833
+ internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextSnapshot.context, event, actorScope.self) : undefined));
1834
1834
  }
1835
1835
  while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
1836
1836
  completedNodes.add(ancestorMarker);
@@ -1841,13 +1841,13 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1841
1841
  if (ancestorMarker) {
1842
1842
  continue;
1843
1843
  }
1844
- nextState = cloneMachineSnapshot(nextState, {
1844
+ nextSnapshot = cloneMachineSnapshot(nextSnapshot, {
1845
1845
  status: 'done',
1846
- output: getMachineOutput(nextState, event, actorScope, nextState.machine.root, rootCompletionNode)
1846
+ output: getMachineOutput(nextSnapshot, event, actorScope, nextSnapshot.machine.root, rootCompletionNode)
1847
1847
  });
1848
1848
  }
1849
1849
  }
1850
- return nextState;
1850
+ return nextSnapshot;
1851
1851
  }
1852
1852
  function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
1853
1853
  for (const t of transitions) {
@@ -1942,8 +1942,8 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
1942
1942
  function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1943
1943
  addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
1944
1944
  }
1945
- function exitStates(currentState, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
1946
- let nextState = currentState;
1945
+ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
1946
+ let nextSnapshot = currentSnapshot;
1947
1947
  const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
1948
1948
  statesToExit.sort((a, b) => b.order - a.order);
1949
1949
  let changedHistory;
@@ -1966,16 +1966,16 @@ function exitStates(currentState, event, actorScope, transitions, mutStateNodeSe
1966
1966
  }
1967
1967
  }
1968
1968
  for (const s of statesToExit) {
1969
- nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
1969
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
1970
1970
  mutStateNodeSet.delete(s);
1971
1971
  }
1972
- return [nextState, changedHistory || historyValue];
1972
+ return [nextSnapshot, changedHistory || historyValue];
1973
1973
  }
1974
- function resolveActionsAndContextWorker(currentState, event, actorScope, actions, extra, retries) {
1974
+ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, extra, retries) {
1975
1975
  const {
1976
1976
  machine
1977
- } = currentState;
1978
- let intermediateState = currentState;
1977
+ } = currentSnapshot;
1978
+ let intermediateSnapshot = currentSnapshot;
1979
1979
  for (const action of actions) {
1980
1980
  const isInline = typeof action === 'function';
1981
1981
  const resolvedAction = isInline ? action :
@@ -1987,13 +1987,13 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
1987
1987
  continue;
1988
1988
  }
1989
1989
  const actionArgs = {
1990
- context: intermediateState.context,
1990
+ context: intermediateSnapshot.context,
1991
1991
  event,
1992
1992
  self: actorScope?.self,
1993
1993
  system: actorScope?.system
1994
1994
  };
1995
1995
  const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
1996
- context: intermediateState.context,
1996
+ context: intermediateSnapshot.context,
1997
1997
  event
1998
1998
  }) : action.params : undefined;
1999
1999
  if (!('resolve' in resolvedAction)) {
@@ -2007,10 +2007,10 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
2007
2007
  continue;
2008
2008
  }
2009
2009
  const builtinAction = resolvedAction;
2010
- const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateState, actionArgs, actionParams, resolvedAction,
2010
+ const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateSnapshot, actionArgs, actionParams, resolvedAction,
2011
2011
  // this holds all params
2012
2012
  extra);
2013
- intermediateState = nextState;
2013
+ intermediateSnapshot = nextState;
2014
2014
  if ('retryResolve' in builtinAction) {
2015
2015
  retries?.push([builtinAction, params]);
2016
2016
  }
@@ -2022,14 +2022,14 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
2022
2022
  }
2023
2023
  }
2024
2024
  if (actions) {
2025
- intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorScope, actions, extra, retries);
2025
+ intermediateSnapshot = resolveActionsAndContextWorker(intermediateSnapshot, event, actorScope, actions, extra, retries);
2026
2026
  }
2027
2027
  }
2028
- return intermediateState;
2028
+ return intermediateSnapshot;
2029
2029
  }
2030
- function resolveActionsAndContext(currentState, event, actorScope, actions, internalQueue, deferredActorIds) {
2030
+ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, internalQueue, deferredActorIds) {
2031
2031
  const retries = deferredActorIds ? [] : undefined;
2032
- const nextState = resolveActionsAndContextWorker(currentState, event, actorScope, actions, {
2032
+ const nextState = resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, {
2033
2033
  internalQueue,
2034
2034
  deferredActorIds
2035
2035
  }, retries);
@@ -2038,18 +2038,18 @@ function resolveActionsAndContext(currentState, event, actorScope, actions, inte
2038
2038
  });
2039
2039
  return nextState;
2040
2040
  }
2041
- function macrostep(state, event, actorScope, internalQueue = []) {
2042
- let nextState = state;
2041
+ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2042
+ let nextSnapshot = snapshot;
2043
2043
  const states = [];
2044
2044
 
2045
2045
  // Handle stop event
2046
2046
  if (event.type === XSTATE_STOP) {
2047
- nextState = cloneMachineSnapshot(stopChildren(nextState, event, actorScope), {
2047
+ nextSnapshot = cloneMachineSnapshot(stopChildren(nextSnapshot, event, actorScope), {
2048
2048
  status: 'stopped'
2049
2049
  });
2050
- states.push(nextState);
2050
+ states.push(nextSnapshot);
2051
2051
  return {
2052
- state: nextState,
2052
+ snapshot: nextSnapshot,
2053
2053
  microstates: states
2054
2054
  };
2055
2055
  }
@@ -2060,47 +2060,47 @@ function macrostep(state, event, actorScope, internalQueue = []) {
2060
2060
  if (nextEvent.type !== XSTATE_INIT) {
2061
2061
  const currentEvent = nextEvent;
2062
2062
  const isErr = isErrorActorEvent(currentEvent);
2063
- const transitions = selectTransitions(currentEvent, nextState);
2063
+ const transitions = selectTransitions(currentEvent, nextSnapshot);
2064
2064
  if (isErr && !transitions.length) {
2065
2065
  // TODO: we should likely only allow transitions selected by very explicit descriptors
2066
2066
  // `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
2067
2067
  // similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
2068
- nextState = cloneMachineSnapshot(state, {
2068
+ nextSnapshot = cloneMachineSnapshot(snapshot, {
2069
2069
  status: 'error',
2070
- error: currentEvent.data
2070
+ error: currentEvent.error
2071
2071
  });
2072
- states.push(nextState);
2072
+ states.push(nextSnapshot);
2073
2073
  return {
2074
- state: nextState,
2074
+ snapshot: nextSnapshot,
2075
2075
  microstates: states
2076
2076
  };
2077
2077
  }
2078
- nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
2079
- states.push(nextState);
2078
+ nextSnapshot = microstep(transitions, snapshot, actorScope, nextEvent, false, internalQueue);
2079
+ states.push(nextSnapshot);
2080
2080
  }
2081
2081
  let shouldSelectEventlessTransitions = true;
2082
- while (nextState.status === 'active') {
2083
- let enabledTransitions = shouldSelectEventlessTransitions ? selectEventlessTransitions(nextState, nextEvent) : [];
2082
+ while (nextSnapshot.status === 'active') {
2083
+ let enabledTransitions = shouldSelectEventlessTransitions ? selectEventlessTransitions(nextSnapshot, nextEvent) : [];
2084
2084
 
2085
2085
  // eventless transitions should always be selected after selecting *regular* transitions
2086
2086
  // by assigning `undefined` to `previousState` we ensure that `shouldSelectEventlessTransitions` gets always computed to true in such a case
2087
- const previousState = enabledTransitions.length ? nextState : undefined;
2087
+ const previousState = enabledTransitions.length ? nextSnapshot : undefined;
2088
2088
  if (!enabledTransitions.length) {
2089
2089
  if (!internalQueue.length) {
2090
2090
  break;
2091
2091
  }
2092
2092
  nextEvent = internalQueue.shift();
2093
- enabledTransitions = selectTransitions(nextEvent, nextState);
2093
+ enabledTransitions = selectTransitions(nextEvent, nextSnapshot);
2094
2094
  }
2095
- nextState = microstep(enabledTransitions, nextState, actorScope, nextEvent, false, internalQueue);
2096
- shouldSelectEventlessTransitions = nextState !== previousState;
2097
- states.push(nextState);
2095
+ nextSnapshot = microstep(enabledTransitions, nextSnapshot, actorScope, nextEvent, false, internalQueue);
2096
+ shouldSelectEventlessTransitions = nextSnapshot !== previousState;
2097
+ states.push(nextSnapshot);
2098
2098
  }
2099
- if (nextState.status !== 'active') {
2100
- stopChildren(nextState, nextEvent, actorScope);
2099
+ if (nextSnapshot.status !== 'active') {
2100
+ stopChildren(nextSnapshot, nextEvent, actorScope);
2101
2101
  }
2102
2102
  return {
2103
- state: nextState,
2103
+ snapshot: nextSnapshot,
2104
2104
  microstates: states
2105
2105
  };
2106
2106
  }
@@ -2198,13 +2198,13 @@ function createMachineSnapshot(config, machine) {
2198
2198
  toJSON: machineSnapshotToJSON
2199
2199
  };
2200
2200
  }
2201
- function cloneMachineSnapshot(state, config = {}) {
2201
+ function cloneMachineSnapshot(snapshot, config = {}) {
2202
2202
  return createMachineSnapshot({
2203
- ...state,
2203
+ ...snapshot,
2204
2204
  ...config
2205
- }, state.machine);
2205
+ }, snapshot.machine);
2206
2206
  }
2207
- function getPersistedState(state, options) {
2207
+ function getPersistedSnapshot(snapshot, options) {
2208
2208
  const {
2209
2209
  _nodes: nodes,
2210
2210
  tags,
@@ -2217,12 +2217,12 @@ function getPersistedState(state, options) {
2217
2217
  getMeta,
2218
2218
  toJSON,
2219
2219
  ...jsonValues
2220
- } = state;
2220
+ } = snapshot;
2221
2221
  const childrenJson = {};
2222
2222
  for (const id in children) {
2223
2223
  const child = children[id];
2224
2224
  childrenJson[id] = {
2225
- state: child.getPersistedState(options),
2225
+ snapshot: child.getPersistedSnapshot(options),
2226
2226
  src: child.src,
2227
2227
  systemId: child._systemId,
2228
2228
  syncSnapshot: child._syncSnapshot
@@ -2262,14 +2262,14 @@ function persistContext(contextPart) {
2262
2262
  return copy ?? contextPart;
2263
2263
  }
2264
2264
 
2265
- function resolveRaise(_, state, args, actionParams, {
2265
+ function resolveRaise(_, snapshot, args, actionParams, {
2266
2266
  event: eventOrExpr,
2267
2267
  id,
2268
2268
  delay
2269
2269
  }, {
2270
2270
  internalQueue
2271
2271
  }) {
2272
- const delaysMap = state.machine.implementations.delays;
2272
+ const delaysMap = snapshot.machine.implementations.delays;
2273
2273
  if (typeof eventOrExpr === 'string') {
2274
2274
  throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2275
2275
  }
@@ -2284,7 +2284,7 @@ function resolveRaise(_, state, args, actionParams, {
2284
2284
  if (typeof resolvedDelay !== 'number') {
2285
2285
  internalQueue.push(resolvedEvent);
2286
2286
  }
2287
- return [state, {
2287
+ return [snapshot, {
2288
2288
  event: resolvedEvent,
2289
2289
  id,
2290
2290
  delay: resolvedDelay
@@ -2314,4 +2314,4 @@ function raise(eventOrExpr, options) {
2314
2314
  return raise;
2315
2315
  }
2316
2316
 
2317
- export { $$ACTOR_TYPE as $, Actor as A, interpret as B, isMachineSnapshot as C, matchesState as D, pathToStateValue as E, toObserver as F, getAllOwnEventDescriptors as G, and as H, not as I, or as J, stateIn as K, cancel as L, raise as M, NULL_EVENT as N, spawnChild as O, stop as P, stopChild as Q, ProcessingStatus as R, STATE_DELIMITER as S, cloneMachineSnapshot as T, XSTATE_ERROR as U, createErrorActorEvent as V, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, macrostep as n, transitionNode as o, resolveActionsAndContext as p, createInitEvent as q, resolveStateValue as r, microstep as s, toArray as t, getInitialStateNodes as u, isStateId as v, getStateNodeByPath as w, getPersistedState as x, resolveReferencedActor as y, createActor as z };
2317
+ export { $$ACTOR_TYPE as $, Actor as A, interpret as B, isMachineSnapshot as C, matchesState as D, pathToStateValue as E, toObserver as F, getAllOwnEventDescriptors as G, and as H, not as I, or as J, stateIn as K, cancel as L, raise as M, NULL_EVENT as N, spawnChild as O, stop as P, stopChild as Q, ProcessingStatus as R, STATE_DELIMITER as S, cloneMachineSnapshot as T, XSTATE_ERROR as U, createErrorActorEvent as V, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, macrostep as n, transitionNode as o, resolveActionsAndContext as p, createInitEvent as q, resolveStateValue as r, microstep as s, toArray as t, getInitialStateNodes as u, isStateId as v, getStateNodeByPath as w, getPersistedSnapshot as x, resolveReferencedActor as y, createActor as z };