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);
|
|
@@ -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
|
}
|
|
@@ -1533,7 +1569,6 @@ function getValueFromAdj(baseNode, adjList) {
|
|
|
1533
1569
|
if (!childStateNodes) {
|
|
1534
1570
|
return {}; // todo: fix?
|
|
1535
1571
|
}
|
|
1536
|
-
|
|
1537
1572
|
if (baseNode.type === 'compound') {
|
|
1538
1573
|
const childStateNode = childStateNodes[0];
|
|
1539
1574
|
if (childStateNode) {
|
|
@@ -1619,7 +1654,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1619
1654
|
if (!afterConfig) {
|
|
1620
1655
|
return [];
|
|
1621
1656
|
}
|
|
1622
|
-
const mutateEntryExit =
|
|
1657
|
+
const mutateEntryExit = delay => {
|
|
1623
1658
|
const afterEvent = createAfterEvent(delay, stateNode.id);
|
|
1624
1659
|
const eventType = afterEvent.type;
|
|
1625
1660
|
stateNode.entry.push(raise(afterEvent, {
|
|
@@ -1629,7 +1664,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1629
1664
|
stateNode.exit.push(cancel(eventType));
|
|
1630
1665
|
return eventType;
|
|
1631
1666
|
};
|
|
1632
|
-
const delayedTransitions = Object.keys(afterConfig).flatMap(
|
|
1667
|
+
const delayedTransitions = Object.keys(afterConfig).flatMap(delay => {
|
|
1633
1668
|
const configTransition = afterConfig[delay];
|
|
1634
1669
|
const resolvedTransition = typeof configTransition === 'string' ? {
|
|
1635
1670
|
target: configTransition
|
|
@@ -1719,7 +1754,9 @@ function formatTransitions(stateNode) {
|
|
|
1719
1754
|
function formatInitialTransition(stateNode, _target) {
|
|
1720
1755
|
const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
|
|
1721
1756
|
if (!resolvedTarget && _target) {
|
|
1722
|
-
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}`);
|
|
1723
1760
|
}
|
|
1724
1761
|
const transition = {
|
|
1725
1762
|
source: stateNode,
|
|
@@ -1829,7 +1866,7 @@ function getStateNodeByPath(stateNode, statePath) {
|
|
|
1829
1866
|
if (typeof statePath === 'string' && isStateId(statePath)) {
|
|
1830
1867
|
try {
|
|
1831
1868
|
return stateNode.machine.getStateNodeById(statePath);
|
|
1832
|
-
} catch
|
|
1869
|
+
} catch {
|
|
1833
1870
|
// try individual paths
|
|
1834
1871
|
// throw e;
|
|
1835
1872
|
}
|
|
@@ -2058,18 +2095,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2058
2095
|
|
|
2059
2096
|
// Exit states
|
|
2060
2097
|
if (!isInitial) {
|
|
2061
|
-
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
|
|
2098
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue, actorScope.actionExecutor);
|
|
2062
2099
|
}
|
|
2063
2100
|
|
|
2064
2101
|
// Execute transition content
|
|
2065
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
2102
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue, undefined);
|
|
2066
2103
|
|
|
2067
2104
|
// Enter states
|
|
2068
2105
|
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
|
|
2069
2106
|
const nextStateNodes = [...mutStateNodeSet];
|
|
2070
2107
|
if (nextState.status === 'done') {
|
|
2071
|
-
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);
|
|
2072
2109
|
}
|
|
2110
|
+
|
|
2111
|
+
// eslint-disable-next-line no-useless-catch
|
|
2073
2112
|
try {
|
|
2074
2113
|
if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
|
|
2075
2114
|
return nextState;
|
|
@@ -2239,7 +2278,7 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
|
|
|
2239
2278
|
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
2240
2279
|
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
2241
2280
|
}
|
|
2242
|
-
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
|
|
2281
|
+
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue, _actionExecutor) {
|
|
2243
2282
|
let nextSnapshot = currentSnapshot;
|
|
2244
2283
|
const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
|
|
2245
2284
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
@@ -2263,12 +2302,14 @@ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNod
|
|
|
2263
2302
|
}
|
|
2264
2303
|
}
|
|
2265
2304
|
for (const s of statesToExit) {
|
|
2266
|
-
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);
|
|
2267
2306
|
mutStateNodeSet.delete(s);
|
|
2268
2307
|
}
|
|
2269
2308
|
return [nextSnapshot, changedHistory || historyValue];
|
|
2270
2309
|
}
|
|
2271
|
-
|
|
2310
|
+
function getAction(machine, actionType) {
|
|
2311
|
+
return machine.implementations.actions[actionType];
|
|
2312
|
+
}
|
|
2272
2313
|
function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
|
|
2273
2314
|
const {
|
|
2274
2315
|
machine
|
|
@@ -2280,10 +2321,8 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2280
2321
|
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2281
2322
|
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2282
2323
|
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
continue;
|
|
2286
|
-
}
|
|
2324
|
+
|
|
2325
|
+
getAction(machine, typeof action === 'string' ? action : action.type);
|
|
2287
2326
|
const actionArgs = {
|
|
2288
2327
|
context: intermediateSnapshot.context,
|
|
2289
2328
|
event,
|
|
@@ -2294,30 +2333,13 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2294
2333
|
context: intermediateSnapshot.context,
|
|
2295
2334
|
event
|
|
2296
2335
|
}) : action.params : undefined;
|
|
2297
|
-
|
|
2298
|
-
actorScope.
|
|
2299
|
-
type: '
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
params: actionParams
|
|
2304
|
-
}
|
|
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
|
|
2305
2342
|
});
|
|
2306
|
-
try {
|
|
2307
|
-
exports.executingCustomAction = resolvedAction;
|
|
2308
|
-
resolvedAction(actionArgs, actionParams);
|
|
2309
|
-
} finally {
|
|
2310
|
-
exports.executingCustomAction = false;
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
if (!('resolve' in resolvedAction)) {
|
|
2314
|
-
if (actorScope.self._processingStatus === ProcessingStatus.Running) {
|
|
2315
|
-
executeAction();
|
|
2316
|
-
} else {
|
|
2317
|
-
actorScope.defer(() => {
|
|
2318
|
-
executeAction();
|
|
2319
|
-
});
|
|
2320
|
-
}
|
|
2321
2343
|
continue;
|
|
2322
2344
|
}
|
|
2323
2345
|
const builtinAction = resolvedAction;
|
|
@@ -2329,11 +2351,12 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2329
2351
|
retries?.push([builtinAction, params]);
|
|
2330
2352
|
}
|
|
2331
2353
|
if ('execute' in builtinAction) {
|
|
2332
|
-
|
|
2333
|
-
builtinAction.
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2354
|
+
actorScope.actionExecutor({
|
|
2355
|
+
type: builtinAction.type,
|
|
2356
|
+
info: actionArgs,
|
|
2357
|
+
params,
|
|
2358
|
+
exec: builtinAction.execute.bind(null, actorScope, params)
|
|
2359
|
+
});
|
|
2337
2360
|
}
|
|
2338
2361
|
if (actions) {
|
|
2339
2362
|
intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions, extra, retries);
|
|
@@ -2352,7 +2375,7 @@ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, i
|
|
|
2352
2375
|
});
|
|
2353
2376
|
return nextState;
|
|
2354
2377
|
}
|
|
2355
|
-
function macrostep(snapshot, event, actorScope, internalQueue
|
|
2378
|
+
function macrostep(snapshot, event, actorScope, internalQueue) {
|
|
2356
2379
|
if (event.type === WILDCARD) {
|
|
2357
2380
|
throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
|
|
2358
2381
|
}
|
|
@@ -2434,7 +2457,7 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
|
|
|
2434
2457
|
};
|
|
2435
2458
|
}
|
|
2436
2459
|
function stopChildren(nextState, event, actorScope) {
|
|
2437
|
-
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);
|
|
2438
2461
|
}
|
|
2439
2462
|
function selectTransitions(event, nextState) {
|
|
2440
2463
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -2607,7 +2630,9 @@ function resolveRaise(_, snapshot, args, actionParams, {
|
|
|
2607
2630
|
}) {
|
|
2608
2631
|
const delaysMap = snapshot.machine.implementations.delays;
|
|
2609
2632
|
if (typeof eventOrExpr === 'string') {
|
|
2610
|
-
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`);
|
|
2611
2636
|
}
|
|
2612
2637
|
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
2613
2638
|
let resolvedDelay;
|
|
@@ -2624,7 +2649,7 @@ function resolveRaise(_, snapshot, args, actionParams, {
|
|
|
2624
2649
|
event: resolvedEvent,
|
|
2625
2650
|
id,
|
|
2626
2651
|
delay: resolvedDelay
|
|
2627
|
-
}];
|
|
2652
|
+
}, undefined];
|
|
2628
2653
|
}
|
|
2629
2654
|
function executeRaise(actorScope, params) {
|
|
2630
2655
|
const {
|
|
@@ -2650,7 +2675,7 @@ function raise(eventOrExpr, options) {
|
|
|
2650
2675
|
if (exports.executingCustomAction) {
|
|
2651
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.');
|
|
2652
2677
|
}
|
|
2653
|
-
function raise(
|
|
2678
|
+
function raise(_args, _params) {
|
|
2654
2679
|
{
|
|
2655
2680
|
throw new Error(`This isn't supposed to be called`);
|
|
2656
2681
|
}
|