xstate 5.0.0-beta.33 → 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.
- package/actions/dist/xstate-actions.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +3 -3
- package/actors/dist/xstate-actors.development.cjs.js +3 -3
- package/actors/dist/xstate-actors.development.esm.js +3 -3
- package/actors/dist/xstate-actors.esm.js +3 -3
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/interpreter.d.ts +1 -1
- package/dist/declarations/src/stateUtils.d.ts +2 -2
- package/dist/{interpreter-054e9fb7.cjs.js → interpreter-1301970f.cjs.js} +8 -8
- package/dist/{interpreter-0c630f66.development.cjs.js → interpreter-70ed62f2.development.cjs.js} +8 -8
- package/dist/{interpreter-03737810.esm.js → interpreter-83f7f2d4.esm.js} +9 -9
- package/dist/{interpreter-825f3d6e.development.esm.js → interpreter-dee56dc8.development.esm.js} +9 -9
- package/dist/{raise-46f122aa.development.esm.js → raise-05f8b2a6.development.esm.js} +44 -27
- package/dist/{raise-987c242e.cjs.js → raise-1dd65455.cjs.js} +44 -27
- package/dist/{raise-4c6a5a96.development.cjs.js → raise-38b707c0.development.cjs.js} +44 -27
- package/dist/{raise-2d92eae8.esm.js → raise-b5cfe1bb.esm.js} +44 -27
- package/dist/{send-0edee2b4.esm.js → send-0b5eda0c.esm.js} +14 -8
- package/dist/{send-0e8675c8.development.cjs.js → send-3764c866.development.cjs.js} +14 -8
- package/dist/{send-4d5b92dc.development.esm.js → send-9526366e.development.esm.js} +14 -8
- package/dist/{send-bd1bd0e3.cjs.js → send-fe94de2b.cjs.js} +14 -8
- package/dist/xstate.cjs.js +5 -5
- package/dist/xstate.development.cjs.js +5 -5
- package/dist/xstate.development.esm.js +8 -8
- package/dist/xstate.esm.js +8 -8
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, f as ActorStatus,
|
|
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
|
|
901
|
+
nextState = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue);
|
|
898
902
|
}
|
|
899
903
|
|
|
900
904
|
// Execute transition content
|
|
901
|
-
|
|
905
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions));
|
|
902
906
|
|
|
903
907
|
// Enter states
|
|
904
|
-
enterStates(event, filteredTransitions, mutConfiguration,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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,
|
|
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
|
|
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,19 +1065,16 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
|
|
|
1058
1065
|
}
|
|
1059
1066
|
}
|
|
1060
1067
|
for (const s of statesToExit) {
|
|
1061
|
-
|
|
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
|
|
1073
|
+
function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
|
|
1066
1074
|
const {
|
|
1067
1075
|
machine
|
|
1068
1076
|
} = currentState;
|
|
1069
|
-
|
|
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
1080
|
const resolvedAction = isInline ? action :
|
|
@@ -1109,11 +1113,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1109
1113
|
continue;
|
|
1110
1114
|
}
|
|
1111
1115
|
const builtinAction = resolvedAction;
|
|
1112
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction
|
|
1113
|
-
|
|
1114
|
-
|
|
1116
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction,
|
|
1117
|
+
// this holds all params
|
|
1118
|
+
extra);
|
|
1115
1119
|
intermediateState = nextState;
|
|
1116
|
-
if ('
|
|
1120
|
+
if ('retryResolve' in builtinAction) {
|
|
1121
|
+
retries?.push([builtinAction, params]);
|
|
1122
|
+
}
|
|
1123
|
+
if ('execute' in builtinAction) {
|
|
1117
1124
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
1118
1125
|
builtinAction.execute(actorCtx, params);
|
|
1119
1126
|
} else {
|
|
@@ -1121,11 +1128,21 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1121
1128
|
}
|
|
1122
1129
|
}
|
|
1123
1130
|
if (actions) {
|
|
1124
|
-
intermediateState =
|
|
1131
|
+
intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
|
|
1125
1132
|
}
|
|
1126
1133
|
}
|
|
1127
1134
|
return intermediateState;
|
|
1128
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
|
+
}
|
|
1129
1146
|
function macrostep(state, event, actorCtx) {
|
|
1130
1147
|
let nextState = state;
|
|
1131
1148
|
const states = [];
|
|
@@ -1182,7 +1199,7 @@ function stopStep(event, nextState, actorCtx) {
|
|
|
1182
1199
|
for (const child of Object.values(nextState.children)) {
|
|
1183
1200
|
actions.push(stop(child));
|
|
1184
1201
|
}
|
|
1185
|
-
return resolveActionsAndContext(
|
|
1202
|
+
return resolveActionsAndContext(nextState, event, actorCtx, actions);
|
|
1186
1203
|
}
|
|
1187
1204
|
function selectTransitions(event, nextState) {
|
|
1188
1205
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { j as cloneState, e as evaluateGuard } from './raise-
|
|
2
|
-
import { f as ActorStatus,
|
|
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,16 +296,21 @@ 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(() => {
|
|
310
|
+
const {
|
|
311
|
+
to,
|
|
312
|
+
event
|
|
313
|
+
} = params;
|
|
309
314
|
actorContext?.system._relay(actorContext.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
310
315
|
});
|
|
311
316
|
}
|
|
@@ -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-
|
|
4
|
-
var interpreter = require('./interpreter-
|
|
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,16 +310,21 @@ 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(() => {
|
|
324
|
+
const {
|
|
325
|
+
to,
|
|
326
|
+
event
|
|
327
|
+
} = params;
|
|
323
328
|
actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
324
329
|
});
|
|
325
330
|
}
|
|
@@ -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-
|
|
2
|
-
import { f as ActorStatus,
|
|
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,16 +308,21 @@ 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(() => {
|
|
322
|
+
const {
|
|
323
|
+
to,
|
|
324
|
+
event
|
|
325
|
+
} = params;
|
|
321
326
|
actorContext?.system._relay(actorContext.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
322
327
|
});
|
|
323
328
|
}
|
|
@@ -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-
|
|
4
|
-
var interpreter = require('./interpreter-
|
|
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,16 +298,21 @@ 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(() => {
|
|
312
|
+
const {
|
|
313
|
+
to,
|
|
314
|
+
event
|
|
315
|
+
} = params;
|
|
311
316
|
actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
312
317
|
});
|
|
313
318
|
}
|
|
@@ -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
|
}
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
|
|
6
|
-
var interpreter = require('./interpreter-
|
|
7
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
8
|
-
var send = require('./send-
|
|
6
|
+
var interpreter = require('./interpreter-1301970f.cjs.js');
|
|
7
|
+
var guards_dist_xstateGuards = require('./raise-1dd65455.cjs.js');
|
|
8
|
+
var send = require('./send-fe94de2b.cjs.js');
|
|
9
9
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
10
10
|
|
|
11
11
|
class SimulatedClock {
|
|
@@ -539,7 +539,7 @@ class StateMachine {
|
|
|
539
539
|
spawn,
|
|
540
540
|
input: event.input
|
|
541
541
|
});
|
|
542
|
-
return guards_dist_xstateGuards.resolveActionsAndContext([send.assign(assignment)]
|
|
542
|
+
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorCtx, [send.assign(assignment)]);
|
|
543
543
|
}
|
|
544
544
|
return preInitial;
|
|
545
545
|
}
|
|
@@ -567,7 +567,7 @@ class StateMachine {
|
|
|
567
567
|
start(state) {
|
|
568
568
|
Object.values(state.children).forEach(child => {
|
|
569
569
|
if (child.status === 0) {
|
|
570
|
-
child.start
|
|
570
|
+
child.start();
|
|
571
571
|
}
|
|
572
572
|
});
|
|
573
573
|
}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
|
|
6
|
-
var interpreter = require('./interpreter-
|
|
7
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
8
|
-
var send = require('./send-
|
|
6
|
+
var interpreter = require('./interpreter-70ed62f2.development.cjs.js');
|
|
7
|
+
var guards_dist_xstateGuards = require('./raise-38b707c0.development.cjs.js');
|
|
8
|
+
var send = require('./send-3764c866.development.cjs.js');
|
|
9
9
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
10
10
|
|
|
11
11
|
class SimulatedClock {
|
|
@@ -542,7 +542,7 @@ class StateMachine {
|
|
|
542
542
|
spawn,
|
|
543
543
|
input: event.input
|
|
544
544
|
});
|
|
545
|
-
return guards_dist_xstateGuards.resolveActionsAndContext([send.assign(assignment)]
|
|
545
|
+
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorCtx, [send.assign(assignment)]);
|
|
546
546
|
}
|
|
547
547
|
return preInitial;
|
|
548
548
|
}
|
|
@@ -570,7 +570,7 @@ class StateMachine {
|
|
|
570
570
|
start(state) {
|
|
571
571
|
Object.values(state.children).forEach(child => {
|
|
572
572
|
if (child.status === 0) {
|
|
573
|
-
child.start
|
|
573
|
+
child.start();
|
|
574
574
|
}
|
|
575
575
|
});
|
|
576
576
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-
|
|
3
|
-
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-
|
|
4
|
-
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-
|
|
5
|
-
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-
|
|
6
|
-
import { a as assign } from './send-
|
|
7
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-dee56dc8.development.esm.js';
|
|
3
|
+
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-dee56dc8.development.esm.js';
|
|
4
|
+
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-05f8b2a6.development.esm.js';
|
|
5
|
+
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-05f8b2a6.development.esm.js';
|
|
6
|
+
import { a as assign } from './send-9526366e.development.esm.js';
|
|
7
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-9526366e.development.esm.js';
|
|
8
8
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -541,7 +541,7 @@ class StateMachine {
|
|
|
541
541
|
spawn,
|
|
542
542
|
input: event.input
|
|
543
543
|
});
|
|
544
|
-
return resolveActionsAndContext(
|
|
544
|
+
return resolveActionsAndContext(preInitial, initEvent, actorCtx, [assign(assignment)]);
|
|
545
545
|
}
|
|
546
546
|
return preInitial;
|
|
547
547
|
}
|
|
@@ -569,7 +569,7 @@ class StateMachine {
|
|
|
569
569
|
start(state) {
|
|
570
570
|
Object.values(state.children).forEach(child => {
|
|
571
571
|
if (child.status === 0) {
|
|
572
|
-
child.start
|
|
572
|
+
child.start();
|
|
573
573
|
}
|
|
574
574
|
});
|
|
575
575
|
}
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
|
|
2
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-
|
|
3
|
-
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-
|
|
4
|
-
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-
|
|
5
|
-
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-
|
|
6
|
-
import { a as assign } from './send-
|
|
7
|
-
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-83f7f2d4.esm.js';
|
|
3
|
+
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-83f7f2d4.esm.js';
|
|
4
|
+
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-b5cfe1bb.esm.js';
|
|
5
|
+
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-b5cfe1bb.esm.js';
|
|
6
|
+
import { a as assign } from './send-0b5eda0c.esm.js';
|
|
7
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-0b5eda0c.esm.js';
|
|
8
8
|
import '../dev/dist/xstate-dev.esm.js';
|
|
9
9
|
|
|
10
10
|
class SimulatedClock {
|
|
@@ -538,7 +538,7 @@ class StateMachine {
|
|
|
538
538
|
spawn,
|
|
539
539
|
input: event.input
|
|
540
540
|
});
|
|
541
|
-
return resolveActionsAndContext(
|
|
541
|
+
return resolveActionsAndContext(preInitial, initEvent, actorCtx, [assign(assignment)]);
|
|
542
542
|
}
|
|
543
543
|
return preInitial;
|
|
544
544
|
}
|
|
@@ -566,7 +566,7 @@ class StateMachine {
|
|
|
566
566
|
start(state) {
|
|
567
567
|
Object.values(state.children).forEach(child => {
|
|
568
568
|
if (child.status === 0) {
|
|
569
|
-
child.start
|
|
569
|
+
child.start();
|
|
570
570
|
}
|
|
571
571
|
});
|
|
572
572
|
}
|