xstate 5.18.2 → 5.19.1
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 +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.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.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 +1 -1
- package/dist/declarations/src/spawn.d.ts +19 -11
- 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 +48 -14
- package/dist/declarations/src/utils.d.ts +1 -1
- package/dist/{log-38475d87.development.esm.js → log-0acd9069.development.esm.js} +32 -33
- package/dist/{log-15d0f775.esm.js → log-3d9d72a9.esm.js} +31 -29
- package/dist/{log-b7ed1b61.development.cjs.js → log-8aa651a0.development.cjs.js} +32 -33
- package/dist/{log-98fcce74.cjs.js → log-a019fbd0.cjs.js} +31 -29
- package/dist/{raise-5ea71f04.development.esm.js → raise-1db27a82.development.esm.js} +98 -72
- package/dist/{raise-e919c5d4.development.cjs.js → raise-4acdb210.development.cjs.js} +98 -72
- package/dist/{raise-b1e0b9a9.cjs.js → raise-60cebf03.cjs.js} +94 -70
- package/dist/{raise-0f7cf128.esm.js → raise-c17ec2bc.esm.js} +94 -70
- package/dist/xstate.cjs.js +57 -15
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +57 -15
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +58 -18
- package/dist/xstate.esm.js +58 -18
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +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 +1 -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);
|
|
@@ -236,7 +236,7 @@ function resolveOutput(mapper, context, event, self) {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
if (!!mapper && typeof mapper === 'object' && Object.values(mapper).some(val => typeof val === 'function')) {
|
|
239
|
-
console.warn(`Dynamically mapping values to individual properties is deprecated. Use a single function that returns the mapped object instead.\nFound object containing properties whose values are possibly mapping functions: ${Object.entries(mapper).filter(([
|
|
239
|
+
console.warn(`Dynamically mapping values to individual properties is deprecated. Use a single function that returns the mapped object instead.\nFound object containing properties whose values are possibly mapping functions: ${Object.entries(mapper).filter(([, value]) => typeof value === 'function').map(([key, value]) => `\n - ${key}: ${value.toString().replace(/\n\s*/g, '')}`).join('')}`);
|
|
240
240
|
}
|
|
241
241
|
return mapper;
|
|
242
242
|
}
|
|
@@ -424,6 +424,7 @@ function createSystem(rootActor, options) {
|
|
|
424
424
|
return system;
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
exports.executingCustomAction = false;
|
|
427
428
|
const $$ACTOR_TYPE = 1;
|
|
428
429
|
|
|
429
430
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
@@ -544,10 +545,37 @@ class Actor {
|
|
|
544
545
|
if (!listeners && !wildcardListener) {
|
|
545
546
|
return;
|
|
546
547
|
}
|
|
547
|
-
const allListeners =
|
|
548
|
-
for (const handler of
|
|
548
|
+
const allListeners = [...(listeners ? listeners.values() : []), ...(wildcardListener ? wildcardListener.values() : [])];
|
|
549
|
+
for (const handler of allListeners) {
|
|
549
550
|
handler(emittedEvent);
|
|
550
551
|
}
|
|
552
|
+
},
|
|
553
|
+
actionExecutor: action => {
|
|
554
|
+
const exec = () => {
|
|
555
|
+
this._actorScope.system._sendInspectionEvent({
|
|
556
|
+
type: '@xstate.action',
|
|
557
|
+
actorRef: this,
|
|
558
|
+
action: {
|
|
559
|
+
type: action.type,
|
|
560
|
+
params: action.params
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
if (!action.exec) {
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const saveExecutingCustomAction = exports.executingCustomAction;
|
|
567
|
+
try {
|
|
568
|
+
exports.executingCustomAction = true;
|
|
569
|
+
action.exec(action.info, action.params);
|
|
570
|
+
} finally {
|
|
571
|
+
exports.executingCustomAction = saveExecutingCustomAction;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
575
|
+
exec();
|
|
576
|
+
} else {
|
|
577
|
+
this._deferred.push(exec);
|
|
578
|
+
}
|
|
551
579
|
}
|
|
552
580
|
};
|
|
553
581
|
|
|
@@ -1087,11 +1115,13 @@ function resolveCancel(_, snapshot, actionArgs, actionParams, {
|
|
|
1087
1115
|
sendId
|
|
1088
1116
|
}) {
|
|
1089
1117
|
const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
|
|
1090
|
-
return [snapshot,
|
|
1118
|
+
return [snapshot, {
|
|
1119
|
+
sendId: resolvedSendId
|
|
1120
|
+
}, undefined];
|
|
1091
1121
|
}
|
|
1092
|
-
function executeCancel(actorScope,
|
|
1122
|
+
function executeCancel(actorScope, params) {
|
|
1093
1123
|
actorScope.defer(() => {
|
|
1094
|
-
actorScope.system.scheduler.cancel(actorScope.self,
|
|
1124
|
+
actorScope.system.scheduler.cancel(actorScope.self, params.sendId);
|
|
1095
1125
|
});
|
|
1096
1126
|
}
|
|
1097
1127
|
/**
|
|
@@ -1127,7 +1157,7 @@ function executeCancel(actorScope, resolvedSendId) {
|
|
|
1127
1157
|
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
1128
1158
|
*/
|
|
1129
1159
|
function cancel(sendId) {
|
|
1130
|
-
function cancel(
|
|
1160
|
+
function cancel(_args, _params) {
|
|
1131
1161
|
{
|
|
1132
1162
|
throw new Error(`This isn't supposed to be called`);
|
|
1133
1163
|
}
|
|
@@ -1149,22 +1179,26 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
|
1149
1179
|
const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
|
|
1150
1180
|
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
1151
1181
|
let actorRef;
|
|
1182
|
+
let resolvedInput = undefined;
|
|
1152
1183
|
if (logic) {
|
|
1184
|
+
resolvedInput = typeof input === 'function' ? input({
|
|
1185
|
+
context: snapshot.context,
|
|
1186
|
+
event: actionArgs.event,
|
|
1187
|
+
self: actorScope.self
|
|
1188
|
+
}) : input;
|
|
1153
1189
|
actorRef = createActor(logic, {
|
|
1154
1190
|
id: resolvedId,
|
|
1155
1191
|
src,
|
|
1156
1192
|
parent: actorScope.self,
|
|
1157
1193
|
syncSnapshot,
|
|
1158
1194
|
systemId,
|
|
1159
|
-
input:
|
|
1160
|
-
context: snapshot.context,
|
|
1161
|
-
event: actionArgs.event,
|
|
1162
|
-
self: actorScope.self
|
|
1163
|
-
}) : input
|
|
1195
|
+
input: resolvedInput
|
|
1164
1196
|
});
|
|
1165
1197
|
}
|
|
1166
1198
|
if (!actorRef) {
|
|
1167
|
-
console.warn(
|
|
1199
|
+
console.warn(
|
|
1200
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-base-to-string
|
|
1201
|
+
`Actor type '${src}' not found in machine '${actorScope.id}'.`);
|
|
1168
1202
|
}
|
|
1169
1203
|
return [cloneMachineSnapshot(snapshot, {
|
|
1170
1204
|
children: {
|
|
@@ -1173,11 +1207,13 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
|
1173
1207
|
}
|
|
1174
1208
|
}), {
|
|
1175
1209
|
id,
|
|
1176
|
-
|
|
1177
|
-
|
|
1210
|
+
systemId,
|
|
1211
|
+
actorRef,
|
|
1212
|
+
src,
|
|
1213
|
+
input: resolvedInput
|
|
1214
|
+
}, undefined];
|
|
1178
1215
|
}
|
|
1179
1216
|
function executeSpawn(actorScope, {
|
|
1180
|
-
id,
|
|
1181
1217
|
actorRef
|
|
1182
1218
|
}) {
|
|
1183
1219
|
if (!actorRef) {
|
|
@@ -1196,12 +1232,12 @@ function spawnChild(...[src, {
|
|
|
1196
1232
|
input,
|
|
1197
1233
|
syncSnapshot = false
|
|
1198
1234
|
} = {}]) {
|
|
1199
|
-
function spawnChild(
|
|
1235
|
+
function spawnChild(_args, _params) {
|
|
1200
1236
|
{
|
|
1201
1237
|
throw new Error(`This isn't supposed to be called`);
|
|
1202
1238
|
}
|
|
1203
1239
|
}
|
|
1204
|
-
spawnChild.type = '
|
|
1240
|
+
spawnChild.type = 'xstate.spawnChild';
|
|
1205
1241
|
spawnChild.id = id;
|
|
1206
1242
|
spawnChild.systemId = systemId;
|
|
1207
1243
|
spawnChild.src = src;
|
|
@@ -1226,7 +1262,7 @@ function resolveStop(_, snapshot, args, actionParams, {
|
|
|
1226
1262
|
}
|
|
1227
1263
|
return [cloneMachineSnapshot(snapshot, {
|
|
1228
1264
|
children
|
|
1229
|
-
}), resolvedActorRef];
|
|
1265
|
+
}), resolvedActorRef, undefined];
|
|
1230
1266
|
}
|
|
1231
1267
|
function executeStop(actorScope, actorRef) {
|
|
1232
1268
|
if (!actorRef) {
|
|
@@ -1258,7 +1294,7 @@ function executeStop(actorScope, actorRef) {
|
|
|
1258
1294
|
* @param actorRef The actor to stop.
|
|
1259
1295
|
*/
|
|
1260
1296
|
function stopChild(actorRef) {
|
|
1261
|
-
function stop(
|
|
1297
|
+
function stop(_args, _params) {
|
|
1262
1298
|
{
|
|
1263
1299
|
throw new Error(`This isn't supposed to be called`);
|
|
1264
1300
|
}
|
|
@@ -1288,7 +1324,7 @@ function checkStateIn(snapshot, _, {
|
|
|
1288
1324
|
return snapshot.matches(stateValue);
|
|
1289
1325
|
}
|
|
1290
1326
|
function stateIn(stateValue) {
|
|
1291
|
-
function stateIn(
|
|
1327
|
+
function stateIn() {
|
|
1292
1328
|
{
|
|
1293
1329
|
throw new Error(`This isn't supposed to be called`);
|
|
1294
1330
|
}
|
|
@@ -1336,7 +1372,7 @@ function checkNot(snapshot, {
|
|
|
1336
1372
|
* @returns A guard
|
|
1337
1373
|
*/
|
|
1338
1374
|
function not(guard) {
|
|
1339
|
-
function not(
|
|
1375
|
+
function not(_args, _params) {
|
|
1340
1376
|
{
|
|
1341
1377
|
throw new Error(`This isn't supposed to be called`);
|
|
1342
1378
|
}
|
|
@@ -1384,7 +1420,7 @@ function checkAnd(snapshot, {
|
|
|
1384
1420
|
* @returns A guard action object
|
|
1385
1421
|
*/
|
|
1386
1422
|
function and(guards) {
|
|
1387
|
-
function and(
|
|
1423
|
+
function and(_args, _params) {
|
|
1388
1424
|
{
|
|
1389
1425
|
throw new Error(`This isn't supposed to be called`);
|
|
1390
1426
|
}
|
|
@@ -1432,7 +1468,7 @@ function checkOr(snapshot, {
|
|
|
1432
1468
|
* @returns A guard action object
|
|
1433
1469
|
*/
|
|
1434
1470
|
function or(guards) {
|
|
1435
|
-
function or(
|
|
1471
|
+
function or(_args, _params) {
|
|
1436
1472
|
{
|
|
1437
1473
|
throw new Error(`This isn't supposed to be called`);
|
|
1438
1474
|
}
|
|
@@ -1618,7 +1654,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1618
1654
|
if (!afterConfig) {
|
|
1619
1655
|
return [];
|
|
1620
1656
|
}
|
|
1621
|
-
const mutateEntryExit =
|
|
1657
|
+
const mutateEntryExit = delay => {
|
|
1622
1658
|
const afterEvent = createAfterEvent(delay, stateNode.id);
|
|
1623
1659
|
const eventType = afterEvent.type;
|
|
1624
1660
|
stateNode.entry.push(raise(afterEvent, {
|
|
@@ -1628,7 +1664,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1628
1664
|
stateNode.exit.push(cancel(eventType));
|
|
1629
1665
|
return eventType;
|
|
1630
1666
|
};
|
|
1631
|
-
const delayedTransitions = Object.keys(afterConfig).flatMap(
|
|
1667
|
+
const delayedTransitions = Object.keys(afterConfig).flatMap(delay => {
|
|
1632
1668
|
const configTransition = afterConfig[delay];
|
|
1633
1669
|
const resolvedTransition = typeof configTransition === 'string' ? {
|
|
1634
1670
|
target: configTransition
|
|
@@ -1718,7 +1754,9 @@ function formatTransitions(stateNode) {
|
|
|
1718
1754
|
function formatInitialTransition(stateNode, _target) {
|
|
1719
1755
|
const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
|
|
1720
1756
|
if (!resolvedTarget && _target) {
|
|
1721
|
-
throw new Error(
|
|
1757
|
+
throw new Error(
|
|
1758
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
|
|
1759
|
+
`Initial state node "${_target}" not found on parent state node #${stateNode.id}`);
|
|
1722
1760
|
}
|
|
1723
1761
|
const transition = {
|
|
1724
1762
|
source: stateNode,
|
|
@@ -1828,7 +1866,7 @@ function getStateNodeByPath(stateNode, statePath) {
|
|
|
1828
1866
|
if (typeof statePath === 'string' && isStateId(statePath)) {
|
|
1829
1867
|
try {
|
|
1830
1868
|
return stateNode.machine.getStateNodeById(statePath);
|
|
1831
|
-
} catch
|
|
1869
|
+
} catch {
|
|
1832
1870
|
// try individual paths
|
|
1833
1871
|
// throw e;
|
|
1834
1872
|
}
|
|
@@ -2057,18 +2095,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2057
2095
|
|
|
2058
2096
|
// Exit states
|
|
2059
2097
|
if (!isInitial) {
|
|
2060
|
-
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
|
|
2098
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue, actorScope.actionExecutor);
|
|
2061
2099
|
}
|
|
2062
2100
|
|
|
2063
2101
|
// Execute transition content
|
|
2064
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
2102
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue, undefined);
|
|
2065
2103
|
|
|
2066
2104
|
// Enter states
|
|
2067
2105
|
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
|
|
2068
2106
|
const nextStateNodes = [...mutStateNodeSet];
|
|
2069
2107
|
if (nextState.status === 'done') {
|
|
2070
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
|
|
2108
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue, undefined);
|
|
2071
2109
|
}
|
|
2110
|
+
|
|
2111
|
+
// eslint-disable-next-line no-useless-catch
|
|
2072
2112
|
try {
|
|
2073
2113
|
if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
|
|
2074
2114
|
return nextState;
|
|
@@ -2238,7 +2278,7 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
|
|
|
2238
2278
|
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
2239
2279
|
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
2240
2280
|
}
|
|
2241
|
-
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
|
|
2281
|
+
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue, _actionExecutor) {
|
|
2242
2282
|
let nextSnapshot = currentSnapshot;
|
|
2243
2283
|
const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
|
|
2244
2284
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
@@ -2262,12 +2302,14 @@ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNod
|
|
|
2262
2302
|
}
|
|
2263
2303
|
}
|
|
2264
2304
|
for (const s of statesToExit) {
|
|
2265
|
-
nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
|
|
2305
|
+
nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue, undefined);
|
|
2266
2306
|
mutStateNodeSet.delete(s);
|
|
2267
2307
|
}
|
|
2268
2308
|
return [nextSnapshot, changedHistory || historyValue];
|
|
2269
2309
|
}
|
|
2270
|
-
|
|
2310
|
+
function getAction(machine, actionType) {
|
|
2311
|
+
return machine.implementations.actions[actionType];
|
|
2312
|
+
}
|
|
2271
2313
|
function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
|
|
2272
2314
|
const {
|
|
2273
2315
|
machine
|
|
@@ -2279,10 +2321,8 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2279
2321
|
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2280
2322
|
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2281
2323
|
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
continue;
|
|
2285
|
-
}
|
|
2324
|
+
|
|
2325
|
+
getAction(machine, typeof action === 'string' ? action : action.type);
|
|
2286
2326
|
const actionArgs = {
|
|
2287
2327
|
context: intermediateSnapshot.context,
|
|
2288
2328
|
event,
|
|
@@ -2293,30 +2333,13 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2293
2333
|
context: intermediateSnapshot.context,
|
|
2294
2334
|
event
|
|
2295
2335
|
}) : action.params : undefined;
|
|
2296
|
-
|
|
2297
|
-
actorScope.
|
|
2298
|
-
type: '
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
params: actionParams
|
|
2303
|
-
}
|
|
2336
|
+
if (!resolvedAction || !('resolve' in resolvedAction)) {
|
|
2337
|
+
actorScope.actionExecutor({
|
|
2338
|
+
type: typeof action === 'string' ? action : typeof action === 'object' ? action.type : action.name || '(anonymous)',
|
|
2339
|
+
info: actionArgs,
|
|
2340
|
+
params: actionParams,
|
|
2341
|
+
exec: resolvedAction
|
|
2304
2342
|
});
|
|
2305
|
-
try {
|
|
2306
|
-
exports.executingCustomAction = resolvedAction;
|
|
2307
|
-
resolvedAction(actionArgs, actionParams);
|
|
2308
|
-
} finally {
|
|
2309
|
-
exports.executingCustomAction = false;
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
if (!('resolve' in resolvedAction)) {
|
|
2313
|
-
if (actorScope.self._processingStatus === ProcessingStatus.Running) {
|
|
2314
|
-
executeAction();
|
|
2315
|
-
} else {
|
|
2316
|
-
actorScope.defer(() => {
|
|
2317
|
-
executeAction();
|
|
2318
|
-
});
|
|
2319
|
-
}
|
|
2320
2343
|
continue;
|
|
2321
2344
|
}
|
|
2322
2345
|
const builtinAction = resolvedAction;
|
|
@@ -2328,11 +2351,12 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2328
2351
|
retries?.push([builtinAction, params]);
|
|
2329
2352
|
}
|
|
2330
2353
|
if ('execute' in builtinAction) {
|
|
2331
|
-
|
|
2332
|
-
builtinAction.
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2354
|
+
actorScope.actionExecutor({
|
|
2355
|
+
type: builtinAction.type,
|
|
2356
|
+
info: actionArgs,
|
|
2357
|
+
params,
|
|
2358
|
+
exec: builtinAction.execute.bind(null, actorScope, params)
|
|
2359
|
+
});
|
|
2336
2360
|
}
|
|
2337
2361
|
if (actions) {
|
|
2338
2362
|
intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions, extra, retries);
|
|
@@ -2351,7 +2375,7 @@ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, i
|
|
|
2351
2375
|
});
|
|
2352
2376
|
return nextState;
|
|
2353
2377
|
}
|
|
2354
|
-
function macrostep(snapshot, event, actorScope, internalQueue
|
|
2378
|
+
function macrostep(snapshot, event, actorScope, internalQueue) {
|
|
2355
2379
|
if (event.type === WILDCARD) {
|
|
2356
2380
|
throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
|
|
2357
2381
|
}
|
|
@@ -2433,7 +2457,7 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
|
|
|
2433
2457
|
};
|
|
2434
2458
|
}
|
|
2435
2459
|
function stopChildren(nextState, event, actorScope) {
|
|
2436
|
-
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stopChild(child)), []);
|
|
2460
|
+
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stopChild(child)), [], undefined);
|
|
2437
2461
|
}
|
|
2438
2462
|
function selectTransitions(event, nextState) {
|
|
2439
2463
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -2606,7 +2630,9 @@ function resolveRaise(_, snapshot, args, actionParams, {
|
|
|
2606
2630
|
}) {
|
|
2607
2631
|
const delaysMap = snapshot.machine.implementations.delays;
|
|
2608
2632
|
if (typeof eventOrExpr === 'string') {
|
|
2609
|
-
throw new Error(
|
|
2633
|
+
throw new Error(
|
|
2634
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
2635
|
+
`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
|
|
2610
2636
|
}
|
|
2611
2637
|
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
2612
2638
|
let resolvedDelay;
|
|
@@ -2623,7 +2649,7 @@ function resolveRaise(_, snapshot, args, actionParams, {
|
|
|
2623
2649
|
event: resolvedEvent,
|
|
2624
2650
|
id,
|
|
2625
2651
|
delay: resolvedDelay
|
|
2626
|
-
}];
|
|
2652
|
+
}, undefined];
|
|
2627
2653
|
}
|
|
2628
2654
|
function executeRaise(actorScope, params) {
|
|
2629
2655
|
const {
|
|
@@ -2649,7 +2675,7 @@ function raise(eventOrExpr, options) {
|
|
|
2649
2675
|
if (exports.executingCustomAction) {
|
|
2650
2676
|
console.warn('Custom actions should not call `raise()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
2651
2677
|
}
|
|
2652
|
-
function raise(
|
|
2678
|
+
function raise(_args, _params) {
|
|
2653
2679
|
{
|
|
2654
2680
|
throw new Error(`This isn't supposed to be called`);
|
|
2655
2681
|
}
|