xstate 5.0.0-beta.38 → 5.0.0-beta.40

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 (44) hide show
  1. package/actions/dist/xstate-actions.cjs.js +3 -3
  2. package/actions/dist/xstate-actions.development.cjs.js +3 -3
  3. package/actions/dist/xstate-actions.development.esm.js +3 -3
  4. package/actions/dist/xstate-actions.esm.js +3 -3
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +60 -3
  8. package/actors/dist/xstate-actors.development.cjs.js +60 -3
  9. package/actors/dist/xstate-actors.development.esm.js +60 -3
  10. package/actors/dist/xstate-actors.esm.js +60 -3
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/declarations/src/StateMachine.d.ts +5 -5
  14. package/dist/declarations/src/actors/callback.d.ts +74 -0
  15. package/dist/declarations/src/actors/transition.d.ts +2 -2
  16. package/dist/declarations/src/interpreter.d.ts +70 -9
  17. package/dist/declarations/src/spawn.d.ts +2 -2
  18. package/dist/declarations/src/stateUtils.d.ts +4 -4
  19. package/dist/declarations/src/system.d.ts +7 -3
  20. package/dist/declarations/src/types.d.ts +7 -7
  21. package/dist/{interpreter-4005eb36.development.esm.js → interpreter-410d7ca9.development.esm.js} +92 -13
  22. package/dist/{interpreter-b6f22ee2.cjs.js → interpreter-586abde4.cjs.js} +92 -13
  23. package/dist/{interpreter-ed3f81f7.development.cjs.js → interpreter-bae5c279.development.cjs.js} +92 -13
  24. package/dist/{interpreter-c80ce92e.esm.js → interpreter-ed0fac7e.esm.js} +92 -13
  25. package/dist/{raise-7faa9b3b.cjs.js → raise-27909189.cjs.js} +83 -80
  26. package/dist/{raise-c989c7fb.esm.js → raise-2b2fdec3.esm.js} +83 -80
  27. package/dist/{raise-42073973.development.esm.js → raise-37f9f3b8.development.esm.js} +84 -81
  28. package/dist/{raise-b69a3d16.development.cjs.js → raise-8325e2df.development.cjs.js} +84 -81
  29. package/dist/{send-34160163.cjs.js → send-4fdf275e.cjs.js} +22 -22
  30. package/dist/{send-4b616da9.esm.js → send-59f66c58.esm.js} +22 -22
  31. package/dist/{send-58725522.development.cjs.js → send-c45d0d2c.development.cjs.js} +22 -22
  32. package/dist/{send-bff8c910.development.esm.js → send-f6b49072.development.esm.js} +22 -22
  33. package/dist/xstate.cjs.js +18 -17
  34. package/dist/xstate.development.cjs.js +18 -17
  35. package/dist/xstate.development.esm.js +21 -20
  36. package/dist/xstate.esm.js +21 -20
  37. package/dist/xstate.umd.min.js +1 -1
  38. package/dist/xstate.umd.min.js.map +1 -1
  39. package/guards/dist/xstate-guards.cjs.js +2 -2
  40. package/guards/dist/xstate-guards.development.cjs.js +2 -2
  41. package/guards/dist/xstate-guards.development.esm.js +2 -2
  42. package/guards/dist/xstate-guards.esm.js +2 -2
  43. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  44. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var interpreter = require('./interpreter-ed3f81f7.development.cjs.js');
3
+ var interpreter = require('./interpreter-bae5c279.development.cjs.js');
4
4
 
5
5
  const cache = new WeakMap();
6
6
  function memo(object, key, fn) {
@@ -22,8 +22,8 @@ function resolveCancel(_, state, actionArgs, actionParams, {
22
22
  const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
23
23
  return [state, resolvedSendId];
24
24
  }
25
- function executeCancel(actorContext, resolvedSendId) {
26
- actorContext.self.cancel(resolvedSendId);
25
+ function executeCancel(actorScope, resolvedSendId) {
26
+ actorScope.self.cancel(resolvedSendId);
27
27
  }
28
28
  /**
29
29
  * Cancels an in-flight `send(...)` action. A canceled sent action will not
@@ -45,7 +45,7 @@ function cancel(sendId) {
45
45
  return cancel;
46
46
  }
47
47
 
48
- function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
48
+ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
49
49
  id,
50
50
  systemId,
51
51
  src,
@@ -64,19 +64,19 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
64
64
  actorRef = interpreter.createActor(referenced.src, {
65
65
  id: resolvedId,
66
66
  src: typeof src === 'string' ? src : undefined,
67
- parent: actorContext?.self,
67
+ parent: actorScope?.self,
68
68
  systemId,
69
69
  input: typeof configuredInput === 'function' ? configuredInput({
70
70
  context: state.context,
71
71
  event: actionArgs.event,
72
- self: actorContext?.self
72
+ self: actorScope?.self
73
73
  }) : configuredInput
74
74
  });
75
75
  if (syncSnapshot) {
76
76
  actorRef.subscribe({
77
77
  next: snapshot => {
78
78
  if (snapshot.status === 'active') {
79
- actorContext.self.send({
79
+ actorScope.self.send({
80
80
  type: `xstate.snapshot.${id}`,
81
81
  snapshot
82
82
  });
@@ -87,7 +87,7 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
87
87
  }
88
88
  }
89
89
  if (!actorRef) {
90
- console.warn(`Actor type '${src}' not found in machine '${actorContext.id}'.`);
90
+ console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
91
91
  }
92
92
  return [cloneState(state, {
93
93
  children: {
@@ -99,21 +99,21 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
99
99
  actorRef
100
100
  }];
101
101
  }
102
- function executeSpawn(actorContext, {
102
+ function executeSpawn(actorScope, {
103
103
  id,
104
104
  actorRef
105
105
  }) {
106
106
  if (!actorRef) {
107
107
  return;
108
108
  }
109
- actorContext.defer(() => {
109
+ actorScope.defer(() => {
110
110
  if (actorRef.status === interpreter.ActorStatus.Stopped) {
111
111
  return;
112
112
  }
113
113
  try {
114
114
  actorRef.start?.();
115
115
  } catch (err) {
116
- actorContext.self.send(interpreter.createErrorActorEvent(id, err));
116
+ actorScope.self.send(interpreter.createErrorActorEvent(id, err));
117
117
  return;
118
118
  }
119
119
  });
@@ -156,7 +156,7 @@ function resolveStop(_, state, args, actionParams, {
156
156
  children
157
157
  }), resolvedActorRef];
158
158
  }
159
- function executeStop(actorContext, actorRef) {
159
+ function executeStop(actorScope, actorRef) {
160
160
  if (!actorRef) {
161
161
  return;
162
162
  }
@@ -164,20 +164,20 @@ function executeStop(actorContext, actorRef) {
164
164
  // we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
165
165
  // since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
166
166
  // this could throw on `systemId` collision, for example, when dealing with reentering transitions
167
- actorContext.system._unregister(actorRef);
167
+ actorScope.system._unregister(actorRef);
168
168
 
169
169
  // this allows us to prevent an actor from being started if it gets stopped within the same macrostep
170
170
  // this can happen, for example, when the invoking state is being exited immediately by an always transition
171
171
  if (actorRef.status !== interpreter.ActorStatus.Running) {
172
- actorContext.stopChild(actorRef);
172
+ actorScope.stopChild(actorRef);
173
173
  return;
174
174
  }
175
175
  // stopping a child enqueues a stop event in the child actor's mailbox
176
176
  // we need for all of the already enqueued events to be processed before we stop the child
177
177
  // the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
178
178
  // and we don't want to ignore those events
179
- actorContext.defer(() => {
180
- actorContext.stopChild(actorRef);
179
+ actorScope.defer(() => {
180
+ actorScope.stopChild(actorRef);
181
181
  });
182
182
  }
183
183
  /**
@@ -762,15 +762,6 @@ function isDescendant(childStateNode, parentStateNode) {
762
762
  }
763
763
  return marker.parent === parentStateNode;
764
764
  }
765
- function getPathFromRootToNode(stateNode) {
766
- const path = [];
767
- let marker = stateNode.parent;
768
- while (marker) {
769
- path.unshift(marker);
770
- marker = marker.parent;
771
- }
772
- return path;
773
- }
774
765
  function hasIntersection(s1, s2) {
775
766
  const set1 = new Set(s1);
776
767
  const set2 = new Set(s2);
@@ -810,17 +801,13 @@ function removeConflictingTransitions(enabledTransitions, configuration, history
810
801
  }
811
802
  return Array.from(filteredTransitions);
812
803
  }
813
- function findLCCA(stateNodes) {
814
- const [head] = stateNodes;
815
- let current = getPathFromRootToNode(head);
816
- let candidates = [];
817
- for (const stateNode of stateNodes) {
818
- const path = getPathFromRootToNode(stateNode);
819
- candidates = current.filter(sn => path.includes(sn));
820
- current = candidates;
821
- candidates = [];
804
+ function findLeastCommonAncestor(stateNodes) {
805
+ const [head, ...tail] = stateNodes;
806
+ for (const ancestor of getProperAncestors(head, undefined)) {
807
+ if (tail.every(sn => isDescendant(sn, ancestor))) {
808
+ return ancestor;
809
+ }
822
810
  }
823
- return current[current.length - 1];
824
811
  }
825
812
  function getEffectiveTargetStates(transition, historyValue) {
826
813
  if (!transition.target) {
@@ -852,8 +839,16 @@ function getTransitionDomain(transition, historyValue) {
852
839
  if (!transition.reenter && targetStates.every(target => target === transition.source || isDescendant(target, transition.source))) {
853
840
  return transition.source;
854
841
  }
855
- const lcca = findLCCA(targetStates.concat(transition.source));
856
- return lcca;
842
+ const lca = findLeastCommonAncestor(targetStates.concat(transition.source));
843
+ if (lca) {
844
+ return lca;
845
+ }
846
+
847
+ // at this point we know that it's a root transition since LCA couldn't be found
848
+ if (transition.reenter) {
849
+ return;
850
+ }
851
+ return transition.source.machine.root;
857
852
  }
858
853
  function computeExitSet(transitions, configuration, historyValue) {
859
854
  const statesToExit = new Set();
@@ -887,7 +882,7 @@ function areConfigurationsEqual(previousConfiguration, nextConfigurationSet) {
887
882
  /**
888
883
  * https://www.w3.org/TR/scxml/#microstepProcedure
889
884
  */
890
- function microstep(transitions, currentState, actorCtx, event, isInitial, internalQueue) {
885
+ function microstep(transitions, currentState, actorScope, event, isInitial, internalQueue) {
891
886
  if (!transitions.length) {
892
887
  return currentState;
893
888
  }
@@ -898,17 +893,17 @@ function microstep(transitions, currentState, actorCtx, event, isInitial, intern
898
893
 
899
894
  // Exit states
900
895
  if (!isInitial) {
901
- [nextState, historyValue] = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue, internalQueue);
896
+ [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, historyValue, internalQueue);
902
897
  }
903
898
 
904
899
  // Execute transition content
905
- nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions), internalQueue);
900
+ nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
906
901
 
907
902
  // Enter states
908
- nextState = enterStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
903
+ nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
909
904
  const nextConfiguration = [...mutConfiguration];
910
905
  if (nextState.status === 'done') {
911
- nextState = resolveActionsAndContext(nextState, event, actorCtx, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
906
+ nextState = resolveActionsAndContext(nextState, event, actorScope, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
912
907
  }
913
908
  try {
914
909
  if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
@@ -924,14 +919,14 @@ function microstep(transitions, currentState, actorCtx, event, isInitial, intern
924
919
  throw e;
925
920
  }
926
921
  }
927
- function getMachineOutput(state, event, actorCtx, rootNode, rootCompletionNode) {
922
+ function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode) {
928
923
  if (!rootNode.output) {
929
924
  return;
930
925
  }
931
- const doneStateEvent = interpreter.createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? interpreter.resolveOutput(rootCompletionNode.output, state.context, event, actorCtx.self) : undefined);
932
- return interpreter.resolveOutput(rootNode.output, state.context, doneStateEvent, actorCtx.self);
926
+ const doneStateEvent = interpreter.createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? interpreter.resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
927
+ return interpreter.resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
933
928
  }
934
- function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
929
+ function enterStates(currentState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
935
930
  let nextState = currentState;
936
931
  const statesToEnter = new Set();
937
932
  // those are states that were directly targeted or indirectly targeted by the explicit target
@@ -961,13 +956,13 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
961
956
  const initialActions = stateNodeToEnter.initial.actions;
962
957
  actions.push(...initialActions);
963
958
  }
964
- nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
959
+ nextState = resolveActionsAndContext(nextState, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
965
960
  if (stateNodeToEnter.type === 'final') {
966
961
  const parent = stateNodeToEnter.parent;
967
962
  let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
968
963
  let rootCompletionNode = ancestorMarker || stateNodeToEnter;
969
964
  if (parent?.type === 'compound') {
970
- internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
965
+ internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
971
966
  }
972
967
  while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutConfiguration, ancestorMarker)) {
973
968
  completedNodes.add(ancestorMarker);
@@ -980,7 +975,7 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
980
975
  }
981
976
  nextState = cloneState(nextState, {
982
977
  status: 'done',
983
- output: getMachineOutput(nextState, event, actorCtx, currentState.configuration[0].machine.root, rootCompletionNode)
978
+ output: getMachineOutput(nextState, event, actorScope, currentState.configuration[0].machine.root, rootCompletionNode)
984
979
  });
985
980
  }
986
981
  }
@@ -1005,7 +1000,11 @@ function computeEntrySet(transitions, historyValue, statesForDefaultEntry, state
1005
1000
  }
1006
1001
  const targetStates = getEffectiveTargetStates(t, historyValue);
1007
1002
  for (const s of targetStates) {
1008
- addAncestorStatesToEnter(s, domain, statesToEnter, historyValue, statesForDefaultEntry);
1003
+ const ancestors = getProperAncestors(s, domain);
1004
+ if (domain?.type === 'parallel') {
1005
+ ancestors.push(domain);
1006
+ }
1007
+ addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, !t.source.parent && t.reenter ? undefined : domain);
1009
1008
  }
1010
1009
  }
1011
1010
  }
@@ -1018,7 +1017,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1018
1017
  addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
1019
1018
  }
1020
1019
  for (const s of historyStateNodes) {
1021
- addAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
1020
+ addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
1022
1021
  }
1023
1022
  } else {
1024
1023
  const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
@@ -1030,7 +1029,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1030
1029
  addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
1031
1030
  }
1032
1031
  for (const s of historyDefaultTransition.target) {
1033
- addAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1032
+ addProperAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1034
1033
  }
1035
1034
  }
1036
1035
  } else {
@@ -1041,7 +1040,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1041
1040
  statesForDefaultEntry.add(initialState);
1042
1041
  }
1043
1042
  addDescendantStatesToEnter(initialState, historyValue, statesForDefaultEntry, statesToEnter);
1044
- addAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1043
+ addProperAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1045
1044
  } else {
1046
1045
  if (stateNode.type === 'parallel') {
1047
1046
  for (const child of getChildren(stateNode).filter(sn => !isHistoryNode(sn))) {
@@ -1057,10 +1056,11 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1057
1056
  }
1058
1057
  }
1059
1058
  }
1060
- function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1061
- const properAncestors = getProperAncestors(stateNode, toStateNode);
1062
- for (const anc of properAncestors) {
1063
- statesToEnter.add(anc);
1059
+ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, reentrancyDomain) {
1060
+ for (const anc of ancestors) {
1061
+ if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
1062
+ statesToEnter.add(anc);
1063
+ }
1064
1064
  if (anc.type === 'parallel') {
1065
1065
  for (const child of getChildren(anc).filter(sn => !isHistoryNode(sn))) {
1066
1066
  if (![...statesToEnter].some(s => isDescendant(s, child))) {
@@ -1071,7 +1071,10 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
1071
1071
  }
1072
1072
  }
1073
1073
  }
1074
- function exitStates(currentState, event, actorCtx, transitions, mutConfiguration, historyValue, internalQueue) {
1074
+ function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1075
+ addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
1076
+ }
1077
+ function exitStates(currentState, event, actorScope, transitions, mutConfiguration, historyValue, internalQueue) {
1075
1078
  let nextState = currentState;
1076
1079
  const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
1077
1080
  statesToExit.sort((a, b) => b.order - a.order);
@@ -1095,12 +1098,12 @@ function exitStates(currentState, event, actorCtx, transitions, mutConfiguration
1095
1098
  }
1096
1099
  }
1097
1100
  for (const s of statesToExit) {
1098
- nextState = resolveActionsAndContext(nextState, event, actorCtx, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
1101
+ nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
1099
1102
  mutConfiguration.delete(s);
1100
1103
  }
1101
1104
  return [nextState, changedHistory || historyValue];
1102
1105
  }
1103
- function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
1106
+ function resolveActionsAndContextWorker(currentState, event, actorScope, actions, extra, retries) {
1104
1107
  const {
1105
1108
  machine
1106
1109
  } = currentState;
@@ -1118,25 +1121,25 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
1118
1121
  const actionArgs = {
1119
1122
  context: intermediateState.context,
1120
1123
  event,
1121
- self: actorCtx?.self,
1122
- system: actorCtx?.system
1124
+ self: actorScope?.self,
1125
+ system: actorScope?.system
1123
1126
  };
1124
1127
  const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
1125
1128
  context: intermediateState.context,
1126
1129
  event
1127
1130
  }) : action.params : undefined;
1128
1131
  if (!('resolve' in resolvedAction)) {
1129
- if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
1132
+ if (actorScope?.self.status === interpreter.ActorStatus.Running) {
1130
1133
  resolvedAction(actionArgs, actionParams);
1131
1134
  } else {
1132
- actorCtx?.defer(() => {
1135
+ actorScope?.defer(() => {
1133
1136
  resolvedAction(actionArgs, actionParams);
1134
1137
  });
1135
1138
  }
1136
1139
  continue;
1137
1140
  }
1138
1141
  const builtinAction = resolvedAction;
1139
- const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, actionParams, resolvedAction,
1142
+ const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateState, actionArgs, actionParams, resolvedAction,
1140
1143
  // this holds all params
1141
1144
  extra);
1142
1145
  intermediateState = nextState;
@@ -1144,30 +1147,30 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
1144
1147
  retries?.push([builtinAction, params]);
1145
1148
  }
1146
1149
  if ('execute' in builtinAction) {
1147
- if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
1148
- builtinAction.execute(actorCtx, params);
1150
+ if (actorScope?.self.status === interpreter.ActorStatus.Running) {
1151
+ builtinAction.execute(actorScope, params);
1149
1152
  } else {
1150
- actorCtx?.defer(builtinAction.execute.bind(null, actorCtx, params));
1153
+ actorScope?.defer(builtinAction.execute.bind(null, actorScope, params));
1151
1154
  }
1152
1155
  }
1153
1156
  if (actions) {
1154
- intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
1157
+ intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorScope, actions, extra, retries);
1155
1158
  }
1156
1159
  }
1157
1160
  return intermediateState;
1158
1161
  }
1159
- function resolveActionsAndContext(currentState, event, actorCtx, actions, internalQueue, deferredActorIds) {
1162
+ function resolveActionsAndContext(currentState, event, actorScope, actions, internalQueue, deferredActorIds) {
1160
1163
  const retries = deferredActorIds ? [] : undefined;
1161
- const nextState = resolveActionsAndContextWorker(currentState, event, actorCtx, actions, {
1164
+ const nextState = resolveActionsAndContextWorker(currentState, event, actorScope, actions, {
1162
1165
  internalQueue,
1163
1166
  deferredActorIds
1164
1167
  }, retries);
1165
1168
  retries?.forEach(([builtinAction, params]) => {
1166
- builtinAction.retryResolve(actorCtx, nextState, params);
1169
+ builtinAction.retryResolve(actorScope, nextState, params);
1167
1170
  });
1168
1171
  return nextState;
1169
1172
  }
1170
- function macrostep(state, event, actorCtx, internalQueue = []) {
1173
+ function macrostep(state, event, actorScope, internalQueue = []) {
1171
1174
  if (event.type === interpreter.WILDCARD) {
1172
1175
  throw new Error(`An event cannot have the wildcard type ('${interpreter.WILDCARD}')`);
1173
1176
  }
@@ -1176,7 +1179,7 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
1176
1179
 
1177
1180
  // Handle stop event
1178
1181
  if (event.type === interpreter.XSTATE_STOP) {
1179
- nextState = cloneState(stopChildren(nextState, event, actorCtx), {
1182
+ nextState = cloneState(stopChildren(nextState, event, actorScope), {
1180
1183
  status: 'stopped'
1181
1184
  });
1182
1185
  states.push(nextState);
@@ -1191,7 +1194,7 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
1191
1194
  // Determine the next state based on the next microstep
1192
1195
  if (nextEvent.type !== interpreter.XSTATE_INIT) {
1193
1196
  const transitions = selectTransitions(nextEvent, nextState);
1194
- nextState = microstep(transitions, state, actorCtx, nextEvent, false, internalQueue);
1197
+ nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
1195
1198
  states.push(nextState);
1196
1199
  }
1197
1200
  let shouldSelectEventlessTransitions = true;
@@ -1208,20 +1211,20 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
1208
1211
  nextEvent = internalQueue.shift();
1209
1212
  enabledTransitions = selectTransitions(nextEvent, nextState);
1210
1213
  }
1211
- nextState = microstep(enabledTransitions, nextState, actorCtx, nextEvent, false, internalQueue);
1214
+ nextState = microstep(enabledTransitions, nextState, actorScope, nextEvent, false, internalQueue);
1212
1215
  shouldSelectEventlessTransitions = nextState !== previousState;
1213
1216
  states.push(nextState);
1214
1217
  }
1215
1218
  if (nextState.status !== 'active') {
1216
- stopChildren(nextState, nextEvent, actorCtx);
1219
+ stopChildren(nextState, nextEvent, actorScope);
1217
1220
  }
1218
1221
  return {
1219
1222
  state: nextState,
1220
1223
  microstates: states
1221
1224
  };
1222
1225
  }
1223
- function stopChildren(nextState, event, actorCtx) {
1224
- return resolveActionsAndContext(nextState, event, actorCtx, Object.values(nextState.children).map(child => stop(child)), []);
1226
+ function stopChildren(nextState, event, actorScope) {
1227
+ return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stop(child)), []);
1225
1228
  }
1226
1229
  function selectTransitions(event, nextState) {
1227
1230
  return nextState.machine.getTransitionData(nextState, event);
@@ -1508,9 +1511,9 @@ function resolveRaise(_, state, args, actionParams, {
1508
1511
  delay: resolvedDelay
1509
1512
  }];
1510
1513
  }
1511
- function executeRaise(actorContext, params) {
1514
+ function executeRaise(actorScope, params) {
1512
1515
  if (typeof params.delay === 'number') {
1513
- actorContext.self.delaySend(params);
1516
+ actorScope.self.delaySend(params);
1514
1517
  return;
1515
1518
  }
1516
1519
  }
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-7faa9b3b.cjs.js');
4
- var interpreter = require('./interpreter-b6f22ee2.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-27909189.cjs.js');
4
+ var interpreter = require('./interpreter-586abde4.cjs.js');
5
5
 
6
- function createSpawner(actorContext, {
6
+ function createSpawner(actorScope, {
7
7
  machine,
8
8
  context
9
9
  }, event, spawnedChildren) {
@@ -21,11 +21,11 @@ function createSpawner(actorContext, {
21
21
  // TODO: this should also receive `src`
22
22
  const actorRef = interpreter.createActor(referenced.src, {
23
23
  id: options.id,
24
- parent: actorContext.self,
24
+ parent: actorScope.self,
25
25
  input: typeof input === 'function' ? input({
26
26
  context,
27
27
  event,
28
- self: actorContext.self
28
+ self: actorScope.self
29
29
  }) : input,
30
30
  src,
31
31
  systemId
@@ -35,7 +35,7 @@ function createSpawner(actorContext, {
35
35
  actorRef.subscribe({
36
36
  next: snapshot => {
37
37
  if (snapshot.status === 'active') {
38
- actorContext.self.send({
38
+ actorScope.self.send({
39
39
  type: `xstate.snapshot.${actorRef.id}`,
40
40
  snapshot
41
41
  });
@@ -49,7 +49,7 @@ function createSpawner(actorContext, {
49
49
  // TODO: this should also receive `src`
50
50
  const actorRef = interpreter.createActor(src, {
51
51
  id: options.id,
52
- parent: actorContext.self,
52
+ parent: actorScope.self,
53
53
  input: options.input,
54
54
  src: undefined,
55
55
  systemId
@@ -58,7 +58,7 @@ function createSpawner(actorContext, {
58
58
  actorRef.subscribe({
59
59
  next: snapshot => {
60
60
  if (snapshot.status === 'active') {
61
- actorContext.self.send({
61
+ actorScope.self.send({
62
62
  type: `xstate.snapshot.${actorRef.id}`,
63
63
  snapshot,
64
64
  id: actorRef.id
@@ -74,14 +74,14 @@ function createSpawner(actorContext, {
74
74
  return (src, options) => {
75
75
  const actorRef = spawn(src, options); // TODO: fix types
76
76
  spawnedChildren[actorRef.id] = actorRef;
77
- actorContext.defer(() => {
77
+ actorScope.defer(() => {
78
78
  if (actorRef.status === interpreter.ActorStatus.Stopped) {
79
79
  return;
80
80
  }
81
81
  try {
82
82
  actorRef.start?.();
83
83
  } catch (err) {
84
- actorContext.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
84
+ actorScope.self.send(interpreter.createErrorActorEvent(actorRef.id, err));
85
85
  return;
86
86
  }
87
87
  });
@@ -89,7 +89,7 @@ function createSpawner(actorContext, {
89
89
  };
90
90
  }
91
91
 
92
- function resolveAssign(actorContext, state, actionArgs, actionParams, {
92
+ function resolveAssign(actorScope, state, actionArgs, actionParams, {
93
93
  assignment
94
94
  }) {
95
95
  if (!state.context) {
@@ -99,9 +99,9 @@ function resolveAssign(actorContext, state, actionArgs, actionParams, {
99
99
  const assignArgs = {
100
100
  context: state.context,
101
101
  event: actionArgs.event,
102
- spawn: createSpawner(actorContext, state, actionArgs.event, spawnedChildren),
103
- self: actorContext?.self,
104
- system: actorContext?.system
102
+ spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
103
+ self: actorScope?.self,
104
+ system: actorScope?.system
105
105
  };
106
106
  let partialUpdate = {};
107
107
  if (typeof assignment === 'function') {
@@ -256,7 +256,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
256
256
  return SpecialTargets;
257
257
  }({});
258
258
 
259
- function resolveSendTo(actorContext, state, args, actionParams, {
259
+ function resolveSendTo(actorScope, state, args, actionParams, {
260
260
  to,
261
261
  event: eventOrExpr,
262
262
  id,
@@ -278,9 +278,9 @@ function resolveSendTo(actorContext, state, args, actionParams, {
278
278
  let targetActorRef;
279
279
  if (typeof resolvedTarget === 'string') {
280
280
  if (resolvedTarget === SpecialTargets.Parent) {
281
- targetActorRef = actorContext?.self._parent;
281
+ targetActorRef = actorScope?.self._parent;
282
282
  } else if (resolvedTarget === SpecialTargets.Internal) {
283
- targetActorRef = actorContext?.self;
283
+ targetActorRef = actorScope?.self;
284
284
  } else if (resolvedTarget.startsWith('#_')) {
285
285
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
286
286
  // #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
@@ -292,7 +292,7 @@ function resolveSendTo(actorContext, state, args, actionParams, {
292
292
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
293
293
  }
294
294
  } else {
295
- targetActorRef = resolvedTarget || actorContext?.self;
295
+ targetActorRef = resolvedTarget || actorScope?.self;
296
296
  }
297
297
  return [state, {
298
298
  to: targetActorRef,
@@ -306,20 +306,20 @@ function retryResolveSendTo(_, state, params) {
306
306
  params.to = state.children[params.to];
307
307
  }
308
308
  }
309
- function executeSendTo(actorContext, params) {
309
+ function executeSendTo(actorScope, params) {
310
310
  if (typeof params.delay === 'number') {
311
- actorContext.self.delaySend(params);
311
+ actorScope.self.delaySend(params);
312
312
  return;
313
313
  }
314
314
 
315
315
  // this forms an outgoing events queue
316
316
  // thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
317
- actorContext.defer(() => {
317
+ actorScope.defer(() => {
318
318
  const {
319
319
  to,
320
320
  event
321
321
  } = params;
322
- actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
322
+ actorScope?.system._relay(actorScope.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorScope.self.id, event.data) : event);
323
323
  });
324
324
  }
325
325
  /**