xstate 5.18.1 → 5.19.0
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.d.mts +1 -1
- package/actions/dist/xstate-actions.cjs.d.ts +1 -1
- package/actions/dist/xstate-actions.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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.d.mts +1 -1
- package/actors/dist/xstate-actors.cjs.d.ts +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +1 -1
- package/dev/dist/xstate-dev.cjs.d.ts +1 -1
- package/dev/dist/xstate-dev.cjs.js +1 -1
- package/dev/dist/xstate-dev.development.cjs.js +1 -1
- package/dev/dist/xstate-dev.development.esm.js +1 -1
- package/dev/dist/xstate-dev.esm.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/actions/raise.d.ts +9 -1
- package/dist/declarations/src/actions/send.d.ts +10 -1
- package/dist/declarations/src/createActor.d.ts +2 -1
- package/dist/declarations/src/getNextSnapshot.d.ts +2 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/inspection.d.ts +3 -3
- package/dist/declarations/src/stateUtils.d.ts +17 -7
- package/dist/declarations/src/transition.d.ts +16 -0
- package/dist/declarations/src/types.d.ts +47 -14
- package/dist/declarations/src/utils.d.ts +1 -1
- package/dist/{log-d26be77d.development.cjs.js → log-17337367.development.cjs.js} +29 -19
- package/dist/{log-a2c94240.esm.js → log-2a773d37.esm.js} +28 -15
- package/dist/{log-098d2ed5.cjs.js → log-b0ee96de.cjs.js} +28 -15
- package/dist/{log-c92a07bc.development.esm.js → log-ef30c65f.development.esm.js} +29 -19
- package/dist/{raise-206d3d29.development.esm.js → raise-1db27a82.development.esm.js} +98 -73
- package/dist/{raise-830a98f7.development.cjs.js → raise-4acdb210.development.cjs.js} +98 -73
- package/dist/{raise-cde45f56.cjs.js → raise-60cebf03.cjs.js} +94 -71
- package/dist/{raise-c0e3c984.esm.js → raise-c17ec2bc.esm.js} +94 -71
- package/dist/xstate.cjs.d.mts +1 -1
- package/dist/xstate.cjs.d.ts +1 -1
- package/dist/xstate.cjs.js +60 -16
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +60 -16
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +61 -19
- package/dist/xstate.esm.js +61 -19
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +1 -1
- package/guards/dist/xstate-guards.cjs.d.ts +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +7 -7
- package/actions/dist/xstate-actions.cjs.d.mts.map +0 -1
- package/actions/dist/xstate-actions.cjs.d.ts.map +0 -1
- package/actors/dist/xstate-actors.cjs.d.mts.map +0 -1
- package/actors/dist/xstate-actors.cjs.d.ts.map +0 -1
- package/dev/dist/xstate-dev.cjs.d.mts.map +0 -1
- package/dev/dist/xstate-dev.cjs.d.ts.map +0 -1
- package/dist/xstate.cjs.d.mts.map +0 -1
- package/dist/xstate.cjs.d.ts.map +0 -1
- package/guards/dist/xstate-guards.cjs.d.mts.map +0 -1
- package/guards/dist/xstate-guards.cjs.d.ts.map +0 -1
|
@@ -156,7 +156,7 @@ function toStatePath(stateId) {
|
|
|
156
156
|
if (isArray(stateId)) {
|
|
157
157
|
return stateId;
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
const result = [];
|
|
160
160
|
let segment = '';
|
|
161
161
|
for (let i = 0; i < stateId.length; i++) {
|
|
162
162
|
const char = stateId.charCodeAt(i);
|
|
@@ -421,6 +421,7 @@ function createSystem(rootActor, options) {
|
|
|
421
421
|
return system;
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
+
let executingCustomAction = false;
|
|
424
425
|
const $$ACTOR_TYPE = 1;
|
|
425
426
|
|
|
426
427
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
@@ -541,10 +542,37 @@ class Actor {
|
|
|
541
542
|
if (!listeners && !wildcardListener) {
|
|
542
543
|
return;
|
|
543
544
|
}
|
|
544
|
-
const allListeners =
|
|
545
|
-
for (const handler of
|
|
545
|
+
const allListeners = [...(listeners ? listeners.values() : []), ...(wildcardListener ? wildcardListener.values() : [])];
|
|
546
|
+
for (const handler of allListeners) {
|
|
546
547
|
handler(emittedEvent);
|
|
547
548
|
}
|
|
549
|
+
},
|
|
550
|
+
actionExecutor: action => {
|
|
551
|
+
const exec = () => {
|
|
552
|
+
this._actorScope.system._sendInspectionEvent({
|
|
553
|
+
type: '@xstate.action',
|
|
554
|
+
actorRef: this,
|
|
555
|
+
action: {
|
|
556
|
+
type: action.type,
|
|
557
|
+
params: action.params
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
if (!action.exec) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const saveExecutingCustomAction = executingCustomAction;
|
|
564
|
+
try {
|
|
565
|
+
executingCustomAction = true;
|
|
566
|
+
action.exec(action.info, action.params);
|
|
567
|
+
} finally {
|
|
568
|
+
executingCustomAction = saveExecutingCustomAction;
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
572
|
+
exec();
|
|
573
|
+
} else {
|
|
574
|
+
this._deferred.push(exec);
|
|
575
|
+
}
|
|
548
576
|
}
|
|
549
577
|
};
|
|
550
578
|
|
|
@@ -1073,11 +1101,13 @@ function resolveCancel(_, snapshot, actionArgs, actionParams, {
|
|
|
1073
1101
|
sendId
|
|
1074
1102
|
}) {
|
|
1075
1103
|
const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
|
|
1076
|
-
return [snapshot,
|
|
1104
|
+
return [snapshot, {
|
|
1105
|
+
sendId: resolvedSendId
|
|
1106
|
+
}, undefined];
|
|
1077
1107
|
}
|
|
1078
|
-
function executeCancel(actorScope,
|
|
1108
|
+
function executeCancel(actorScope, params) {
|
|
1079
1109
|
actorScope.defer(() => {
|
|
1080
|
-
actorScope.system.scheduler.cancel(actorScope.self,
|
|
1110
|
+
actorScope.system.scheduler.cancel(actorScope.self, params.sendId);
|
|
1081
1111
|
});
|
|
1082
1112
|
}
|
|
1083
1113
|
/**
|
|
@@ -1113,7 +1143,7 @@ function executeCancel(actorScope, resolvedSendId) {
|
|
|
1113
1143
|
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
1114
1144
|
*/
|
|
1115
1145
|
function cancel(sendId) {
|
|
1116
|
-
function cancel(
|
|
1146
|
+
function cancel(_args, _params) {
|
|
1117
1147
|
}
|
|
1118
1148
|
cancel.type = 'xstate.cancel';
|
|
1119
1149
|
cancel.sendId = sendId;
|
|
@@ -1132,18 +1162,20 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
|
1132
1162
|
const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
|
|
1133
1163
|
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
1134
1164
|
let actorRef;
|
|
1165
|
+
let resolvedInput = undefined;
|
|
1135
1166
|
if (logic) {
|
|
1167
|
+
resolvedInput = typeof input === 'function' ? input({
|
|
1168
|
+
context: snapshot.context,
|
|
1169
|
+
event: actionArgs.event,
|
|
1170
|
+
self: actorScope.self
|
|
1171
|
+
}) : input;
|
|
1136
1172
|
actorRef = createActor(logic, {
|
|
1137
1173
|
id: resolvedId,
|
|
1138
1174
|
src,
|
|
1139
1175
|
parent: actorScope.self,
|
|
1140
1176
|
syncSnapshot,
|
|
1141
1177
|
systemId,
|
|
1142
|
-
input:
|
|
1143
|
-
context: snapshot.context,
|
|
1144
|
-
event: actionArgs.event,
|
|
1145
|
-
self: actorScope.self
|
|
1146
|
-
}) : input
|
|
1178
|
+
input: resolvedInput
|
|
1147
1179
|
});
|
|
1148
1180
|
}
|
|
1149
1181
|
return [cloneMachineSnapshot(snapshot, {
|
|
@@ -1153,11 +1185,13 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
|
1153
1185
|
}
|
|
1154
1186
|
}), {
|
|
1155
1187
|
id,
|
|
1156
|
-
|
|
1157
|
-
|
|
1188
|
+
systemId,
|
|
1189
|
+
actorRef,
|
|
1190
|
+
src,
|
|
1191
|
+
input: resolvedInput
|
|
1192
|
+
}, undefined];
|
|
1158
1193
|
}
|
|
1159
1194
|
function executeSpawn(actorScope, {
|
|
1160
|
-
id,
|
|
1161
1195
|
actorRef
|
|
1162
1196
|
}) {
|
|
1163
1197
|
if (!actorRef) {
|
|
@@ -1176,9 +1210,9 @@ function spawnChild(...[src, {
|
|
|
1176
1210
|
input,
|
|
1177
1211
|
syncSnapshot = false
|
|
1178
1212
|
} = {}]) {
|
|
1179
|
-
function spawnChild(
|
|
1213
|
+
function spawnChild(_args, _params) {
|
|
1180
1214
|
}
|
|
1181
|
-
spawnChild.type = '
|
|
1215
|
+
spawnChild.type = 'xstate.spawnChild';
|
|
1182
1216
|
spawnChild.id = id;
|
|
1183
1217
|
spawnChild.systemId = systemId;
|
|
1184
1218
|
spawnChild.src = src;
|
|
@@ -1203,7 +1237,7 @@ function resolveStop(_, snapshot, args, actionParams, {
|
|
|
1203
1237
|
}
|
|
1204
1238
|
return [cloneMachineSnapshot(snapshot, {
|
|
1205
1239
|
children
|
|
1206
|
-
}), resolvedActorRef];
|
|
1240
|
+
}), resolvedActorRef, undefined];
|
|
1207
1241
|
}
|
|
1208
1242
|
function executeStop(actorScope, actorRef) {
|
|
1209
1243
|
if (!actorRef) {
|
|
@@ -1235,7 +1269,7 @@ function executeStop(actorScope, actorRef) {
|
|
|
1235
1269
|
* @param actorRef The actor to stop.
|
|
1236
1270
|
*/
|
|
1237
1271
|
function stopChild(actorRef) {
|
|
1238
|
-
function stop(
|
|
1272
|
+
function stop(_args, _params) {
|
|
1239
1273
|
}
|
|
1240
1274
|
stop.type = 'xstate.stopChild';
|
|
1241
1275
|
stop.actorRef = actorRef;
|
|
@@ -1262,7 +1296,7 @@ function checkStateIn(snapshot, _, {
|
|
|
1262
1296
|
return snapshot.matches(stateValue);
|
|
1263
1297
|
}
|
|
1264
1298
|
function stateIn(stateValue) {
|
|
1265
|
-
function stateIn(
|
|
1299
|
+
function stateIn() {
|
|
1266
1300
|
return false;
|
|
1267
1301
|
}
|
|
1268
1302
|
stateIn.check = checkStateIn;
|
|
@@ -1308,7 +1342,7 @@ function checkNot(snapshot, {
|
|
|
1308
1342
|
* @returns A guard
|
|
1309
1343
|
*/
|
|
1310
1344
|
function not(guard) {
|
|
1311
|
-
function not(
|
|
1345
|
+
function not(_args, _params) {
|
|
1312
1346
|
return false;
|
|
1313
1347
|
}
|
|
1314
1348
|
not.check = checkNot;
|
|
@@ -1354,7 +1388,7 @@ function checkAnd(snapshot, {
|
|
|
1354
1388
|
* @returns A guard action object
|
|
1355
1389
|
*/
|
|
1356
1390
|
function and(guards) {
|
|
1357
|
-
function and(
|
|
1391
|
+
function and(_args, _params) {
|
|
1358
1392
|
return false;
|
|
1359
1393
|
}
|
|
1360
1394
|
and.check = checkAnd;
|
|
@@ -1400,7 +1434,7 @@ function checkOr(snapshot, {
|
|
|
1400
1434
|
* @returns A guard action object
|
|
1401
1435
|
*/
|
|
1402
1436
|
function or(guards) {
|
|
1403
|
-
function or(
|
|
1437
|
+
function or(_args, _params) {
|
|
1404
1438
|
return false;
|
|
1405
1439
|
}
|
|
1406
1440
|
or.check = checkOr;
|
|
@@ -1499,7 +1533,6 @@ function getValueFromAdj(baseNode, adjList) {
|
|
|
1499
1533
|
if (!childStateNodes) {
|
|
1500
1534
|
return {}; // todo: fix?
|
|
1501
1535
|
}
|
|
1502
|
-
|
|
1503
1536
|
if (baseNode.type === 'compound') {
|
|
1504
1537
|
const childStateNode = childStateNodes[0];
|
|
1505
1538
|
if (childStateNode) {
|
|
@@ -1579,7 +1612,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1579
1612
|
if (!afterConfig) {
|
|
1580
1613
|
return [];
|
|
1581
1614
|
}
|
|
1582
|
-
const mutateEntryExit =
|
|
1615
|
+
const mutateEntryExit = delay => {
|
|
1583
1616
|
const afterEvent = createAfterEvent(delay, stateNode.id);
|
|
1584
1617
|
const eventType = afterEvent.type;
|
|
1585
1618
|
stateNode.entry.push(raise(afterEvent, {
|
|
@@ -1589,7 +1622,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1589
1622
|
stateNode.exit.push(cancel(eventType));
|
|
1590
1623
|
return eventType;
|
|
1591
1624
|
};
|
|
1592
|
-
const delayedTransitions = Object.keys(afterConfig).flatMap(
|
|
1625
|
+
const delayedTransitions = Object.keys(afterConfig).flatMap(delay => {
|
|
1593
1626
|
const configTransition = afterConfig[delay];
|
|
1594
1627
|
const resolvedTransition = typeof configTransition === 'string' ? {
|
|
1595
1628
|
target: configTransition
|
|
@@ -1674,7 +1707,9 @@ function formatTransitions(stateNode) {
|
|
|
1674
1707
|
function formatInitialTransition(stateNode, _target) {
|
|
1675
1708
|
const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
|
|
1676
1709
|
if (!resolvedTarget && _target) {
|
|
1677
|
-
throw new Error(
|
|
1710
|
+
throw new Error(
|
|
1711
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
|
|
1712
|
+
`Initial state node "${_target}" not found on parent state node #${stateNode.id}`);
|
|
1678
1713
|
}
|
|
1679
1714
|
const transition = {
|
|
1680
1715
|
source: stateNode,
|
|
@@ -1784,7 +1819,7 @@ function getStateNodeByPath(stateNode, statePath) {
|
|
|
1784
1819
|
if (typeof statePath === 'string' && isStateId(statePath)) {
|
|
1785
1820
|
try {
|
|
1786
1821
|
return stateNode.machine.getStateNodeById(statePath);
|
|
1787
|
-
} catch
|
|
1822
|
+
} catch {
|
|
1788
1823
|
// try individual paths
|
|
1789
1824
|
// throw e;
|
|
1790
1825
|
}
|
|
@@ -2013,18 +2048,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2013
2048
|
|
|
2014
2049
|
// Exit states
|
|
2015
2050
|
if (!isInitial) {
|
|
2016
|
-
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
|
|
2051
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue, actorScope.actionExecutor);
|
|
2017
2052
|
}
|
|
2018
2053
|
|
|
2019
2054
|
// Execute transition content
|
|
2020
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
2055
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue, undefined);
|
|
2021
2056
|
|
|
2022
2057
|
// Enter states
|
|
2023
2058
|
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
|
|
2024
2059
|
const nextStateNodes = [...mutStateNodeSet];
|
|
2025
2060
|
if (nextState.status === 'done') {
|
|
2026
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
|
|
2061
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue, undefined);
|
|
2027
2062
|
}
|
|
2063
|
+
|
|
2064
|
+
// eslint-disable-next-line no-useless-catch
|
|
2028
2065
|
try {
|
|
2029
2066
|
if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
|
|
2030
2067
|
return nextState;
|
|
@@ -2194,7 +2231,7 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
|
|
|
2194
2231
|
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
2195
2232
|
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
2196
2233
|
}
|
|
2197
|
-
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
|
|
2234
|
+
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue, _actionExecutor) {
|
|
2198
2235
|
let nextSnapshot = currentSnapshot;
|
|
2199
2236
|
const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
|
|
2200
2237
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
@@ -2218,12 +2255,14 @@ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNod
|
|
|
2218
2255
|
}
|
|
2219
2256
|
}
|
|
2220
2257
|
for (const s of statesToExit) {
|
|
2221
|
-
nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
|
|
2258
|
+
nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue, undefined);
|
|
2222
2259
|
mutStateNodeSet.delete(s);
|
|
2223
2260
|
}
|
|
2224
2261
|
return [nextSnapshot, changedHistory || historyValue];
|
|
2225
2262
|
}
|
|
2226
|
-
|
|
2263
|
+
function getAction(machine, actionType) {
|
|
2264
|
+
return machine.implementations.actions[actionType];
|
|
2265
|
+
}
|
|
2227
2266
|
function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
|
|
2228
2267
|
const {
|
|
2229
2268
|
machine
|
|
@@ -2235,10 +2274,8 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2235
2274
|
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2236
2275
|
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2237
2276
|
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
continue;
|
|
2241
|
-
}
|
|
2277
|
+
|
|
2278
|
+
getAction(machine, typeof action === 'string' ? action : action.type);
|
|
2242
2279
|
const actionArgs = {
|
|
2243
2280
|
context: intermediateSnapshot.context,
|
|
2244
2281
|
event,
|
|
@@ -2249,30 +2286,13 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2249
2286
|
context: intermediateSnapshot.context,
|
|
2250
2287
|
event
|
|
2251
2288
|
}) : action.params : undefined;
|
|
2252
|
-
|
|
2253
|
-
actorScope.
|
|
2254
|
-
type: '
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
params: actionParams
|
|
2259
|
-
}
|
|
2289
|
+
if (!resolvedAction || !('resolve' in resolvedAction)) {
|
|
2290
|
+
actorScope.actionExecutor({
|
|
2291
|
+
type: typeof action === 'string' ? action : typeof action === 'object' ? action.type : action.name || '(anonymous)',
|
|
2292
|
+
info: actionArgs,
|
|
2293
|
+
params: actionParams,
|
|
2294
|
+
exec: resolvedAction
|
|
2260
2295
|
});
|
|
2261
|
-
try {
|
|
2262
|
-
executingCustomAction = resolvedAction;
|
|
2263
|
-
resolvedAction(actionArgs, actionParams);
|
|
2264
|
-
} finally {
|
|
2265
|
-
executingCustomAction = false;
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
if (!('resolve' in resolvedAction)) {
|
|
2269
|
-
if (actorScope.self._processingStatus === ProcessingStatus.Running) {
|
|
2270
|
-
executeAction();
|
|
2271
|
-
} else {
|
|
2272
|
-
actorScope.defer(() => {
|
|
2273
|
-
executeAction();
|
|
2274
|
-
});
|
|
2275
|
-
}
|
|
2276
2296
|
continue;
|
|
2277
2297
|
}
|
|
2278
2298
|
const builtinAction = resolvedAction;
|
|
@@ -2284,11 +2304,12 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2284
2304
|
retries?.push([builtinAction, params]);
|
|
2285
2305
|
}
|
|
2286
2306
|
if ('execute' in builtinAction) {
|
|
2287
|
-
|
|
2288
|
-
builtinAction.
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2307
|
+
actorScope.actionExecutor({
|
|
2308
|
+
type: builtinAction.type,
|
|
2309
|
+
info: actionArgs,
|
|
2310
|
+
params,
|
|
2311
|
+
exec: builtinAction.execute.bind(null, actorScope, params)
|
|
2312
|
+
});
|
|
2292
2313
|
}
|
|
2293
2314
|
if (actions) {
|
|
2294
2315
|
intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions, extra, retries);
|
|
@@ -2307,7 +2328,7 @@ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, i
|
|
|
2307
2328
|
});
|
|
2308
2329
|
return nextState;
|
|
2309
2330
|
}
|
|
2310
|
-
function macrostep(snapshot, event, actorScope, internalQueue
|
|
2331
|
+
function macrostep(snapshot, event, actorScope, internalQueue) {
|
|
2311
2332
|
let nextSnapshot = snapshot;
|
|
2312
2333
|
const microstates = [];
|
|
2313
2334
|
function addMicrostate(microstate, event, transitions) {
|
|
@@ -2386,7 +2407,7 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
|
|
|
2386
2407
|
};
|
|
2387
2408
|
}
|
|
2388
2409
|
function stopChildren(nextState, event, actorScope) {
|
|
2389
|
-
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stopChild(child)), []);
|
|
2410
|
+
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stopChild(child)), [], undefined);
|
|
2390
2411
|
}
|
|
2391
2412
|
function selectTransitions(event, nextState) {
|
|
2392
2413
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -2553,7 +2574,9 @@ function resolveRaise(_, snapshot, args, actionParams, {
|
|
|
2553
2574
|
}) {
|
|
2554
2575
|
const delaysMap = snapshot.machine.implementations.delays;
|
|
2555
2576
|
if (typeof eventOrExpr === 'string') {
|
|
2556
|
-
throw new Error(
|
|
2577
|
+
throw new Error(
|
|
2578
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
2579
|
+
`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
|
|
2557
2580
|
}
|
|
2558
2581
|
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
2559
2582
|
let resolvedDelay;
|
|
@@ -2570,7 +2593,7 @@ function resolveRaise(_, snapshot, args, actionParams, {
|
|
|
2570
2593
|
event: resolvedEvent,
|
|
2571
2594
|
id,
|
|
2572
2595
|
delay: resolvedDelay
|
|
2573
|
-
}];
|
|
2596
|
+
}, undefined];
|
|
2574
2597
|
}
|
|
2575
2598
|
function executeRaise(actorScope, params) {
|
|
2576
2599
|
const {
|
|
@@ -2593,7 +2616,7 @@ function executeRaise(actorScope, params) {
|
|
|
2593
2616
|
* @param eventType The event to raise.
|
|
2594
2617
|
*/
|
|
2595
2618
|
function raise(eventOrExpr, options) {
|
|
2596
|
-
function raise(
|
|
2619
|
+
function raise(_args, _params) {
|
|
2597
2620
|
}
|
|
2598
2621
|
raise.type = 'xstate.raise';
|
|
2599
2622
|
raise.event = eventOrExpr;
|