xstate 5.0.0-beta.32 → 5.0.0-beta.34

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 (42) 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 +31 -20
  8. package/actors/dist/xstate-actors.development.cjs.js +31 -20
  9. package/actors/dist/xstate-actors.development.esm.js +31 -20
  10. package/actors/dist/xstate-actors.esm.js +31 -20
  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/index.d.ts +1 -0
  14. package/dist/declarations/src/interpreter.d.ts +1 -1
  15. package/dist/declarations/src/stateUtils.d.ts +2 -2
  16. package/dist/declarations/src/system.d.ts +22 -0
  17. package/dist/declarations/src/types.d.ts +4 -5
  18. package/dist/declarations/src/utils.d.ts +0 -1
  19. package/dist/{interpreter-05e11c15.cjs.js → interpreter-1301970f.cjs.js} +77 -32
  20. package/dist/{interpreter-a2236840.development.cjs.js → interpreter-70ed62f2.development.cjs.js} +80 -32
  21. package/dist/{interpreter-d5fa7ce0.esm.js → interpreter-83f7f2d4.esm.js} +78 -33
  22. package/dist/{interpreter-e4d2487f.development.esm.js → interpreter-dee56dc8.development.esm.js} +81 -33
  23. package/dist/{raise-6fbd4513.development.esm.js → raise-05f8b2a6.development.esm.js} +52 -33
  24. package/dist/{raise-90808d65.cjs.js → raise-1dd65455.cjs.js} +52 -33
  25. package/dist/{raise-b4bfe138.development.cjs.js → raise-38b707c0.development.cjs.js} +52 -33
  26. package/dist/{raise-6a68d0cc.esm.js → raise-b5cfe1bb.esm.js} +52 -33
  27. package/dist/{send-e5f0f3f6.esm.js → send-0b5eda0c.esm.js} +15 -9
  28. package/dist/{send-4163d2af.development.cjs.js → send-3764c866.development.cjs.js} +15 -9
  29. package/dist/{send-7baeedcb.development.esm.js → send-9526366e.development.esm.js} +15 -9
  30. package/dist/{send-72e85cc6.cjs.js → send-fe94de2b.cjs.js} +15 -9
  31. package/dist/xstate.cjs.js +6 -31
  32. package/dist/xstate.development.cjs.js +6 -31
  33. package/dist/xstate.development.esm.js +9 -34
  34. package/dist/xstate.esm.js +9 -34
  35. package/dist/xstate.umd.min.js +1 -1
  36. package/dist/xstate.umd.min.js.map +1 -1
  37. package/guards/dist/xstate-guards.cjs.js +2 -2
  38. package/guards/dist/xstate-guards.development.cjs.js +2 -2
  39. package/guards/dist/xstate-guards.development.esm.js +2 -2
  40. package/guards/dist/xstate-guards.esm.js +2 -2
  41. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  42. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var interpreter = require('./interpreter-a2236840.development.cjs.js');
3
+ var interpreter = require('./interpreter-70ed62f2.development.cjs.js');
4
4
 
5
5
  const cache = new WeakMap();
6
6
  function memo(object, key, fn) {
@@ -918,31 +918,33 @@ function microstep(transitions, currentState, actorCtx, event, isInitial) {
918
918
  }
919
919
 
920
920
  function microstepProcedure(transitions, currentState, mutConfiguration, event, actorCtx, isInitial) {
921
- const actions = [];
922
921
  const historyValue = {
923
922
  ...currentState.historyValue
924
923
  };
925
924
  const filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
926
925
  const internalQueue = [...currentState._internalQueue];
926
+ // TODO: this `cloneState` is really just a hack to prevent infinite loops
927
+ // we need to take another look at how internal queue is managed
928
+ let nextState = cloneState(currentState, {
929
+ _internalQueue: []
930
+ });
927
931
 
928
932
  // Exit states
929
933
  if (!isInitial) {
930
- exitStates(filteredTransitions, mutConfiguration, historyValue, actions);
934
+ nextState = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue);
931
935
  }
932
936
 
933
937
  // Execute transition content
934
- actions.push(...filteredTransitions.flatMap(t => t.actions));
938
+ nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions));
935
939
 
936
940
  // Enter states
937
- enterStates(event, filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue, isInitial, actorCtx);
941
+ nextState = enterStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
938
942
  const nextConfiguration = [...mutConfiguration];
939
943
  const done = isInFinalState(nextConfiguration);
940
944
  if (done) {
941
- const finalActions = nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit);
942
- actions.push(...finalActions);
945
+ nextState = resolveActionsAndContext(nextState, event, actorCtx, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit));
943
946
  }
944
947
  try {
945
- const nextState = resolveActionsAndContext(actions, event, currentState, actorCtx);
946
948
  const output = done ? getOutput(nextConfiguration, nextState.context, event, actorCtx.self) : undefined;
947
949
  internalQueue.push(...nextState._internalQueue);
948
950
  return cloneState(currentState, {
@@ -960,7 +962,8 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
960
962
  throw e;
961
963
  }
962
964
  }
963
- function enterStates(event, filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue, isInitial, actorContext) {
965
+ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
966
+ let nextState = currentState;
964
967
  const statesToEnter = new Set();
965
968
  const statesForDefaultEntry = new Set();
966
969
  computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
@@ -971,24 +974,26 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
971
974
  }
972
975
  for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
973
976
  mutConfiguration.add(stateNodeToEnter);
974
- for (const invokeDef of stateNodeToEnter.invoke) {
975
- actions.push(invoke(invokeDef));
976
- }
977
+ const actions = [];
977
978
 
978
979
  // Add entry actions
979
980
  actions.push(...stateNodeToEnter.entry);
981
+ for (const invokeDef of stateNodeToEnter.invoke) {
982
+ actions.push(invoke(invokeDef));
983
+ }
980
984
  if (statesForDefaultEntry.has(stateNodeToEnter)) {
981
985
  for (const stateNode of statesForDefaultEntry) {
982
986
  const initialActions = stateNode.initial.actions;
983
987
  actions.push(...initialActions);
984
988
  }
985
989
  }
990
+ nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
986
991
  if (stateNodeToEnter.type === 'final') {
987
992
  const parent = stateNodeToEnter.parent;
988
993
  if (!parent.parent) {
989
994
  continue;
990
995
  }
991
- internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output, currentState.context, event, actorContext.self) : undefined));
996
+ internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
992
997
  if (parent.parent) {
993
998
  const grandparent = parent.parent;
994
999
  if (grandparent.type === 'parallel') {
@@ -999,6 +1004,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
999
1004
  }
1000
1005
  }
1001
1006
  }
1007
+ return nextState;
1002
1008
  }
1003
1009
  function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
1004
1010
  for (const t of transitions) {
@@ -1072,7 +1078,8 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
1072
1078
  }
1073
1079
  }
1074
1080
  }
1075
- function exitStates(transitions, mutConfiguration, historyValue, actions) {
1081
+ function exitStates(currentState, event, actorCtx, transitions, mutConfiguration, historyValue) {
1082
+ let nextState = currentState;
1076
1083
  const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
1077
1084
  statesToExit.sort((a, b) => b.order - a.order);
1078
1085
 
@@ -1091,27 +1098,24 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
1091
1098
  }
1092
1099
  }
1093
1100
  for (const s of statesToExit) {
1094
- actions.push(...s.exit, ...s.invoke.map(def => stop(def.id)));
1101
+ nextState = resolveActionsAndContext(nextState, event, actorCtx, [...s.exit, ...s.invoke.map(def => stop(def.id))]);
1095
1102
  mutConfiguration.delete(s);
1096
1103
  }
1104
+ return nextState;
1097
1105
  }
1098
- function resolveActionsAndContext(actions, event, currentState, actorCtx) {
1106
+ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
1099
1107
  const {
1100
1108
  machine
1101
1109
  } = currentState;
1102
- // TODO: this `cloneState` is really just a hack to prevent infinite loops
1103
- // we need to take another look at how internal queue is managed
1104
- let intermediateState = cloneState(currentState, {
1105
- _internalQueue: []
1106
- });
1110
+ let intermediateState = currentState;
1107
1111
  for (const action of actions) {
1108
1112
  const isInline = typeof action === 'function';
1109
- const resolved = isInline ? action :
1113
+ const resolvedAction = isInline ? action :
1110
1114
  // the existing type of `.actions` assumes non-nullable `TExpressionAction`
1111
1115
  // it's fine to cast this here to get a common type and lack of errors in the rest of the code
1112
1116
  // our logic below makes sure that we call those 2 "variants" correctly
1113
1117
  machine.implementations.actions[typeof action === 'string' ? action : action.type];
1114
- if (!resolved) {
1118
+ if (!resolvedAction) {
1115
1119
  continue;
1116
1120
  }
1117
1121
  const actionArgs = {
@@ -1131,20 +1135,25 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
1131
1135
  // TS isn't able to narrow it down here
1132
1136
  action
1133
1137
  };
1134
- if (!('resolve' in resolved)) {
1138
+ if (!('resolve' in resolvedAction)) {
1135
1139
  if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
1136
- resolved(actionArgs);
1140
+ resolvedAction(actionArgs);
1137
1141
  } else {
1138
- actorCtx?.defer(() => resolved(actionArgs));
1142
+ actorCtx?.defer(() => {
1143
+ resolvedAction(actionArgs);
1144
+ });
1139
1145
  }
1140
1146
  continue;
1141
1147
  }
1142
- const builtinAction = resolved;
1143
- const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolved // this holds all params
1144
- );
1145
-
1148
+ const builtinAction = resolvedAction;
1149
+ const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction,
1150
+ // this holds all params
1151
+ extra);
1146
1152
  intermediateState = nextState;
1147
- if ('execute' in resolved) {
1153
+ if ('retryResolve' in builtinAction) {
1154
+ retries?.push([builtinAction, params]);
1155
+ }
1156
+ if ('execute' in builtinAction) {
1148
1157
  if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
1149
1158
  builtinAction.execute(actorCtx, params);
1150
1159
  } else {
@@ -1152,11 +1161,21 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
1152
1161
  }
1153
1162
  }
1154
1163
  if (actions) {
1155
- intermediateState = resolveActionsAndContext(actions, event, intermediateState, actorCtx);
1164
+ intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
1156
1165
  }
1157
1166
  }
1158
1167
  return intermediateState;
1159
1168
  }
1169
+ function resolveActionsAndContext(currentState, event, actorCtx, actions, deferredActorIds) {
1170
+ const retries = deferredActorIds ? [] : undefined;
1171
+ const nextState = resolveActionsAndContextWorker(currentState, event, actorCtx, actions, deferredActorIds && {
1172
+ deferredActorIds
1173
+ }, retries);
1174
+ retries?.forEach(([builtinAction, params]) => {
1175
+ builtinAction.retryResolve(actorCtx, nextState, params);
1176
+ });
1177
+ return nextState;
1178
+ }
1160
1179
  function macrostep(state, event, actorCtx) {
1161
1180
  if (event.type === interpreter.WILDCARD) {
1162
1181
  throw new Error(`An event cannot have the wildcard type ('${interpreter.WILDCARD}')`);
@@ -1216,7 +1235,7 @@ function stopStep(event, nextState, actorCtx) {
1216
1235
  for (const child of Object.values(nextState.children)) {
1217
1236
  actions.push(stop(child));
1218
1237
  }
1219
- return resolveActionsAndContext(actions, event, nextState, actorCtx);
1238
+ return resolveActionsAndContext(nextState, event, actorCtx, actions);
1220
1239
  }
1221
1240
  function selectTransitions(event, nextState) {
1222
1241
  return nextState.machine.getTransitionData(nextState, event);
@@ -1,4 +1,4 @@
1
- import { r as resolveReferencedActor, d as createActor, f as ActorStatus, k as createErrorActorEvent, l as toStateValue, n as STATE_IDENTIFIER, o as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, q as toStatePath, s as createDoneStateEvent, u as resolveOutput, j as XSTATE_STOP, X as XSTATE_INIT, W as WILDCARD, v as isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-d5fa7ce0.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, X as XSTATE_STOP, u as XSTATE_INIT, W as WILDCARD, v as isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-83f7f2d4.esm.js';
2
2
 
3
3
  const cache = new WeakMap();
4
4
  function memo(object, key, fn) {
@@ -885,31 +885,33 @@ function microstep(transitions, currentState, actorCtx, event, isInitial) {
885
885
  }
886
886
 
887
887
  function microstepProcedure(transitions, currentState, mutConfiguration, event, actorCtx, isInitial) {
888
- const actions = [];
889
888
  const historyValue = {
890
889
  ...currentState.historyValue
891
890
  };
892
891
  const filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
893
892
  const internalQueue = [...currentState._internalQueue];
893
+ // TODO: this `cloneState` is really just a hack to prevent infinite loops
894
+ // we need to take another look at how internal queue is managed
895
+ let nextState = cloneState(currentState, {
896
+ _internalQueue: []
897
+ });
894
898
 
895
899
  // Exit states
896
900
  if (!isInitial) {
897
- exitStates(filteredTransitions, mutConfiguration, historyValue, actions);
901
+ nextState = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue);
898
902
  }
899
903
 
900
904
  // Execute transition content
901
- actions.push(...filteredTransitions.flatMap(t => t.actions));
905
+ nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions));
902
906
 
903
907
  // Enter states
904
- enterStates(event, filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue, isInitial, actorCtx);
908
+ nextState = enterStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
905
909
  const nextConfiguration = [...mutConfiguration];
906
910
  const done = isInFinalState(nextConfiguration);
907
911
  if (done) {
908
- const finalActions = nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit);
909
- actions.push(...finalActions);
912
+ nextState = resolveActionsAndContext(nextState, event, actorCtx, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit));
910
913
  }
911
914
  try {
912
- const nextState = resolveActionsAndContext(actions, event, currentState, actorCtx);
913
915
  const output = done ? getOutput(nextConfiguration, nextState.context, event, actorCtx.self) : undefined;
914
916
  internalQueue.push(...nextState._internalQueue);
915
917
  return cloneState(currentState, {
@@ -927,7 +929,8 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
927
929
  throw e;
928
930
  }
929
931
  }
930
- function enterStates(event, filteredTransitions, mutConfiguration, actions, internalQueue, currentState, historyValue, isInitial, actorContext) {
932
+ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
933
+ let nextState = currentState;
931
934
  const statesToEnter = new Set();
932
935
  const statesForDefaultEntry = new Set();
933
936
  computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
@@ -938,24 +941,26 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
938
941
  }
939
942
  for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
940
943
  mutConfiguration.add(stateNodeToEnter);
941
- for (const invokeDef of stateNodeToEnter.invoke) {
942
- actions.push(invoke(invokeDef));
943
- }
944
+ const actions = [];
944
945
 
945
946
  // Add entry actions
946
947
  actions.push(...stateNodeToEnter.entry);
948
+ for (const invokeDef of stateNodeToEnter.invoke) {
949
+ actions.push(invoke(invokeDef));
950
+ }
947
951
  if (statesForDefaultEntry.has(stateNodeToEnter)) {
948
952
  for (const stateNode of statesForDefaultEntry) {
949
953
  const initialActions = stateNode.initial.actions;
950
954
  actions.push(...initialActions);
951
955
  }
952
956
  }
957
+ nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
953
958
  if (stateNodeToEnter.type === 'final') {
954
959
  const parent = stateNodeToEnter.parent;
955
960
  if (!parent.parent) {
956
961
  continue;
957
962
  }
958
- internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, currentState.context, event, actorContext.self) : undefined));
963
+ internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
959
964
  if (parent.parent) {
960
965
  const grandparent = parent.parent;
961
966
  if (grandparent.type === 'parallel') {
@@ -966,6 +971,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
966
971
  }
967
972
  }
968
973
  }
974
+ return nextState;
969
975
  }
970
976
  function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
971
977
  for (const t of transitions) {
@@ -1039,7 +1045,8 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
1039
1045
  }
1040
1046
  }
1041
1047
  }
1042
- function exitStates(transitions, mutConfiguration, historyValue, actions) {
1048
+ function exitStates(currentState, event, actorCtx, transitions, mutConfiguration, historyValue) {
1049
+ let nextState = currentState;
1043
1050
  const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
1044
1051
  statesToExit.sort((a, b) => b.order - a.order);
1045
1052
 
@@ -1058,27 +1065,24 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
1058
1065
  }
1059
1066
  }
1060
1067
  for (const s of statesToExit) {
1061
- actions.push(...s.exit, ...s.invoke.map(def => stop(def.id)));
1068
+ nextState = resolveActionsAndContext(nextState, event, actorCtx, [...s.exit, ...s.invoke.map(def => stop(def.id))]);
1062
1069
  mutConfiguration.delete(s);
1063
1070
  }
1071
+ return nextState;
1064
1072
  }
1065
- function resolveActionsAndContext(actions, event, currentState, actorCtx) {
1073
+ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
1066
1074
  const {
1067
1075
  machine
1068
1076
  } = currentState;
1069
- // TODO: this `cloneState` is really just a hack to prevent infinite loops
1070
- // we need to take another look at how internal queue is managed
1071
- let intermediateState = cloneState(currentState, {
1072
- _internalQueue: []
1073
- });
1077
+ let intermediateState = currentState;
1074
1078
  for (const action of actions) {
1075
1079
  const isInline = typeof action === 'function';
1076
- const resolved = isInline ? action :
1080
+ const resolvedAction = isInline ? action :
1077
1081
  // the existing type of `.actions` assumes non-nullable `TExpressionAction`
1078
1082
  // it's fine to cast this here to get a common type and lack of errors in the rest of the code
1079
1083
  // our logic below makes sure that we call those 2 "variants" correctly
1080
1084
  machine.implementations.actions[typeof action === 'string' ? action : action.type];
1081
- if (!resolved) {
1085
+ if (!resolvedAction) {
1082
1086
  continue;
1083
1087
  }
1084
1088
  const actionArgs = {
@@ -1098,20 +1102,25 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
1098
1102
  // TS isn't able to narrow it down here
1099
1103
  action
1100
1104
  };
1101
- if (!('resolve' in resolved)) {
1105
+ if (!('resolve' in resolvedAction)) {
1102
1106
  if (actorCtx?.self.status === ActorStatus.Running) {
1103
- resolved(actionArgs);
1107
+ resolvedAction(actionArgs);
1104
1108
  } else {
1105
- actorCtx?.defer(() => resolved(actionArgs));
1109
+ actorCtx?.defer(() => {
1110
+ resolvedAction(actionArgs);
1111
+ });
1106
1112
  }
1107
1113
  continue;
1108
1114
  }
1109
- const builtinAction = resolved;
1110
- const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolved // this holds all params
1111
- );
1112
-
1115
+ const builtinAction = resolvedAction;
1116
+ const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction,
1117
+ // this holds all params
1118
+ extra);
1113
1119
  intermediateState = nextState;
1114
- if ('execute' in resolved) {
1120
+ if ('retryResolve' in builtinAction) {
1121
+ retries?.push([builtinAction, params]);
1122
+ }
1123
+ if ('execute' in builtinAction) {
1115
1124
  if (actorCtx?.self.status === ActorStatus.Running) {
1116
1125
  builtinAction.execute(actorCtx, params);
1117
1126
  } else {
@@ -1119,11 +1128,21 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
1119
1128
  }
1120
1129
  }
1121
1130
  if (actions) {
1122
- intermediateState = resolveActionsAndContext(actions, event, intermediateState, actorCtx);
1131
+ intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
1123
1132
  }
1124
1133
  }
1125
1134
  return intermediateState;
1126
1135
  }
1136
+ function resolveActionsAndContext(currentState, event, actorCtx, actions, deferredActorIds) {
1137
+ const retries = deferredActorIds ? [] : undefined;
1138
+ const nextState = resolveActionsAndContextWorker(currentState, event, actorCtx, actions, deferredActorIds && {
1139
+ deferredActorIds
1140
+ }, retries);
1141
+ retries?.forEach(([builtinAction, params]) => {
1142
+ builtinAction.retryResolve(actorCtx, nextState, params);
1143
+ });
1144
+ return nextState;
1145
+ }
1127
1146
  function macrostep(state, event, actorCtx) {
1128
1147
  let nextState = state;
1129
1148
  const states = [];
@@ -1180,7 +1199,7 @@ function stopStep(event, nextState, actorCtx) {
1180
1199
  for (const child of Object.values(nextState.children)) {
1181
1200
  actions.push(stop(child));
1182
1201
  }
1183
- return resolveActionsAndContext(actions, event, nextState, actorCtx);
1202
+ return resolveActionsAndContext(nextState, event, actorCtx, actions);
1184
1203
  }
1185
1204
  function selectTransitions(event, nextState) {
1186
1205
  return nextState.machine.getTransitionData(nextState, event);
@@ -1,5 +1,5 @@
1
- import { j as cloneState, e as evaluateGuard } from './raise-6a68d0cc.esm.js';
2
- import { f as ActorStatus, k as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-d5fa7ce0.esm.js';
1
+ import { j as cloneState, e as evaluateGuard } from './raise-b5cfe1bb.esm.js';
2
+ import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-83f7f2d4.esm.js';
3
3
 
4
4
  function createSpawner(actorContext, {
5
5
  machine,
@@ -256,7 +256,7 @@ function resolveSendTo(actorContext, state, args, {
256
256
  event: eventOrExpr,
257
257
  id,
258
258
  delay
259
- }) {
259
+ }, extra) {
260
260
  const delaysMap = state.machine.implementations.delays;
261
261
  if (typeof eventOrExpr === 'string') {
262
262
  throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
@@ -281,7 +281,7 @@ function resolveSendTo(actorContext, state, args, {
281
281
  // #_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.
282
282
  targetActorRef = state.children[resolvedTarget.slice(2)];
283
283
  } else {
284
- targetActorRef = state.children[resolvedTarget];
284
+ targetActorRef = extra?.deferredActorIds.includes(resolvedTarget) ? resolvedTarget : state.children[resolvedTarget];
285
285
  }
286
286
  if (!targetActorRef) {
287
287
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
@@ -296,17 +296,22 @@ function resolveSendTo(actorContext, state, args, {
296
296
  delay: resolvedDelay
297
297
  }];
298
298
  }
299
+ function retryResolveSendTo(_, state, params) {
300
+ if (typeof params.to === 'string') {
301
+ params.to = state.children[params.to];
302
+ }
303
+ }
299
304
  function executeSendTo(actorContext, params) {
300
305
  if (typeof params.delay === 'number') {
301
306
  actorContext.self.delaySend(params);
302
307
  return;
303
308
  }
304
- const {
305
- to,
306
- event
307
- } = params;
308
309
  actorContext.defer(() => {
309
- to.send(event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
310
+ const {
311
+ to,
312
+ event
313
+ } = params;
314
+ actorContext?.system._relay(actorContext.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
310
315
  });
311
316
  }
312
317
  /**
@@ -327,6 +332,7 @@ function sendTo(to, eventOrExpr, options) {
327
332
  sendTo.id = options?.id;
328
333
  sendTo.delay = options?.delay;
329
334
  sendTo.resolve = resolveSendTo;
335
+ sendTo.retryResolve = retryResolveSendTo;
330
336
  sendTo.execute = executeSendTo;
331
337
  return sendTo;
332
338
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-b4bfe138.development.cjs.js');
4
- var interpreter = require('./interpreter-a2236840.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-38b707c0.development.cjs.js');
4
+ var interpreter = require('./interpreter-70ed62f2.development.cjs.js');
5
5
 
6
6
  function createSpawner(actorContext, {
7
7
  machine,
@@ -270,7 +270,7 @@ function resolveSendTo(actorContext, state, args, {
270
270
  event: eventOrExpr,
271
271
  id,
272
272
  delay
273
- }) {
273
+ }, extra) {
274
274
  const delaysMap = state.machine.implementations.delays;
275
275
  if (typeof eventOrExpr === 'string') {
276
276
  throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
@@ -295,7 +295,7 @@ function resolveSendTo(actorContext, state, args, {
295
295
  // #_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.
296
296
  targetActorRef = state.children[resolvedTarget.slice(2)];
297
297
  } else {
298
- targetActorRef = state.children[resolvedTarget];
298
+ targetActorRef = extra?.deferredActorIds.includes(resolvedTarget) ? resolvedTarget : state.children[resolvedTarget];
299
299
  }
300
300
  if (!targetActorRef) {
301
301
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
@@ -310,17 +310,22 @@ function resolveSendTo(actorContext, state, args, {
310
310
  delay: resolvedDelay
311
311
  }];
312
312
  }
313
+ function retryResolveSendTo(_, state, params) {
314
+ if (typeof params.to === 'string') {
315
+ params.to = state.children[params.to];
316
+ }
317
+ }
313
318
  function executeSendTo(actorContext, params) {
314
319
  if (typeof params.delay === 'number') {
315
320
  actorContext.self.delaySend(params);
316
321
  return;
317
322
  }
318
- const {
319
- to,
320
- event
321
- } = params;
322
323
  actorContext.defer(() => {
323
- to.send(event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
324
+ const {
325
+ to,
326
+ event
327
+ } = params;
328
+ actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
324
329
  });
325
330
  }
326
331
  /**
@@ -344,6 +349,7 @@ function sendTo(to, eventOrExpr, options) {
344
349
  sendTo.id = options?.id;
345
350
  sendTo.delay = options?.delay;
346
351
  sendTo.resolve = resolveSendTo;
352
+ sendTo.retryResolve = retryResolveSendTo;
347
353
  sendTo.execute = executeSendTo;
348
354
  return sendTo;
349
355
  }
@@ -1,5 +1,5 @@
1
- import { j as cloneState, e as evaluateGuard } from './raise-6fbd4513.development.esm.js';
2
- import { f as ActorStatus, k as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-e4d2487f.development.esm.js';
1
+ import { j as cloneState, e as evaluateGuard } from './raise-05f8b2a6.development.esm.js';
2
+ import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, y as XSTATE_ERROR } from './interpreter-dee56dc8.development.esm.js';
3
3
 
4
4
  function createSpawner(actorContext, {
5
5
  machine,
@@ -268,7 +268,7 @@ function resolveSendTo(actorContext, state, args, {
268
268
  event: eventOrExpr,
269
269
  id,
270
270
  delay
271
- }) {
271
+ }, extra) {
272
272
  const delaysMap = state.machine.implementations.delays;
273
273
  if (typeof eventOrExpr === 'string') {
274
274
  throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
@@ -293,7 +293,7 @@ function resolveSendTo(actorContext, state, args, {
293
293
  // #_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.
294
294
  targetActorRef = state.children[resolvedTarget.slice(2)];
295
295
  } else {
296
- targetActorRef = state.children[resolvedTarget];
296
+ targetActorRef = extra?.deferredActorIds.includes(resolvedTarget) ? resolvedTarget : state.children[resolvedTarget];
297
297
  }
298
298
  if (!targetActorRef) {
299
299
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
@@ -308,17 +308,22 @@ function resolveSendTo(actorContext, state, args, {
308
308
  delay: resolvedDelay
309
309
  }];
310
310
  }
311
+ function retryResolveSendTo(_, state, params) {
312
+ if (typeof params.to === 'string') {
313
+ params.to = state.children[params.to];
314
+ }
315
+ }
311
316
  function executeSendTo(actorContext, params) {
312
317
  if (typeof params.delay === 'number') {
313
318
  actorContext.self.delaySend(params);
314
319
  return;
315
320
  }
316
- const {
317
- to,
318
- event
319
- } = params;
320
321
  actorContext.defer(() => {
321
- to.send(event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
322
+ const {
323
+ to,
324
+ event
325
+ } = params;
326
+ actorContext?.system._relay(actorContext.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
322
327
  });
323
328
  }
324
329
  /**
@@ -342,6 +347,7 @@ function sendTo(to, eventOrExpr, options) {
342
347
  sendTo.id = options?.id;
343
348
  sendTo.delay = options?.delay;
344
349
  sendTo.resolve = resolveSendTo;
350
+ sendTo.retryResolve = retryResolveSendTo;
345
351
  sendTo.execute = executeSendTo;
346
352
  return sendTo;
347
353
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-90808d65.cjs.js');
4
- var interpreter = require('./interpreter-05e11c15.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-1dd65455.cjs.js');
4
+ var interpreter = require('./interpreter-1301970f.cjs.js');
5
5
 
6
6
  function createSpawner(actorContext, {
7
7
  machine,
@@ -258,7 +258,7 @@ function resolveSendTo(actorContext, state, args, {
258
258
  event: eventOrExpr,
259
259
  id,
260
260
  delay
261
- }) {
261
+ }, extra) {
262
262
  const delaysMap = state.machine.implementations.delays;
263
263
  if (typeof eventOrExpr === 'string') {
264
264
  throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
@@ -283,7 +283,7 @@ function resolveSendTo(actorContext, state, args, {
283
283
  // #_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.
284
284
  targetActorRef = state.children[resolvedTarget.slice(2)];
285
285
  } else {
286
- targetActorRef = state.children[resolvedTarget];
286
+ targetActorRef = extra?.deferredActorIds.includes(resolvedTarget) ? resolvedTarget : state.children[resolvedTarget];
287
287
  }
288
288
  if (!targetActorRef) {
289
289
  throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
@@ -298,17 +298,22 @@ function resolveSendTo(actorContext, state, args, {
298
298
  delay: resolvedDelay
299
299
  }];
300
300
  }
301
+ function retryResolveSendTo(_, state, params) {
302
+ if (typeof params.to === 'string') {
303
+ params.to = state.children[params.to];
304
+ }
305
+ }
301
306
  function executeSendTo(actorContext, params) {
302
307
  if (typeof params.delay === 'number') {
303
308
  actorContext.self.delaySend(params);
304
309
  return;
305
310
  }
306
- const {
307
- to,
308
- event
309
- } = params;
310
311
  actorContext.defer(() => {
311
- to.send(event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
312
+ const {
313
+ to,
314
+ event
315
+ } = params;
316
+ actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
312
317
  });
313
318
  }
314
319
  /**
@@ -329,6 +334,7 @@ function sendTo(to, eventOrExpr, options) {
329
334
  sendTo.id = options?.id;
330
335
  sendTo.delay = options?.delay;
331
336
  sendTo.resolve = resolveSendTo;
337
+ sendTo.retryResolve = retryResolveSendTo;
332
338
  sendTo.execute = executeSendTo;
333
339
  return sendTo;
334
340
  }