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,4 +1,4 @@
1
- import { r as resolveReferencedActor, d as createActor, f as ActorStatus, j as createErrorActorEvent, k as toStateValue, l as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, o as toStatePath, q as createDoneStateEvent, s as resolveOutput, W as WILDCARD, X as XSTATE_STOP, u as XSTATE_INIT, v as createAfterEvent, w as flatten, e as matchesState, $ as $$ACTOR_TYPE } from './interpreter-4005eb36.development.esm.js';
1
+ import { r as resolveReferencedActor, d as createActor, f as ActorStatus, j as createErrorActorEvent, k as toStateValue, l as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, o as toStatePath, q as createDoneStateEvent, s as resolveOutput, W as WILDCARD, X as XSTATE_STOP, u as XSTATE_INIT, v as createAfterEvent, w as flatten, e as matchesState, $ as $$ACTOR_TYPE } from './interpreter-410d7ca9.development.esm.js';
2
2
 
3
3
  const cache = new WeakMap();
4
4
  function memo(object, key, fn) {
@@ -20,8 +20,8 @@ function resolveCancel(_, state, actionArgs, actionParams, {
20
20
  const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
21
21
  return [state, resolvedSendId];
22
22
  }
23
- function executeCancel(actorContext, resolvedSendId) {
24
- actorContext.self.cancel(resolvedSendId);
23
+ function executeCancel(actorScope, resolvedSendId) {
24
+ actorScope.self.cancel(resolvedSendId);
25
25
  }
26
26
  /**
27
27
  * Cancels an in-flight `send(...)` action. A canceled sent action will not
@@ -43,7 +43,7 @@ function cancel(sendId) {
43
43
  return cancel;
44
44
  }
45
45
 
46
- function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
46
+ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
47
47
  id,
48
48
  systemId,
49
49
  src,
@@ -62,19 +62,19 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
62
62
  actorRef = createActor(referenced.src, {
63
63
  id: resolvedId,
64
64
  src: typeof src === 'string' ? src : undefined,
65
- parent: actorContext?.self,
65
+ parent: actorScope?.self,
66
66
  systemId,
67
67
  input: typeof configuredInput === 'function' ? configuredInput({
68
68
  context: state.context,
69
69
  event: actionArgs.event,
70
- self: actorContext?.self
70
+ self: actorScope?.self
71
71
  }) : configuredInput
72
72
  });
73
73
  if (syncSnapshot) {
74
74
  actorRef.subscribe({
75
75
  next: snapshot => {
76
76
  if (snapshot.status === 'active') {
77
- actorContext.self.send({
77
+ actorScope.self.send({
78
78
  type: `xstate.snapshot.${id}`,
79
79
  snapshot
80
80
  });
@@ -85,7 +85,7 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
85
85
  }
86
86
  }
87
87
  if (!actorRef) {
88
- console.warn(`Actor type '${src}' not found in machine '${actorContext.id}'.`);
88
+ console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
89
89
  }
90
90
  return [cloneState(state, {
91
91
  children: {
@@ -97,21 +97,21 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
97
97
  actorRef
98
98
  }];
99
99
  }
100
- function executeSpawn(actorContext, {
100
+ function executeSpawn(actorScope, {
101
101
  id,
102
102
  actorRef
103
103
  }) {
104
104
  if (!actorRef) {
105
105
  return;
106
106
  }
107
- actorContext.defer(() => {
107
+ actorScope.defer(() => {
108
108
  if (actorRef.status === ActorStatus.Stopped) {
109
109
  return;
110
110
  }
111
111
  try {
112
112
  actorRef.start?.();
113
113
  } catch (err) {
114
- actorContext.self.send(createErrorActorEvent(id, err));
114
+ actorScope.self.send(createErrorActorEvent(id, err));
115
115
  return;
116
116
  }
117
117
  });
@@ -154,7 +154,7 @@ function resolveStop(_, state, args, actionParams, {
154
154
  children
155
155
  }), resolvedActorRef];
156
156
  }
157
- function executeStop(actorContext, actorRef) {
157
+ function executeStop(actorScope, actorRef) {
158
158
  if (!actorRef) {
159
159
  return;
160
160
  }
@@ -162,20 +162,20 @@ function executeStop(actorContext, actorRef) {
162
162
  // we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
163
163
  // since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
164
164
  // this could throw on `systemId` collision, for example, when dealing with reentering transitions
165
- actorContext.system._unregister(actorRef);
165
+ actorScope.system._unregister(actorRef);
166
166
 
167
167
  // this allows us to prevent an actor from being started if it gets stopped within the same macrostep
168
168
  // this can happen, for example, when the invoking state is being exited immediately by an always transition
169
169
  if (actorRef.status !== ActorStatus.Running) {
170
- actorContext.stopChild(actorRef);
170
+ actorScope.stopChild(actorRef);
171
171
  return;
172
172
  }
173
173
  // stopping a child enqueues a stop event in the child actor's mailbox
174
174
  // we need for all of the already enqueued events to be processed before we stop the child
175
175
  // the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
176
176
  // and we don't want to ignore those events
177
- actorContext.defer(() => {
178
- actorContext.stopChild(actorRef);
177
+ actorScope.defer(() => {
178
+ actorScope.stopChild(actorRef);
179
179
  });
180
180
  }
181
181
  /**
@@ -760,15 +760,6 @@ function isDescendant(childStateNode, parentStateNode) {
760
760
  }
761
761
  return marker.parent === parentStateNode;
762
762
  }
763
- function getPathFromRootToNode(stateNode) {
764
- const path = [];
765
- let marker = stateNode.parent;
766
- while (marker) {
767
- path.unshift(marker);
768
- marker = marker.parent;
769
- }
770
- return path;
771
- }
772
763
  function hasIntersection(s1, s2) {
773
764
  const set1 = new Set(s1);
774
765
  const set2 = new Set(s2);
@@ -808,17 +799,13 @@ function removeConflictingTransitions(enabledTransitions, configuration, history
808
799
  }
809
800
  return Array.from(filteredTransitions);
810
801
  }
811
- function findLCCA(stateNodes) {
812
- const [head] = stateNodes;
813
- let current = getPathFromRootToNode(head);
814
- let candidates = [];
815
- for (const stateNode of stateNodes) {
816
- const path = getPathFromRootToNode(stateNode);
817
- candidates = current.filter(sn => path.includes(sn));
818
- current = candidates;
819
- candidates = [];
802
+ function findLeastCommonAncestor(stateNodes) {
803
+ const [head, ...tail] = stateNodes;
804
+ for (const ancestor of getProperAncestors(head, undefined)) {
805
+ if (tail.every(sn => isDescendant(sn, ancestor))) {
806
+ return ancestor;
807
+ }
820
808
  }
821
- return current[current.length - 1];
822
809
  }
823
810
  function getEffectiveTargetStates(transition, historyValue) {
824
811
  if (!transition.target) {
@@ -850,8 +837,16 @@ function getTransitionDomain(transition, historyValue) {
850
837
  if (!transition.reenter && targetStates.every(target => target === transition.source || isDescendant(target, transition.source))) {
851
838
  return transition.source;
852
839
  }
853
- const lcca = findLCCA(targetStates.concat(transition.source));
854
- return lcca;
840
+ const lca = findLeastCommonAncestor(targetStates.concat(transition.source));
841
+ if (lca) {
842
+ return lca;
843
+ }
844
+
845
+ // at this point we know that it's a root transition since LCA couldn't be found
846
+ if (transition.reenter) {
847
+ return;
848
+ }
849
+ return transition.source.machine.root;
855
850
  }
856
851
  function computeExitSet(transitions, configuration, historyValue) {
857
852
  const statesToExit = new Set();
@@ -885,7 +880,7 @@ function areConfigurationsEqual(previousConfiguration, nextConfigurationSet) {
885
880
  /**
886
881
  * https://www.w3.org/TR/scxml/#microstepProcedure
887
882
  */
888
- function microstep(transitions, currentState, actorCtx, event, isInitial, internalQueue) {
883
+ function microstep(transitions, currentState, actorScope, event, isInitial, internalQueue) {
889
884
  if (!transitions.length) {
890
885
  return currentState;
891
886
  }
@@ -896,17 +891,17 @@ function microstep(transitions, currentState, actorCtx, event, isInitial, intern
896
891
 
897
892
  // Exit states
898
893
  if (!isInitial) {
899
- [nextState, historyValue] = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue, internalQueue);
894
+ [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, historyValue, internalQueue);
900
895
  }
901
896
 
902
897
  // Execute transition content
903
- nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions), internalQueue);
898
+ nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
904
899
 
905
900
  // Enter states
906
- nextState = enterStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
901
+ nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
907
902
  const nextConfiguration = [...mutConfiguration];
908
903
  if (nextState.status === 'done') {
909
- nextState = resolveActionsAndContext(nextState, event, actorCtx, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
904
+ nextState = resolveActionsAndContext(nextState, event, actorScope, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
910
905
  }
911
906
  try {
912
907
  if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
@@ -922,14 +917,14 @@ function microstep(transitions, currentState, actorCtx, event, isInitial, intern
922
917
  throw e;
923
918
  }
924
919
  }
925
- function getMachineOutput(state, event, actorCtx, rootNode, rootCompletionNode) {
920
+ function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode) {
926
921
  if (!rootNode.output) {
927
922
  return;
928
923
  }
929
- const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorCtx.self) : undefined);
930
- return resolveOutput(rootNode.output, state.context, doneStateEvent, actorCtx.self);
924
+ const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
925
+ return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
931
926
  }
932
- function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
927
+ function enterStates(currentState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
933
928
  let nextState = currentState;
934
929
  const statesToEnter = new Set();
935
930
  // those are states that were directly targeted or indirectly targeted by the explicit target
@@ -959,13 +954,13 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
959
954
  const initialActions = stateNodeToEnter.initial.actions;
960
955
  actions.push(...initialActions);
961
956
  }
962
- nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
957
+ nextState = resolveActionsAndContext(nextState, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
963
958
  if (stateNodeToEnter.type === 'final') {
964
959
  const parent = stateNodeToEnter.parent;
965
960
  let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
966
961
  let rootCompletionNode = ancestorMarker || stateNodeToEnter;
967
962
  if (parent?.type === 'compound') {
968
- internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
963
+ internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
969
964
  }
970
965
  while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutConfiguration, ancestorMarker)) {
971
966
  completedNodes.add(ancestorMarker);
@@ -978,7 +973,7 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
978
973
  }
979
974
  nextState = cloneState(nextState, {
980
975
  status: 'done',
981
- output: getMachineOutput(nextState, event, actorCtx, currentState.configuration[0].machine.root, rootCompletionNode)
976
+ output: getMachineOutput(nextState, event, actorScope, currentState.configuration[0].machine.root, rootCompletionNode)
982
977
  });
983
978
  }
984
979
  }
@@ -1003,7 +998,11 @@ function computeEntrySet(transitions, historyValue, statesForDefaultEntry, state
1003
998
  }
1004
999
  const targetStates = getEffectiveTargetStates(t, historyValue);
1005
1000
  for (const s of targetStates) {
1006
- addAncestorStatesToEnter(s, domain, statesToEnter, historyValue, statesForDefaultEntry);
1001
+ const ancestors = getProperAncestors(s, domain);
1002
+ if (domain?.type === 'parallel') {
1003
+ ancestors.push(domain);
1004
+ }
1005
+ addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, !t.source.parent && t.reenter ? undefined : domain);
1007
1006
  }
1008
1007
  }
1009
1008
  }
@@ -1016,7 +1015,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1016
1015
  addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
1017
1016
  }
1018
1017
  for (const s of historyStateNodes) {
1019
- addAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
1018
+ addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
1020
1019
  }
1021
1020
  } else {
1022
1021
  const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
@@ -1028,7 +1027,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1028
1027
  addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
1029
1028
  }
1030
1029
  for (const s of historyDefaultTransition.target) {
1031
- addAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1030
+ addProperAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1032
1031
  }
1033
1032
  }
1034
1033
  } else {
@@ -1039,7 +1038,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1039
1038
  statesForDefaultEntry.add(initialState);
1040
1039
  }
1041
1040
  addDescendantStatesToEnter(initialState, historyValue, statesForDefaultEntry, statesToEnter);
1042
- addAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1041
+ addProperAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1043
1042
  } else {
1044
1043
  if (stateNode.type === 'parallel') {
1045
1044
  for (const child of getChildren(stateNode).filter(sn => !isHistoryNode(sn))) {
@@ -1055,10 +1054,11 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1055
1054
  }
1056
1055
  }
1057
1056
  }
1058
- function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1059
- const properAncestors = getProperAncestors(stateNode, toStateNode);
1060
- for (const anc of properAncestors) {
1061
- statesToEnter.add(anc);
1057
+ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, reentrancyDomain) {
1058
+ for (const anc of ancestors) {
1059
+ if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
1060
+ statesToEnter.add(anc);
1061
+ }
1062
1062
  if (anc.type === 'parallel') {
1063
1063
  for (const child of getChildren(anc).filter(sn => !isHistoryNode(sn))) {
1064
1064
  if (![...statesToEnter].some(s => isDescendant(s, child))) {
@@ -1069,7 +1069,10 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
1069
1069
  }
1070
1070
  }
1071
1071
  }
1072
- function exitStates(currentState, event, actorCtx, transitions, mutConfiguration, historyValue, internalQueue) {
1072
+ function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1073
+ addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
1074
+ }
1075
+ function exitStates(currentState, event, actorScope, transitions, mutConfiguration, historyValue, internalQueue) {
1073
1076
  let nextState = currentState;
1074
1077
  const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
1075
1078
  statesToExit.sort((a, b) => b.order - a.order);
@@ -1093,12 +1096,12 @@ function exitStates(currentState, event, actorCtx, transitions, mutConfiguration
1093
1096
  }
1094
1097
  }
1095
1098
  for (const s of statesToExit) {
1096
- nextState = resolveActionsAndContext(nextState, event, actorCtx, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
1099
+ nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
1097
1100
  mutConfiguration.delete(s);
1098
1101
  }
1099
1102
  return [nextState, changedHistory || historyValue];
1100
1103
  }
1101
- function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
1104
+ function resolveActionsAndContextWorker(currentState, event, actorScope, actions, extra, retries) {
1102
1105
  const {
1103
1106
  machine
1104
1107
  } = currentState;
@@ -1116,25 +1119,25 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
1116
1119
  const actionArgs = {
1117
1120
  context: intermediateState.context,
1118
1121
  event,
1119
- self: actorCtx?.self,
1120
- system: actorCtx?.system
1122
+ self: actorScope?.self,
1123
+ system: actorScope?.system
1121
1124
  };
1122
1125
  const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
1123
1126
  context: intermediateState.context,
1124
1127
  event
1125
1128
  }) : action.params : undefined;
1126
1129
  if (!('resolve' in resolvedAction)) {
1127
- if (actorCtx?.self.status === ActorStatus.Running) {
1130
+ if (actorScope?.self.status === ActorStatus.Running) {
1128
1131
  resolvedAction(actionArgs, actionParams);
1129
1132
  } else {
1130
- actorCtx?.defer(() => {
1133
+ actorScope?.defer(() => {
1131
1134
  resolvedAction(actionArgs, actionParams);
1132
1135
  });
1133
1136
  }
1134
1137
  continue;
1135
1138
  }
1136
1139
  const builtinAction = resolvedAction;
1137
- const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, actionParams, resolvedAction,
1140
+ const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateState, actionArgs, actionParams, resolvedAction,
1138
1141
  // this holds all params
1139
1142
  extra);
1140
1143
  intermediateState = nextState;
@@ -1142,30 +1145,30 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
1142
1145
  retries?.push([builtinAction, params]);
1143
1146
  }
1144
1147
  if ('execute' in builtinAction) {
1145
- if (actorCtx?.self.status === ActorStatus.Running) {
1146
- builtinAction.execute(actorCtx, params);
1148
+ if (actorScope?.self.status === ActorStatus.Running) {
1149
+ builtinAction.execute(actorScope, params);
1147
1150
  } else {
1148
- actorCtx?.defer(builtinAction.execute.bind(null, actorCtx, params));
1151
+ actorScope?.defer(builtinAction.execute.bind(null, actorScope, params));
1149
1152
  }
1150
1153
  }
1151
1154
  if (actions) {
1152
- intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
1155
+ intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorScope, actions, extra, retries);
1153
1156
  }
1154
1157
  }
1155
1158
  return intermediateState;
1156
1159
  }
1157
- function resolveActionsAndContext(currentState, event, actorCtx, actions, internalQueue, deferredActorIds) {
1160
+ function resolveActionsAndContext(currentState, event, actorScope, actions, internalQueue, deferredActorIds) {
1158
1161
  const retries = deferredActorIds ? [] : undefined;
1159
- const nextState = resolveActionsAndContextWorker(currentState, event, actorCtx, actions, {
1162
+ const nextState = resolveActionsAndContextWorker(currentState, event, actorScope, actions, {
1160
1163
  internalQueue,
1161
1164
  deferredActorIds
1162
1165
  }, retries);
1163
1166
  retries?.forEach(([builtinAction, params]) => {
1164
- builtinAction.retryResolve(actorCtx, nextState, params);
1167
+ builtinAction.retryResolve(actorScope, nextState, params);
1165
1168
  });
1166
1169
  return nextState;
1167
1170
  }
1168
- function macrostep(state, event, actorCtx, internalQueue = []) {
1171
+ function macrostep(state, event, actorScope, internalQueue = []) {
1169
1172
  if (event.type === WILDCARD) {
1170
1173
  throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
1171
1174
  }
@@ -1174,7 +1177,7 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
1174
1177
 
1175
1178
  // Handle stop event
1176
1179
  if (event.type === XSTATE_STOP) {
1177
- nextState = cloneState(stopChildren(nextState, event, actorCtx), {
1180
+ nextState = cloneState(stopChildren(nextState, event, actorScope), {
1178
1181
  status: 'stopped'
1179
1182
  });
1180
1183
  states.push(nextState);
@@ -1189,7 +1192,7 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
1189
1192
  // Determine the next state based on the next microstep
1190
1193
  if (nextEvent.type !== XSTATE_INIT) {
1191
1194
  const transitions = selectTransitions(nextEvent, nextState);
1192
- nextState = microstep(transitions, state, actorCtx, nextEvent, false, internalQueue);
1195
+ nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
1193
1196
  states.push(nextState);
1194
1197
  }
1195
1198
  let shouldSelectEventlessTransitions = true;
@@ -1206,20 +1209,20 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
1206
1209
  nextEvent = internalQueue.shift();
1207
1210
  enabledTransitions = selectTransitions(nextEvent, nextState);
1208
1211
  }
1209
- nextState = microstep(enabledTransitions, nextState, actorCtx, nextEvent, false, internalQueue);
1212
+ nextState = microstep(enabledTransitions, nextState, actorScope, nextEvent, false, internalQueue);
1210
1213
  shouldSelectEventlessTransitions = nextState !== previousState;
1211
1214
  states.push(nextState);
1212
1215
  }
1213
1216
  if (nextState.status !== 'active') {
1214
- stopChildren(nextState, nextEvent, actorCtx);
1217
+ stopChildren(nextState, nextEvent, actorScope);
1215
1218
  }
1216
1219
  return {
1217
1220
  state: nextState,
1218
1221
  microstates: states
1219
1222
  };
1220
1223
  }
1221
- function stopChildren(nextState, event, actorCtx) {
1222
- return resolveActionsAndContext(nextState, event, actorCtx, Object.values(nextState.children).map(child => stop(child)), []);
1224
+ function stopChildren(nextState, event, actorScope) {
1225
+ return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stop(child)), []);
1223
1226
  }
1224
1227
  function selectTransitions(event, nextState) {
1225
1228
  return nextState.machine.getTransitionData(nextState, event);
@@ -1506,9 +1509,9 @@ function resolveRaise(_, state, args, actionParams, {
1506
1509
  delay: resolvedDelay
1507
1510
  }];
1508
1511
  }
1509
- function executeRaise(actorContext, params) {
1512
+ function executeRaise(actorScope, params) {
1510
1513
  if (typeof params.delay === 'number') {
1511
- actorContext.self.delaySend(params);
1514
+ actorScope.self.delaySend(params);
1512
1515
  return;
1513
1516
  }
1514
1517
  }