xstate 5.0.0-beta.51 → 5.0.0-beta.53

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 (48) hide show
  1. package/actions/dist/xstate-actions.cjs.js +9 -11
  2. package/actions/dist/xstate-actions.cjs.mjs +0 -2
  3. package/actions/dist/xstate-actions.development.cjs.js +9 -11
  4. package/actions/dist/xstate-actions.development.cjs.mjs +0 -2
  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 +6 -6
  17. package/dist/declarations/src/StateNode.d.ts +4 -4
  18. package/dist/declarations/src/actions.d.ts +0 -2
  19. package/dist/declarations/src/actors/index.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 +7 -7
  23. package/dist/declarations/src/stateUtils.d.ts +9 -9
  24. package/dist/declarations/src/types.d.ts +23 -19
  25. package/dist/{pure-296f8ebd.development.esm.js → log-1fd7d00a.development.esm.js} +24 -61
  26. package/dist/{pure-aefddc19.esm.js → log-60ab9eaf.esm.js} +24 -58
  27. package/dist/{pure-c5f1b46c.cjs.js → log-717bb5a1.cjs.js} +23 -59
  28. package/dist/{pure-a0f16134.development.cjs.js → log-c8797128.development.cjs.js} +23 -62
  29. package/dist/{raise-acaa3884.development.esm.js → raise-953b1eb5.development.esm.js} +136 -136
  30. package/dist/{raise-d5633a02.cjs.js → raise-a8367773.cjs.js} +136 -136
  31. package/dist/{raise-4742bf04.esm.js → raise-be2f20bc.esm.js} +136 -136
  32. package/dist/{raise-528386de.development.cjs.js → raise-d9fd8932.development.cjs.js} +136 -136
  33. package/dist/xstate.cjs.js +28 -30
  34. package/dist/xstate.cjs.mjs +0 -2
  35. package/dist/xstate.development.cjs.js +28 -30
  36. package/dist/xstate.development.cjs.mjs +0 -2
  37. package/dist/xstate.development.esm.js +21 -21
  38. package/dist/xstate.esm.js +21 -21
  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
  47. package/dist/declarations/src/actions/choose.d.ts +0 -9
  48. package/dist/declarations/src/actions/pure.d.ts +0 -10
@@ -64,9 +64,8 @@ const XSTATE_STOP = 'xstate.stop';
64
64
  * @param id The state node ID where this event is handled
65
65
  */
66
66
  function createAfterEvent(delayRef, id) {
67
- const idSuffix = id ? `#${id}` : '';
68
67
  return {
69
- type: `xstate.after(${delayRef})${idSuffix}`
68
+ type: `xstate.after.${delayRef}.${id}`
70
69
  };
71
70
  }
72
71
 
@@ -301,16 +300,17 @@ function toObserver(nextHandler, errorHandler, completionHandler) {
301
300
  };
302
301
  }
303
302
  function createInvokeId(stateNodeId, index) {
304
- return `${stateNodeId}[${index}]`;
303
+ return `${index}.${stateNodeId}`;
305
304
  }
306
305
  function resolveReferencedActor(machine, src) {
307
- if (src.startsWith('xstate#')) {
308
- const [, indexStr] = src.match(/\[(\d+)\]$/);
309
- const node = machine.getStateNodeById(src.slice(7, -(indexStr.length + 2)));
310
- const invokeConfig = node.config.invoke;
311
- return (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
306
+ const match = src.match(/^xstate\.invoke\.(\d+)\.(.*)/);
307
+ if (!match) {
308
+ return machine.implementations.actors[src];
312
309
  }
313
- return machine.implementations.actors[src];
310
+ const [, indexStr, nodeId] = match;
311
+ const node = machine.getStateNodeById(nodeId);
312
+ const invokeConfig = node.config.invoke;
313
+ return (Array.isArray(invokeConfig) ? invokeConfig[indexStr] : invokeConfig).src;
314
314
  }
315
315
  function getAllOwnEventDescriptors(snapshot) {
316
316
  return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
@@ -352,7 +352,7 @@ class Actor {
352
352
  /**
353
353
  * The current internal state of the actor.
354
354
  */
355
- this._state = void 0;
355
+ this._snapshot = void 0;
356
356
  /**
357
357
  * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
358
358
  */
@@ -442,19 +442,19 @@ class Actor {
442
442
  this._systemId = systemId;
443
443
  this.system._set(systemId, this);
444
444
  }
445
- this._initState(options?.state);
446
- if (systemId && this._state.status !== 'active') {
445
+ this._initState(options?.snapshot ?? options?.state);
446
+ if (systemId && this._snapshot.status !== 'active') {
447
447
  this.system._unregister(this);
448
448
  }
449
449
  }
450
450
  _initState(persistedState) {
451
451
  try {
452
- this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
452
+ this._snapshot = persistedState ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
453
453
  } catch (err) {
454
- // if we get here then it means that we assign a value to this._state that is not of the correct type
454
+ // if we get here then it means that we assign a value to this._snapshot that is not of the correct type
455
455
  // we can't get the true `TSnapshot & { status: 'error'; }`, it's impossible
456
456
  // so right now this is a lie of sorts
457
- this._state = {
457
+ this._snapshot = {
458
458
  status: 'error',
459
459
  output: undefined,
460
460
  error: err
@@ -463,7 +463,7 @@ class Actor {
463
463
  }
464
464
  update(snapshot, event) {
465
465
  // Update state
466
- this._state = snapshot;
466
+ this._snapshot = snapshot;
467
467
 
468
468
  // Execute deferred effects
469
469
  let deferredFn;
@@ -477,14 +477,14 @@ class Actor {
477
477
  // no "builtin deferred" should actually throw an error since they are either safe
478
478
  // or the control flow is passed through the mailbox and errors should be caught by the `_process` used by the mailbox
479
479
  this._deferred.length = 0;
480
- this._state = {
480
+ this._snapshot = {
481
481
  ...snapshot,
482
482
  status: 'error',
483
483
  error: err
484
484
  };
485
485
  }
486
486
  }
487
- switch (this._state.status) {
487
+ switch (this._snapshot.status) {
488
488
  case 'active':
489
489
  for (const observer of this.observers) {
490
490
  try {
@@ -510,13 +510,13 @@ class Actor {
510
510
  }
511
511
  this._stopProcedure();
512
512
  this._complete();
513
- this._doneEvent = createDoneActorEvent(this.id, this._state.output);
513
+ this._doneEvent = createDoneActorEvent(this.id, this._snapshot.output);
514
514
  if (this._parent) {
515
515
  this.system._relay(this, this._parent, this._doneEvent);
516
516
  }
517
517
  break;
518
518
  case 'error':
519
- this._error(this._state.error);
519
+ this._error(this._snapshot.error);
520
520
  break;
521
521
  }
522
522
  this.system._sendInspectionEvent({
@@ -629,24 +629,24 @@ class Actor {
629
629
  actorRef: this,
630
630
  event: initEvent
631
631
  });
632
- const status = this._state.status;
632
+ const status = this._snapshot.status;
633
633
  switch (status) {
634
634
  case 'done':
635
635
  // a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
636
636
  // we still need to complete observers, flush deferreds etc
637
- this.update(this._state, initEvent);
637
+ this.update(this._snapshot, initEvent);
638
638
  // TODO: rethink cleanup of observers, mailbox, etc
639
639
  return this;
640
640
  case 'error':
641
- this._error(this._state.error);
641
+ this._error(this._snapshot.error);
642
642
  return this;
643
643
  }
644
644
  if (this.logic.start) {
645
645
  try {
646
- this.logic.start(this._state, this._actorScope);
646
+ this.logic.start(this._snapshot, this._actorScope);
647
647
  } catch (err) {
648
- this._state = {
649
- ...this._state,
648
+ this._snapshot = {
649
+ ...this._snapshot,
650
650
  status: 'error',
651
651
  error: err
652
652
  };
@@ -658,7 +658,7 @@ class Actor {
658
658
  // TODO: this notifies all subscribers but usually this is redundant
659
659
  // there is no real change happening here
660
660
  // we need to rethink if this needs to be refactored
661
- this.update(this._state, initEvent);
661
+ this.update(this._snapshot, initEvent);
662
662
  if (this.options.devTools) {
663
663
  this.attachDevTools();
664
664
  }
@@ -669,7 +669,7 @@ class Actor {
669
669
  let nextState;
670
670
  let caughtError;
671
671
  try {
672
- nextState = this.logic.transition(this._state, event, this._actorScope);
672
+ nextState = this.logic.transition(this._snapshot, event, this._actorScope);
673
673
  } catch (err) {
674
674
  // we wrap it in a box so we can rethrow it later even if falsy value gets caught here
675
675
  caughtError = {
@@ -680,8 +680,8 @@ class Actor {
680
680
  const {
681
681
  err
682
682
  } = caughtError;
683
- this._state = {
684
- ...this._state,
683
+ this._snapshot = {
684
+ ...this._snapshot,
685
685
  status: 'error',
686
686
  error: err
687
687
  };
@@ -869,8 +869,8 @@ class Actor {
869
869
  * @see https://stately.ai/docs/persistence
870
870
  */
871
871
 
872
- getPersistedState(options) {
873
- return this.logic.getPersistedState(this._state, options);
872
+ getPersistedSnapshot(options) {
873
+ return this.logic.getPersistedSnapshot(this._snapshot, options);
874
874
  }
875
875
  [symbolObservable]() {
876
876
  return this;
@@ -888,10 +888,10 @@ class Actor {
888
888
  * Note that some actors, such as callback actors generated with `fromCallback`, will not emit snapshots.
889
889
  *
890
890
  * @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
891
- * @see {@link Actor.getPersistedState} to persist the internal state of an actor (which is more than just a snapshot).
891
+ * @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
892
892
  */
893
893
  getSnapshot() {
894
- return this._state;
894
+ return this._snapshot;
895
895
  }
896
896
  }
897
897
 
@@ -944,11 +944,11 @@ const interpret = createActor;
944
944
  * @deprecated Use `Actor` instead.
945
945
  */
946
946
 
947
- function resolveCancel(_, state, actionArgs, actionParams, {
947
+ function resolveCancel(_, snapshot, actionArgs, actionParams, {
948
948
  sendId
949
949
  }) {
950
950
  const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
951
- return [state, resolvedSendId];
951
+ return [snapshot, resolvedSendId];
952
952
  }
953
953
  function executeCancel(actorScope, resolvedSendId) {
954
954
  actorScope.self.cancel(resolvedSendId);
@@ -973,14 +973,14 @@ function cancel(sendId) {
973
973
  return cancel;
974
974
  }
975
975
 
976
- function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
976
+ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
977
977
  id,
978
978
  systemId,
979
979
  src,
980
980
  input,
981
981
  syncSnapshot
982
982
  }) {
983
- const logic = typeof src === 'string' ? resolveReferencedActor(state.machine, src) : src;
983
+ const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
984
984
  const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
985
985
  let actorRef;
986
986
  if (logic) {
@@ -991,7 +991,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
991
991
  syncSnapshot,
992
992
  systemId,
993
993
  input: typeof input === 'function' ? input({
994
- context: state.context,
994
+ context: snapshot.context,
995
995
  event: actionArgs.event,
996
996
  self: actorScope?.self
997
997
  }) : input
@@ -1000,9 +1000,9 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
1000
1000
  if (!actorRef) {
1001
1001
  console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
1002
1002
  }
1003
- return [cloneMachineSnapshot(state, {
1003
+ return [cloneMachineSnapshot(snapshot, {
1004
1004
  children: {
1005
- ...state.children,
1005
+ ...snapshot.children,
1006
1006
  [resolvedId]: actorRef
1007
1007
  }
1008
1008
  }), {
@@ -1035,7 +1035,7 @@ function spawnChild(...[src, {
1035
1035
  throw new Error(`This isn't supposed to be called`);
1036
1036
  }
1037
1037
  }
1038
- spawnChild.type = 'xstate.spawnChild';
1038
+ spawnChild.type = 'snapshot.spawnChild';
1039
1039
  spawnChild.id = id;
1040
1040
  spawnChild.systemId = systemId;
1041
1041
  spawnChild.src = src;
@@ -1046,19 +1046,19 @@ function spawnChild(...[src, {
1046
1046
  return spawnChild;
1047
1047
  }
1048
1048
 
1049
- function resolveStop(_, state, args, actionParams, {
1049
+ function resolveStop(_, snapshot, args, actionParams, {
1050
1050
  actorRef
1051
1051
  }) {
1052
1052
  const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
1053
- const resolvedActorRef = typeof actorRefOrString === 'string' ? state.children[actorRefOrString] : actorRefOrString;
1054
- let children = state.children;
1053
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
1054
+ let children = snapshot.children;
1055
1055
  if (resolvedActorRef) {
1056
1056
  children = {
1057
1057
  ...children
1058
1058
  };
1059
1059
  delete children[resolvedActorRef.id];
1060
1060
  }
1061
- return [cloneMachineSnapshot(state, {
1061
+ return [cloneMachineSnapshot(snapshot, {
1062
1062
  children
1063
1063
  }), resolvedActorRef];
1064
1064
  }
@@ -1111,14 +1111,14 @@ function stopChild(actorRef) {
1111
1111
  */
1112
1112
  const stop = stopChild;
1113
1113
 
1114
- function checkStateIn(state, _, {
1114
+ function checkStateIn(snapshot, _, {
1115
1115
  stateValue
1116
1116
  }) {
1117
1117
  if (typeof stateValue === 'string' && isStateId(stateValue)) {
1118
- const target = state.machine.getStateNodeById(stateValue);
1119
- return state._nodes.some(sn => sn === target);
1118
+ const target = snapshot.machine.getStateNodeById(stateValue);
1119
+ return snapshot._nodes.some(sn => sn === target);
1120
1120
  }
1121
- return state.matches(stateValue);
1121
+ return snapshot.matches(stateValue);
1122
1122
  }
1123
1123
  function stateIn(stateValue) {
1124
1124
  function stateIn(args, params) {
@@ -1130,13 +1130,13 @@ function stateIn(stateValue) {
1130
1130
  stateIn.stateValue = stateValue;
1131
1131
  return stateIn;
1132
1132
  }
1133
- function checkNot(state, {
1133
+ function checkNot(snapshot, {
1134
1134
  context,
1135
1135
  event
1136
1136
  }, {
1137
1137
  guards
1138
1138
  }) {
1139
- return !evaluateGuard(guards[0], context, event, state);
1139
+ return !evaluateGuard(guards[0], context, event, snapshot);
1140
1140
  }
1141
1141
  function not(guard) {
1142
1142
  function not(args, params) {
@@ -1148,13 +1148,13 @@ function not(guard) {
1148
1148
  not.guards = [guard];
1149
1149
  return not;
1150
1150
  }
1151
- function checkAnd(state, {
1151
+ function checkAnd(snapshot, {
1152
1152
  context,
1153
1153
  event
1154
1154
  }, {
1155
1155
  guards
1156
1156
  }) {
1157
- return guards.every(guard => evaluateGuard(guard, context, event, state));
1157
+ return guards.every(guard => evaluateGuard(guard, context, event, snapshot));
1158
1158
  }
1159
1159
  function and(guards) {
1160
1160
  function and(args, params) {
@@ -1166,13 +1166,13 @@ function and(guards) {
1166
1166
  and.guards = guards;
1167
1167
  return and;
1168
1168
  }
1169
- function checkOr(state, {
1169
+ function checkOr(snapshot, {
1170
1170
  context,
1171
1171
  event
1172
1172
  }, {
1173
1173
  guards
1174
1174
  }) {
1175
- return guards.some(guard => evaluateGuard(guard, context, event, state));
1175
+ return guards.some(guard => evaluateGuard(guard, context, event, snapshot));
1176
1176
  }
1177
1177
  function or(guards) {
1178
1178
  function or(args, params) {
@@ -1186,17 +1186,17 @@ function or(guards) {
1186
1186
  }
1187
1187
 
1188
1188
  // TODO: throw on cycles (depth check should be enough)
1189
- function evaluateGuard(guard, context, event, state) {
1189
+ function evaluateGuard(guard, context, event, snapshot) {
1190
1190
  const {
1191
1191
  machine
1192
- } = state;
1192
+ } = snapshot;
1193
1193
  const isInline = typeof guard === 'function';
1194
1194
  const resolved = isInline ? guard : machine.implementations.guards[typeof guard === 'string' ? guard : guard.type];
1195
1195
  if (!isInline && !resolved) {
1196
1196
  throw new Error(`Guard '${typeof guard === 'string' ? guard : guard.type}' is not implemented.'.`);
1197
1197
  }
1198
1198
  if (typeof resolved !== 'function') {
1199
- return evaluateGuard(resolved, context, event, state);
1199
+ return evaluateGuard(resolved, context, event, snapshot);
1200
1200
  }
1201
1201
  const guardArgs = {
1202
1202
  context,
@@ -1213,7 +1213,7 @@ function evaluateGuard(guard, context, event, state) {
1213
1213
  return resolved(guardArgs, guardParams);
1214
1214
  }
1215
1215
  const builtinGuard = resolved;
1216
- return builtinGuard.check(state, guardArgs, resolved // this holds all params
1216
+ return builtinGuard.check(snapshot, guardArgs, resolved // this holds all params
1217
1217
  );
1218
1218
  }
1219
1219
 
@@ -1613,24 +1613,24 @@ function getStateNodes(stateNode, stateValue) {
1613
1613
  return allSubStateNodes.concat(subStateNodes);
1614
1614
  }, []));
1615
1615
  }
1616
- function transitionAtomicNode(stateNode, stateValue, state, event) {
1616
+ function transitionAtomicNode(stateNode, stateValue, snapshot, event) {
1617
1617
  const childStateNode = getStateNode(stateNode, stateValue);
1618
- const next = childStateNode.next(state, event);
1618
+ const next = childStateNode.next(snapshot, event);
1619
1619
  if (!next || !next.length) {
1620
- return stateNode.next(state, event);
1620
+ return stateNode.next(snapshot, event);
1621
1621
  }
1622
1622
  return next;
1623
1623
  }
1624
- function transitionCompoundNode(stateNode, stateValue, state, event) {
1624
+ function transitionCompoundNode(stateNode, stateValue, snapshot, event) {
1625
1625
  const subStateKeys = Object.keys(stateValue);
1626
1626
  const childStateNode = getStateNode(stateNode, subStateKeys[0]);
1627
- const next = transitionNode(childStateNode, stateValue[subStateKeys[0]], state, event);
1627
+ const next = transitionNode(childStateNode, stateValue[subStateKeys[0]], snapshot, event);
1628
1628
  if (!next || !next.length) {
1629
- return stateNode.next(state, event);
1629
+ return stateNode.next(snapshot, event);
1630
1630
  }
1631
1631
  return next;
1632
1632
  }
1633
- function transitionParallelNode(stateNode, stateValue, state, event) {
1633
+ function transitionParallelNode(stateNode, stateValue, snapshot, event) {
1634
1634
  const allInnerTransitions = [];
1635
1635
  for (const subStateKey of Object.keys(stateValue)) {
1636
1636
  const subStateValue = stateValue[subStateKey];
@@ -1638,29 +1638,29 @@ function transitionParallelNode(stateNode, stateValue, state, event) {
1638
1638
  continue;
1639
1639
  }
1640
1640
  const subStateNode = getStateNode(stateNode, subStateKey);
1641
- const innerTransitions = transitionNode(subStateNode, subStateValue, state, event);
1641
+ const innerTransitions = transitionNode(subStateNode, subStateValue, snapshot, event);
1642
1642
  if (innerTransitions) {
1643
1643
  allInnerTransitions.push(...innerTransitions);
1644
1644
  }
1645
1645
  }
1646
1646
  if (!allInnerTransitions.length) {
1647
- return stateNode.next(state, event);
1647
+ return stateNode.next(snapshot, event);
1648
1648
  }
1649
1649
  return allInnerTransitions;
1650
1650
  }
1651
- function transitionNode(stateNode, stateValue, state, event) {
1651
+ function transitionNode(stateNode, stateValue, snapshot, event) {
1652
1652
  // leaf node
1653
1653
  if (typeof stateValue === 'string') {
1654
- return transitionAtomicNode(stateNode, stateValue, state, event);
1654
+ return transitionAtomicNode(stateNode, stateValue, snapshot, event);
1655
1655
  }
1656
1656
 
1657
1657
  // compound node
1658
1658
  if (Object.keys(stateValue).length === 1) {
1659
- return transitionCompoundNode(stateNode, stateValue, state, event);
1659
+ return transitionCompoundNode(stateNode, stateValue, snapshot, event);
1660
1660
  }
1661
1661
 
1662
1662
  // parallel node
1663
- return transitionParallelNode(stateNode, stateValue, state, event);
1663
+ return transitionParallelNode(stateNode, stateValue, snapshot, event);
1664
1664
  }
1665
1665
  function getHistoryNodes(stateNode) {
1666
1666
  return Object.keys(stateNode.states).map(key => stateNode.states[key]).filter(sn => sn.type === 'history');
@@ -1792,14 +1792,14 @@ function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
1792
1792
  /**
1793
1793
  * https://www.w3.org/TR/scxml/#microstepProcedure
1794
1794
  */
1795
- function microstep(transitions, currentState, actorScope, event, isInitial, internalQueue) {
1795
+ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, internalQueue) {
1796
1796
  if (!transitions.length) {
1797
- return currentState;
1797
+ return currentSnapshot;
1798
1798
  }
1799
- const mutStateNodeSet = new Set(currentState._nodes);
1800
- let historyValue = currentState.historyValue;
1799
+ const mutStateNodeSet = new Set(currentSnapshot._nodes);
1800
+ let historyValue = currentSnapshot.historyValue;
1801
1801
  const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
1802
- let nextState = currentState;
1802
+ let nextState = currentSnapshot;
1803
1803
 
1804
1804
  // Exit states
1805
1805
  if (!isInitial) {
@@ -1816,7 +1816,7 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
1816
1816
  nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
1817
1817
  }
1818
1818
  try {
1819
- if (historyValue === currentState.historyValue && areStateNodeCollectionsEqual(currentState._nodes, mutStateNodeSet)) {
1819
+ if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
1820
1820
  return nextState;
1821
1821
  }
1822
1822
  return cloneMachineSnapshot(nextState, {
@@ -1829,15 +1829,15 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
1829
1829
  throw e;
1830
1830
  }
1831
1831
  }
1832
- function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode) {
1832
+ function getMachineOutput(snapshot, event, actorScope, rootNode, rootCompletionNode) {
1833
1833
  if (!rootNode.output) {
1834
1834
  return;
1835
1835
  }
1836
- const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
1837
- return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
1836
+ const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, snapshot.context, event, actorScope.self) : undefined);
1837
+ return resolveOutput(rootNode.output, snapshot.context, doneStateEvent, actorScope.self);
1838
1838
  }
1839
- function enterStates(currentState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
1840
- let nextState = currentState;
1839
+ function enterStates(currentSnapshot, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
1840
+ let nextSnapshot = currentSnapshot;
1841
1841
  const statesToEnter = new Set();
1842
1842
  // those are states that were directly targeted or indirectly targeted by the explicit target
1843
1843
  // in other words, those are states for which initial actions should be executed
@@ -1847,7 +1847,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1847
1847
 
1848
1848
  // In the initial state, the root state node is "entered".
1849
1849
  if (isInitial) {
1850
- statesForDefaultEntry.add(currentState.machine.root);
1850
+ statesForDefaultEntry.add(currentSnapshot.machine.root);
1851
1851
  }
1852
1852
  const completedNodes = new Set();
1853
1853
  for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
@@ -1866,13 +1866,13 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1866
1866
  const initialActions = stateNodeToEnter.initial.actions;
1867
1867
  actions.push(...initialActions);
1868
1868
  }
1869
- nextState = resolveActionsAndContext(nextState, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
1869
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
1870
1870
  if (stateNodeToEnter.type === 'final') {
1871
1871
  const parent = stateNodeToEnter.parent;
1872
1872
  let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
1873
1873
  let rootCompletionNode = ancestorMarker || stateNodeToEnter;
1874
1874
  if (parent?.type === 'compound') {
1875
- internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
1875
+ internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextSnapshot.context, event, actorScope.self) : undefined));
1876
1876
  }
1877
1877
  while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
1878
1878
  completedNodes.add(ancestorMarker);
@@ -1883,13 +1883,13 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutSt
1883
1883
  if (ancestorMarker) {
1884
1884
  continue;
1885
1885
  }
1886
- nextState = cloneMachineSnapshot(nextState, {
1886
+ nextSnapshot = cloneMachineSnapshot(nextSnapshot, {
1887
1887
  status: 'done',
1888
- output: getMachineOutput(nextState, event, actorScope, nextState.machine.root, rootCompletionNode)
1888
+ output: getMachineOutput(nextSnapshot, event, actorScope, nextSnapshot.machine.root, rootCompletionNode)
1889
1889
  });
1890
1890
  }
1891
1891
  }
1892
- return nextState;
1892
+ return nextSnapshot;
1893
1893
  }
1894
1894
  function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
1895
1895
  for (const t of transitions) {
@@ -1984,8 +1984,8 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
1984
1984
  function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1985
1985
  addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
1986
1986
  }
1987
- function exitStates(currentState, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
1988
- let nextState = currentState;
1987
+ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
1988
+ let nextSnapshot = currentSnapshot;
1989
1989
  const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
1990
1990
  statesToExit.sort((a, b) => b.order - a.order);
1991
1991
  let changedHistory;
@@ -2008,16 +2008,16 @@ function exitStates(currentState, event, actorScope, transitions, mutStateNodeSe
2008
2008
  }
2009
2009
  }
2010
2010
  for (const s of statesToExit) {
2011
- nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
2011
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
2012
2012
  mutStateNodeSet.delete(s);
2013
2013
  }
2014
- return [nextState, changedHistory || historyValue];
2014
+ return [nextSnapshot, changedHistory || historyValue];
2015
2015
  }
2016
- function resolveActionsAndContextWorker(currentState, event, actorScope, actions, extra, retries) {
2016
+ function resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, extra, retries) {
2017
2017
  const {
2018
2018
  machine
2019
- } = currentState;
2020
- let intermediateState = currentState;
2019
+ } = currentSnapshot;
2020
+ let intermediateSnapshot = currentSnapshot;
2021
2021
  for (const action of actions) {
2022
2022
  const isInline = typeof action === 'function';
2023
2023
  const resolvedAction = isInline ? action :
@@ -2029,13 +2029,13 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
2029
2029
  continue;
2030
2030
  }
2031
2031
  const actionArgs = {
2032
- context: intermediateState.context,
2032
+ context: intermediateSnapshot.context,
2033
2033
  event,
2034
2034
  self: actorScope?.self,
2035
2035
  system: actorScope?.system
2036
2036
  };
2037
2037
  const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
2038
- context: intermediateState.context,
2038
+ context: intermediateSnapshot.context,
2039
2039
  event
2040
2040
  }) : action.params : undefined;
2041
2041
  if (!('resolve' in resolvedAction)) {
@@ -2049,10 +2049,10 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
2049
2049
  continue;
2050
2050
  }
2051
2051
  const builtinAction = resolvedAction;
2052
- const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateState, actionArgs, actionParams, resolvedAction,
2052
+ const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateSnapshot, actionArgs, actionParams, resolvedAction,
2053
2053
  // this holds all params
2054
2054
  extra);
2055
- intermediateState = nextState;
2055
+ intermediateSnapshot = nextState;
2056
2056
  if ('retryResolve' in builtinAction) {
2057
2057
  retries?.push([builtinAction, params]);
2058
2058
  }
@@ -2064,14 +2064,14 @@ function resolveActionsAndContextWorker(currentState, event, actorScope, actions
2064
2064
  }
2065
2065
  }
2066
2066
  if (actions) {
2067
- intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorScope, actions, extra, retries);
2067
+ intermediateSnapshot = resolveActionsAndContextWorker(intermediateSnapshot, event, actorScope, actions, extra, retries);
2068
2068
  }
2069
2069
  }
2070
- return intermediateState;
2070
+ return intermediateSnapshot;
2071
2071
  }
2072
- function resolveActionsAndContext(currentState, event, actorScope, actions, internalQueue, deferredActorIds) {
2072
+ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, internalQueue, deferredActorIds) {
2073
2073
  const retries = deferredActorIds ? [] : undefined;
2074
- const nextState = resolveActionsAndContextWorker(currentState, event, actorScope, actions, {
2074
+ const nextState = resolveActionsAndContextWorker(currentSnapshot, event, actorScope, actions, {
2075
2075
  internalQueue,
2076
2076
  deferredActorIds
2077
2077
  }, retries);
@@ -2080,21 +2080,21 @@ function resolveActionsAndContext(currentState, event, actorScope, actions, inte
2080
2080
  });
2081
2081
  return nextState;
2082
2082
  }
2083
- function macrostep(state, event, actorScope, internalQueue = []) {
2083
+ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2084
2084
  if (event.type === WILDCARD) {
2085
2085
  throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
2086
2086
  }
2087
- let nextState = state;
2087
+ let nextSnapshot = snapshot;
2088
2088
  const states = [];
2089
2089
 
2090
2090
  // Handle stop event
2091
2091
  if (event.type === XSTATE_STOP) {
2092
- nextState = cloneMachineSnapshot(stopChildren(nextState, event, actorScope), {
2092
+ nextSnapshot = cloneMachineSnapshot(stopChildren(nextSnapshot, event, actorScope), {
2093
2093
  status: 'stopped'
2094
2094
  });
2095
- states.push(nextState);
2095
+ states.push(nextSnapshot);
2096
2096
  return {
2097
- state: nextState,
2097
+ snapshot: nextSnapshot,
2098
2098
  microstates: states
2099
2099
  };
2100
2100
  }
@@ -2105,47 +2105,47 @@ function macrostep(state, event, actorScope, internalQueue = []) {
2105
2105
  if (nextEvent.type !== XSTATE_INIT) {
2106
2106
  const currentEvent = nextEvent;
2107
2107
  const isErr = isErrorActorEvent(currentEvent);
2108
- const transitions = selectTransitions(currentEvent, nextState);
2108
+ const transitions = selectTransitions(currentEvent, nextSnapshot);
2109
2109
  if (isErr && !transitions.length) {
2110
2110
  // TODO: we should likely only allow transitions selected by very explicit descriptors
2111
2111
  // `*` shouldn't be matched, likely `xstate.error.*` shouldnt be either
2112
2112
  // similarly `xstate.error.actor.*` and `xstate.error.actor.todo.*` have to be considered too
2113
- nextState = cloneMachineSnapshot(state, {
2113
+ nextSnapshot = cloneMachineSnapshot(snapshot, {
2114
2114
  status: 'error',
2115
2115
  error: currentEvent.data
2116
2116
  });
2117
- states.push(nextState);
2117
+ states.push(nextSnapshot);
2118
2118
  return {
2119
- state: nextState,
2119
+ snapshot: nextSnapshot,
2120
2120
  microstates: states
2121
2121
  };
2122
2122
  }
2123
- nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
2124
- states.push(nextState);
2123
+ nextSnapshot = microstep(transitions, snapshot, actorScope, nextEvent, false, internalQueue);
2124
+ states.push(nextSnapshot);
2125
2125
  }
2126
2126
  let shouldSelectEventlessTransitions = true;
2127
- while (nextState.status === 'active') {
2128
- let enabledTransitions = shouldSelectEventlessTransitions ? selectEventlessTransitions(nextState, nextEvent) : [];
2127
+ while (nextSnapshot.status === 'active') {
2128
+ let enabledTransitions = shouldSelectEventlessTransitions ? selectEventlessTransitions(nextSnapshot, nextEvent) : [];
2129
2129
 
2130
2130
  // eventless transitions should always be selected after selecting *regular* transitions
2131
2131
  // by assigning `undefined` to `previousState` we ensure that `shouldSelectEventlessTransitions` gets always computed to true in such a case
2132
- const previousState = enabledTransitions.length ? nextState : undefined;
2132
+ const previousState = enabledTransitions.length ? nextSnapshot : undefined;
2133
2133
  if (!enabledTransitions.length) {
2134
2134
  if (!internalQueue.length) {
2135
2135
  break;
2136
2136
  }
2137
2137
  nextEvent = internalQueue.shift();
2138
- enabledTransitions = selectTransitions(nextEvent, nextState);
2138
+ enabledTransitions = selectTransitions(nextEvent, nextSnapshot);
2139
2139
  }
2140
- nextState = microstep(enabledTransitions, nextState, actorScope, nextEvent, false, internalQueue);
2141
- shouldSelectEventlessTransitions = nextState !== previousState;
2142
- states.push(nextState);
2140
+ nextSnapshot = microstep(enabledTransitions, nextSnapshot, actorScope, nextEvent, false, internalQueue);
2141
+ shouldSelectEventlessTransitions = nextSnapshot !== previousState;
2142
+ states.push(nextSnapshot);
2143
2143
  }
2144
- if (nextState.status !== 'active') {
2145
- stopChildren(nextState, nextEvent, actorScope);
2144
+ if (nextSnapshot.status !== 'active') {
2145
+ stopChildren(nextSnapshot, nextEvent, actorScope);
2146
2146
  }
2147
2147
  return {
2148
- state: nextState,
2148
+ snapshot: nextSnapshot,
2149
2149
  microstates: states
2150
2150
  };
2151
2151
  }
@@ -2246,13 +2246,13 @@ function createMachineSnapshot(config, machine) {
2246
2246
  toJSON: machineSnapshotToJSON
2247
2247
  };
2248
2248
  }
2249
- function cloneMachineSnapshot(state, config = {}) {
2249
+ function cloneMachineSnapshot(snapshot, config = {}) {
2250
2250
  return createMachineSnapshot({
2251
- ...state,
2251
+ ...snapshot,
2252
2252
  ...config
2253
- }, state.machine);
2253
+ }, snapshot.machine);
2254
2254
  }
2255
- function getPersistedState(state, options) {
2255
+ function getPersistedSnapshot(snapshot, options) {
2256
2256
  const {
2257
2257
  _nodes: nodes,
2258
2258
  tags,
@@ -2265,7 +2265,7 @@ function getPersistedState(state, options) {
2265
2265
  getMeta,
2266
2266
  toJSON,
2267
2267
  ...jsonValues
2268
- } = state;
2268
+ } = snapshot;
2269
2269
  const childrenJson = {};
2270
2270
  for (const id in children) {
2271
2271
  const child = children[id];
@@ -2273,7 +2273,7 @@ function getPersistedState(state, options) {
2273
2273
  throw new Error('An inline child actor cannot be persisted.');
2274
2274
  }
2275
2275
  childrenJson[id] = {
2276
- state: child.getPersistedState(options),
2276
+ snapshot: child.getPersistedSnapshot(options),
2277
2277
  src: child.src,
2278
2278
  systemId: child._systemId,
2279
2279
  syncSnapshot: child._syncSnapshot
@@ -2313,14 +2313,14 @@ function persistContext(contextPart) {
2313
2313
  return copy ?? contextPart;
2314
2314
  }
2315
2315
 
2316
- function resolveRaise(_, state, args, actionParams, {
2316
+ function resolveRaise(_, snapshot, args, actionParams, {
2317
2317
  event: eventOrExpr,
2318
2318
  id,
2319
2319
  delay
2320
2320
  }, {
2321
2321
  internalQueue
2322
2322
  }) {
2323
- const delaysMap = state.machine.implementations.delays;
2323
+ const delaysMap = snapshot.machine.implementations.delays;
2324
2324
  if (typeof eventOrExpr === 'string') {
2325
2325
  throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2326
2326
  }
@@ -2335,7 +2335,7 @@ function resolveRaise(_, state, args, actionParams, {
2335
2335
  if (typeof resolvedDelay !== 'number') {
2336
2336
  internalQueue.push(resolvedEvent);
2337
2337
  }
2338
- return [state, {
2338
+ return [snapshot, {
2339
2339
  event: resolvedEvent,
2340
2340
  id,
2341
2341
  delay: resolvedDelay
@@ -2368,4 +2368,4 @@ function raise(eventOrExpr, options) {
2368
2368
  return raise;
2369
2369
  }
2370
2370
 
2371
- 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 };
2371
+ 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 };