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
|
@@ -154,7 +154,7 @@ function toStatePath(stateId) {
|
|
|
154
154
|
if (isArray(stateId)) {
|
|
155
155
|
return stateId;
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
const result = [];
|
|
158
158
|
let segment = '';
|
|
159
159
|
for (let i = 0; i < stateId.length; i++) {
|
|
160
160
|
const char = stateId.charCodeAt(i);
|
|
@@ -419,6 +419,7 @@ function createSystem(rootActor, options) {
|
|
|
419
419
|
return system;
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
+
let executingCustomAction = false;
|
|
422
423
|
const $$ACTOR_TYPE = 1;
|
|
423
424
|
|
|
424
425
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
@@ -539,10 +540,37 @@ class Actor {
|
|
|
539
540
|
if (!listeners && !wildcardListener) {
|
|
540
541
|
return;
|
|
541
542
|
}
|
|
542
|
-
const allListeners =
|
|
543
|
-
for (const handler of
|
|
543
|
+
const allListeners = [...(listeners ? listeners.values() : []), ...(wildcardListener ? wildcardListener.values() : [])];
|
|
544
|
+
for (const handler of allListeners) {
|
|
544
545
|
handler(emittedEvent);
|
|
545
546
|
}
|
|
547
|
+
},
|
|
548
|
+
actionExecutor: action => {
|
|
549
|
+
const exec = () => {
|
|
550
|
+
this._actorScope.system._sendInspectionEvent({
|
|
551
|
+
type: '@xstate.action',
|
|
552
|
+
actorRef: this,
|
|
553
|
+
action: {
|
|
554
|
+
type: action.type,
|
|
555
|
+
params: action.params
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
if (!action.exec) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const saveExecutingCustomAction = executingCustomAction;
|
|
562
|
+
try {
|
|
563
|
+
executingCustomAction = true;
|
|
564
|
+
action.exec(action.info, action.params);
|
|
565
|
+
} finally {
|
|
566
|
+
executingCustomAction = saveExecutingCustomAction;
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
if (this._processingStatus === ProcessingStatus.Running) {
|
|
570
|
+
exec();
|
|
571
|
+
} else {
|
|
572
|
+
this._deferred.push(exec);
|
|
573
|
+
}
|
|
546
574
|
}
|
|
547
575
|
};
|
|
548
576
|
|
|
@@ -1071,11 +1099,13 @@ function resolveCancel(_, snapshot, actionArgs, actionParams, {
|
|
|
1071
1099
|
sendId
|
|
1072
1100
|
}) {
|
|
1073
1101
|
const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
|
|
1074
|
-
return [snapshot,
|
|
1102
|
+
return [snapshot, {
|
|
1103
|
+
sendId: resolvedSendId
|
|
1104
|
+
}, undefined];
|
|
1075
1105
|
}
|
|
1076
|
-
function executeCancel(actorScope,
|
|
1106
|
+
function executeCancel(actorScope, params) {
|
|
1077
1107
|
actorScope.defer(() => {
|
|
1078
|
-
actorScope.system.scheduler.cancel(actorScope.self,
|
|
1108
|
+
actorScope.system.scheduler.cancel(actorScope.self, params.sendId);
|
|
1079
1109
|
});
|
|
1080
1110
|
}
|
|
1081
1111
|
/**
|
|
@@ -1111,7 +1141,7 @@ function executeCancel(actorScope, resolvedSendId) {
|
|
|
1111
1141
|
* @param sendId The `id` of the `sendTo(...)` action to cancel.
|
|
1112
1142
|
*/
|
|
1113
1143
|
function cancel(sendId) {
|
|
1114
|
-
function cancel(
|
|
1144
|
+
function cancel(_args, _params) {
|
|
1115
1145
|
}
|
|
1116
1146
|
cancel.type = 'xstate.cancel';
|
|
1117
1147
|
cancel.sendId = sendId;
|
|
@@ -1130,18 +1160,20 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
|
1130
1160
|
const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
|
|
1131
1161
|
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
1132
1162
|
let actorRef;
|
|
1163
|
+
let resolvedInput = undefined;
|
|
1133
1164
|
if (logic) {
|
|
1165
|
+
resolvedInput = typeof input === 'function' ? input({
|
|
1166
|
+
context: snapshot.context,
|
|
1167
|
+
event: actionArgs.event,
|
|
1168
|
+
self: actorScope.self
|
|
1169
|
+
}) : input;
|
|
1134
1170
|
actorRef = createActor(logic, {
|
|
1135
1171
|
id: resolvedId,
|
|
1136
1172
|
src,
|
|
1137
1173
|
parent: actorScope.self,
|
|
1138
1174
|
syncSnapshot,
|
|
1139
1175
|
systemId,
|
|
1140
|
-
input:
|
|
1141
|
-
context: snapshot.context,
|
|
1142
|
-
event: actionArgs.event,
|
|
1143
|
-
self: actorScope.self
|
|
1144
|
-
}) : input
|
|
1176
|
+
input: resolvedInput
|
|
1145
1177
|
});
|
|
1146
1178
|
}
|
|
1147
1179
|
return [cloneMachineSnapshot(snapshot, {
|
|
@@ -1151,11 +1183,13 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
|
1151
1183
|
}
|
|
1152
1184
|
}), {
|
|
1153
1185
|
id,
|
|
1154
|
-
|
|
1155
|
-
|
|
1186
|
+
systemId,
|
|
1187
|
+
actorRef,
|
|
1188
|
+
src,
|
|
1189
|
+
input: resolvedInput
|
|
1190
|
+
}, undefined];
|
|
1156
1191
|
}
|
|
1157
1192
|
function executeSpawn(actorScope, {
|
|
1158
|
-
id,
|
|
1159
1193
|
actorRef
|
|
1160
1194
|
}) {
|
|
1161
1195
|
if (!actorRef) {
|
|
@@ -1174,9 +1208,9 @@ function spawnChild(...[src, {
|
|
|
1174
1208
|
input,
|
|
1175
1209
|
syncSnapshot = false
|
|
1176
1210
|
} = {}]) {
|
|
1177
|
-
function spawnChild(
|
|
1211
|
+
function spawnChild(_args, _params) {
|
|
1178
1212
|
}
|
|
1179
|
-
spawnChild.type = '
|
|
1213
|
+
spawnChild.type = 'xstate.spawnChild';
|
|
1180
1214
|
spawnChild.id = id;
|
|
1181
1215
|
spawnChild.systemId = systemId;
|
|
1182
1216
|
spawnChild.src = src;
|
|
@@ -1201,7 +1235,7 @@ function resolveStop(_, snapshot, args, actionParams, {
|
|
|
1201
1235
|
}
|
|
1202
1236
|
return [cloneMachineSnapshot(snapshot, {
|
|
1203
1237
|
children
|
|
1204
|
-
}), resolvedActorRef];
|
|
1238
|
+
}), resolvedActorRef, undefined];
|
|
1205
1239
|
}
|
|
1206
1240
|
function executeStop(actorScope, actorRef) {
|
|
1207
1241
|
if (!actorRef) {
|
|
@@ -1233,7 +1267,7 @@ function executeStop(actorScope, actorRef) {
|
|
|
1233
1267
|
* @param actorRef The actor to stop.
|
|
1234
1268
|
*/
|
|
1235
1269
|
function stopChild(actorRef) {
|
|
1236
|
-
function stop(
|
|
1270
|
+
function stop(_args, _params) {
|
|
1237
1271
|
}
|
|
1238
1272
|
stop.type = 'xstate.stopChild';
|
|
1239
1273
|
stop.actorRef = actorRef;
|
|
@@ -1260,7 +1294,7 @@ function checkStateIn(snapshot, _, {
|
|
|
1260
1294
|
return snapshot.matches(stateValue);
|
|
1261
1295
|
}
|
|
1262
1296
|
function stateIn(stateValue) {
|
|
1263
|
-
function stateIn(
|
|
1297
|
+
function stateIn() {
|
|
1264
1298
|
return false;
|
|
1265
1299
|
}
|
|
1266
1300
|
stateIn.check = checkStateIn;
|
|
@@ -1306,7 +1340,7 @@ function checkNot(snapshot, {
|
|
|
1306
1340
|
* @returns A guard
|
|
1307
1341
|
*/
|
|
1308
1342
|
function not(guard) {
|
|
1309
|
-
function not(
|
|
1343
|
+
function not(_args, _params) {
|
|
1310
1344
|
return false;
|
|
1311
1345
|
}
|
|
1312
1346
|
not.check = checkNot;
|
|
@@ -1352,7 +1386,7 @@ function checkAnd(snapshot, {
|
|
|
1352
1386
|
* @returns A guard action object
|
|
1353
1387
|
*/
|
|
1354
1388
|
function and(guards) {
|
|
1355
|
-
function and(
|
|
1389
|
+
function and(_args, _params) {
|
|
1356
1390
|
return false;
|
|
1357
1391
|
}
|
|
1358
1392
|
and.check = checkAnd;
|
|
@@ -1398,7 +1432,7 @@ function checkOr(snapshot, {
|
|
|
1398
1432
|
* @returns A guard action object
|
|
1399
1433
|
*/
|
|
1400
1434
|
function or(guards) {
|
|
1401
|
-
function or(
|
|
1435
|
+
function or(_args, _params) {
|
|
1402
1436
|
return false;
|
|
1403
1437
|
}
|
|
1404
1438
|
or.check = checkOr;
|
|
@@ -1497,7 +1531,6 @@ function getValueFromAdj(baseNode, adjList) {
|
|
|
1497
1531
|
if (!childStateNodes) {
|
|
1498
1532
|
return {}; // todo: fix?
|
|
1499
1533
|
}
|
|
1500
|
-
|
|
1501
1534
|
if (baseNode.type === 'compound') {
|
|
1502
1535
|
const childStateNode = childStateNodes[0];
|
|
1503
1536
|
if (childStateNode) {
|
|
@@ -1577,7 +1610,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1577
1610
|
if (!afterConfig) {
|
|
1578
1611
|
return [];
|
|
1579
1612
|
}
|
|
1580
|
-
const mutateEntryExit =
|
|
1613
|
+
const mutateEntryExit = delay => {
|
|
1581
1614
|
const afterEvent = createAfterEvent(delay, stateNode.id);
|
|
1582
1615
|
const eventType = afterEvent.type;
|
|
1583
1616
|
stateNode.entry.push(raise(afterEvent, {
|
|
@@ -1587,7 +1620,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
1587
1620
|
stateNode.exit.push(cancel(eventType));
|
|
1588
1621
|
return eventType;
|
|
1589
1622
|
};
|
|
1590
|
-
const delayedTransitions = Object.keys(afterConfig).flatMap(
|
|
1623
|
+
const delayedTransitions = Object.keys(afterConfig).flatMap(delay => {
|
|
1591
1624
|
const configTransition = afterConfig[delay];
|
|
1592
1625
|
const resolvedTransition = typeof configTransition === 'string' ? {
|
|
1593
1626
|
target: configTransition
|
|
@@ -1672,7 +1705,9 @@ function formatTransitions(stateNode) {
|
|
|
1672
1705
|
function formatInitialTransition(stateNode, _target) {
|
|
1673
1706
|
const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
|
|
1674
1707
|
if (!resolvedTarget && _target) {
|
|
1675
|
-
throw new Error(
|
|
1708
|
+
throw new Error(
|
|
1709
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
|
|
1710
|
+
`Initial state node "${_target}" not found on parent state node #${stateNode.id}`);
|
|
1676
1711
|
}
|
|
1677
1712
|
const transition = {
|
|
1678
1713
|
source: stateNode,
|
|
@@ -1782,7 +1817,7 @@ function getStateNodeByPath(stateNode, statePath) {
|
|
|
1782
1817
|
if (typeof statePath === 'string' && isStateId(statePath)) {
|
|
1783
1818
|
try {
|
|
1784
1819
|
return stateNode.machine.getStateNodeById(statePath);
|
|
1785
|
-
} catch
|
|
1820
|
+
} catch {
|
|
1786
1821
|
// try individual paths
|
|
1787
1822
|
// throw e;
|
|
1788
1823
|
}
|
|
@@ -2011,18 +2046,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2011
2046
|
|
|
2012
2047
|
// Exit states
|
|
2013
2048
|
if (!isInitial) {
|
|
2014
|
-
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
|
|
2049
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue, actorScope.actionExecutor);
|
|
2015
2050
|
}
|
|
2016
2051
|
|
|
2017
2052
|
// Execute transition content
|
|
2018
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
2053
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue, undefined);
|
|
2019
2054
|
|
|
2020
2055
|
// Enter states
|
|
2021
2056
|
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
|
|
2022
2057
|
const nextStateNodes = [...mutStateNodeSet];
|
|
2023
2058
|
if (nextState.status === 'done') {
|
|
2024
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
|
|
2059
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue, undefined);
|
|
2025
2060
|
}
|
|
2061
|
+
|
|
2062
|
+
// eslint-disable-next-line no-useless-catch
|
|
2026
2063
|
try {
|
|
2027
2064
|
if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
|
|
2028
2065
|
return nextState;
|
|
@@ -2192,7 +2229,7 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
|
|
|
2192
2229
|
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
2193
2230
|
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
2194
2231
|
}
|
|
2195
|
-
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
|
|
2232
|
+
function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue, _actionExecutor) {
|
|
2196
2233
|
let nextSnapshot = currentSnapshot;
|
|
2197
2234
|
const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
|
|
2198
2235
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
@@ -2216,12 +2253,14 @@ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNod
|
|
|
2216
2253
|
}
|
|
2217
2254
|
}
|
|
2218
2255
|
for (const s of statesToExit) {
|
|
2219
|
-
nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
|
|
2256
|
+
nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue, undefined);
|
|
2220
2257
|
mutStateNodeSet.delete(s);
|
|
2221
2258
|
}
|
|
2222
2259
|
return [nextSnapshot, changedHistory || historyValue];
|
|
2223
2260
|
}
|
|
2224
|
-
|
|
2261
|
+
function getAction(machine, actionType) {
|
|
2262
|
+
return machine.implementations.actions[actionType];
|
|
2263
|
+
}
|
|
2225
2264
|
function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
|
|
2226
2265
|
const {
|
|
2227
2266
|
machine
|
|
@@ -2233,10 +2272,8 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2233
2272
|
// the existing type of `.actions` assumes non-nullable `TExpressionAction`
|
|
2234
2273
|
// it's fine to cast this here to get a common type and lack of errors in the rest of the code
|
|
2235
2274
|
// our logic below makes sure that we call those 2 "variants" correctly
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
continue;
|
|
2239
|
-
}
|
|
2275
|
+
|
|
2276
|
+
getAction(machine, typeof action === 'string' ? action : action.type);
|
|
2240
2277
|
const actionArgs = {
|
|
2241
2278
|
context: intermediateSnapshot.context,
|
|
2242
2279
|
event,
|
|
@@ -2247,30 +2284,13 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2247
2284
|
context: intermediateSnapshot.context,
|
|
2248
2285
|
event
|
|
2249
2286
|
}) : action.params : undefined;
|
|
2250
|
-
|
|
2251
|
-
actorScope.
|
|
2252
|
-
type: '
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
params: actionParams
|
|
2257
|
-
}
|
|
2287
|
+
if (!resolvedAction || !('resolve' in resolvedAction)) {
|
|
2288
|
+
actorScope.actionExecutor({
|
|
2289
|
+
type: typeof action === 'string' ? action : typeof action === 'object' ? action.type : action.name || '(anonymous)',
|
|
2290
|
+
info: actionArgs,
|
|
2291
|
+
params: actionParams,
|
|
2292
|
+
exec: resolvedAction
|
|
2258
2293
|
});
|
|
2259
|
-
try {
|
|
2260
|
-
executingCustomAction = resolvedAction;
|
|
2261
|
-
resolvedAction(actionArgs, actionParams);
|
|
2262
|
-
} finally {
|
|
2263
|
-
executingCustomAction = false;
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
if (!('resolve' in resolvedAction)) {
|
|
2267
|
-
if (actorScope.self._processingStatus === ProcessingStatus.Running) {
|
|
2268
|
-
executeAction();
|
|
2269
|
-
} else {
|
|
2270
|
-
actorScope.defer(() => {
|
|
2271
|
-
executeAction();
|
|
2272
|
-
});
|
|
2273
|
-
}
|
|
2274
2294
|
continue;
|
|
2275
2295
|
}
|
|
2276
2296
|
const builtinAction = resolvedAction;
|
|
@@ -2282,11 +2302,12 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
|
|
|
2282
2302
|
retries?.push([builtinAction, params]);
|
|
2283
2303
|
}
|
|
2284
2304
|
if ('execute' in builtinAction) {
|
|
2285
|
-
|
|
2286
|
-
builtinAction.
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2305
|
+
actorScope.actionExecutor({
|
|
2306
|
+
type: builtinAction.type,
|
|
2307
|
+
info: actionArgs,
|
|
2308
|
+
params,
|
|
2309
|
+
exec: builtinAction.execute.bind(null, actorScope, params)
|
|
2310
|
+
});
|
|
2290
2311
|
}
|
|
2291
2312
|
if (actions) {
|
|
2292
2313
|
intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions, extra, retries);
|
|
@@ -2305,7 +2326,7 @@ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, i
|
|
|
2305
2326
|
});
|
|
2306
2327
|
return nextState;
|
|
2307
2328
|
}
|
|
2308
|
-
function macrostep(snapshot, event, actorScope, internalQueue
|
|
2329
|
+
function macrostep(snapshot, event, actorScope, internalQueue) {
|
|
2309
2330
|
let nextSnapshot = snapshot;
|
|
2310
2331
|
const microstates = [];
|
|
2311
2332
|
function addMicrostate(microstate, event, transitions) {
|
|
@@ -2384,7 +2405,7 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
|
|
|
2384
2405
|
};
|
|
2385
2406
|
}
|
|
2386
2407
|
function stopChildren(nextState, event, actorScope) {
|
|
2387
|
-
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stopChild(child)), []);
|
|
2408
|
+
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stopChild(child)), [], undefined);
|
|
2388
2409
|
}
|
|
2389
2410
|
function selectTransitions(event, nextState) {
|
|
2390
2411
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -2551,7 +2572,9 @@ function resolveRaise(_, snapshot, args, actionParams, {
|
|
|
2551
2572
|
}) {
|
|
2552
2573
|
const delaysMap = snapshot.machine.implementations.delays;
|
|
2553
2574
|
if (typeof eventOrExpr === 'string') {
|
|
2554
|
-
throw new Error(
|
|
2575
|
+
throw new Error(
|
|
2576
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
2577
|
+
`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
|
|
2555
2578
|
}
|
|
2556
2579
|
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
2557
2580
|
let resolvedDelay;
|
|
@@ -2568,7 +2591,7 @@ function resolveRaise(_, snapshot, args, actionParams, {
|
|
|
2568
2591
|
event: resolvedEvent,
|
|
2569
2592
|
id,
|
|
2570
2593
|
delay: resolvedDelay
|
|
2571
|
-
}];
|
|
2594
|
+
}, undefined];
|
|
2572
2595
|
}
|
|
2573
2596
|
function executeRaise(actorScope, params) {
|
|
2574
2597
|
const {
|
|
@@ -2591,7 +2614,7 @@ function executeRaise(actorScope, params) {
|
|
|
2591
2614
|
* @param eventType The event to raise.
|
|
2592
2615
|
*/
|
|
2593
2616
|
function raise(eventOrExpr, options) {
|
|
2594
|
-
function raise(
|
|
2617
|
+
function raise(_args, _params) {
|
|
2595
2618
|
}
|
|
2596
2619
|
raise.type = 'xstate.raise';
|
|
2597
2620
|
raise.event = eventOrExpr;
|
package/dist/xstate.cjs.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./declarations/src/index.js";
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieHN0YXRlLmNqcy5kLm10cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
|
package/dist/xstate.cjs.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./declarations/src/index";
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieHN0YXRlLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
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 guards_dist_xstateGuards = require('./raise-
|
|
7
|
-
var log = require('./log-
|
|
6
|
+
var guards_dist_xstateGuards = require('./raise-60cebf03.cjs.js');
|
|
7
|
+
var log = require('./log-b0ee96de.cjs.js');
|
|
8
8
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -72,7 +72,7 @@ const toSerializableAction = action => {
|
|
|
72
72
|
return action;
|
|
73
73
|
};
|
|
74
74
|
class StateNode {
|
|
75
|
-
constructor(
|
|
75
|
+
constructor(/** The raw config used to create the machine. */
|
|
76
76
|
config, options) {
|
|
77
77
|
this.config = config;
|
|
78
78
|
/**
|
|
@@ -224,10 +224,10 @@ class StateNode {
|
|
|
224
224
|
systemId
|
|
225
225
|
} = invokeConfig;
|
|
226
226
|
const resolvedId = invokeConfig.id ?? guards_dist_xstateGuards.createInvokeId(this.id, i);
|
|
227
|
-
const
|
|
227
|
+
const sourceName = typeof src === 'string' ? src : `xstate.invoke.${guards_dist_xstateGuards.createInvokeId(this.id, i)}`;
|
|
228
228
|
return {
|
|
229
229
|
...invokeConfig,
|
|
230
|
-
src:
|
|
230
|
+
src: sourceName,
|
|
231
231
|
id: resolvedId,
|
|
232
232
|
systemId: systemId,
|
|
233
233
|
toJSON() {
|
|
@@ -239,7 +239,7 @@ class StateNode {
|
|
|
239
239
|
return {
|
|
240
240
|
...invokeDefValues,
|
|
241
241
|
type: 'xstate.invoke',
|
|
242
|
-
src:
|
|
242
|
+
src: sourceName,
|
|
243
243
|
id: resolvedId
|
|
244
244
|
};
|
|
245
245
|
}
|
|
@@ -328,7 +328,7 @@ class StateNode {
|
|
|
328
328
|
|
|
329
329
|
const STATE_IDENTIFIER = '#';
|
|
330
330
|
class StateMachine {
|
|
331
|
-
constructor(
|
|
331
|
+
constructor(/** The raw config used to create the machine. */
|
|
332
332
|
config, implementations) {
|
|
333
333
|
this.config = config;
|
|
334
334
|
/** The machine's own version. */
|
|
@@ -422,7 +422,7 @@ class StateMachine {
|
|
|
422
422
|
* @param event The received event
|
|
423
423
|
*/
|
|
424
424
|
transition(snapshot, event, actorScope) {
|
|
425
|
-
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).snapshot;
|
|
425
|
+
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).snapshot;
|
|
426
426
|
}
|
|
427
427
|
|
|
428
428
|
/**
|
|
@@ -433,7 +433,7 @@ class StateMachine {
|
|
|
433
433
|
* @param event The received event
|
|
434
434
|
*/
|
|
435
435
|
microstep(snapshot, event, actorScope) {
|
|
436
|
-
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).microstates;
|
|
436
|
+
return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope, []).microstates;
|
|
437
437
|
}
|
|
438
438
|
getTransitionData(snapshot, event) {
|
|
439
439
|
return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
|
|
@@ -463,7 +463,7 @@ class StateMachine {
|
|
|
463
463
|
input: event.input,
|
|
464
464
|
self
|
|
465
465
|
});
|
|
466
|
-
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue);
|
|
466
|
+
return guards_dist_xstateGuards.resolveActionsAndContext(preInitial, initEvent, actorScope, [log.assign(assignment)], internalQueue, undefined);
|
|
467
467
|
}
|
|
468
468
|
return preInitial;
|
|
469
469
|
}
|
|
@@ -541,13 +541,13 @@ class StateMachine {
|
|
|
541
541
|
children,
|
|
542
542
|
_nodes: Array.from(guards_dist_xstateGuards.getAllStateNodes(guards_dist_xstateGuards.getStateNodes(this.root, snapshot.value)))
|
|
543
543
|
}, this);
|
|
544
|
-
|
|
544
|
+
const seen = new Set();
|
|
545
545
|
function reviveContext(contextPart, children) {
|
|
546
546
|
if (seen.has(contextPart)) {
|
|
547
547
|
return;
|
|
548
548
|
}
|
|
549
549
|
seen.add(contextPart);
|
|
550
|
-
for (
|
|
550
|
+
for (const key in contextPart) {
|
|
551
551
|
const value = contextPart[key];
|
|
552
552
|
if (value && typeof value === 'object') {
|
|
553
553
|
if ('xstate$$type' in value && value.xstate$$type === guards_dist_xstateGuards.$$ACTOR_TYPE) {
|
|
@@ -563,9 +563,6 @@ class StateMachine {
|
|
|
563
563
|
}
|
|
564
564
|
}
|
|
565
565
|
|
|
566
|
-
// this is not 100% accurate since we can't make parallel regions required in the result
|
|
567
|
-
// `TTestValue` doesn't encode this information anyhow for us to be able to do that
|
|
568
|
-
// this is fine for most practical use cases anyway though
|
|
569
566
|
/**
|
|
570
567
|
* Creates a state machine (statechart) with the given configuration.
|
|
571
568
|
*
|
|
@@ -623,10 +620,13 @@ function createInertActorScope(actorLogic) {
|
|
|
623
620
|
sessionId: '',
|
|
624
621
|
stopChild: () => {},
|
|
625
622
|
system: self.system,
|
|
626
|
-
emit: () => {}
|
|
623
|
+
emit: () => {},
|
|
624
|
+
actionExecutor: () => {}
|
|
627
625
|
};
|
|
628
626
|
return inertActorScope;
|
|
629
627
|
}
|
|
628
|
+
|
|
629
|
+
/** @deprecated Use `initialTransition(…)` instead. */
|
|
630
630
|
function getInitialSnapshot(actorLogic, ...[input]) {
|
|
631
631
|
const actorScope = createInertActorScope(actorLogic);
|
|
632
632
|
return actorLogic.getInitialSnapshot(actorScope, input);
|
|
@@ -639,6 +639,7 @@ function getInitialSnapshot(actorLogic, ...[input]) {
|
|
|
639
639
|
* If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
|
|
640
640
|
* used.
|
|
641
641
|
*
|
|
642
|
+
* @deprecated Use `transition(…)` instead.
|
|
642
643
|
* @example
|
|
643
644
|
*
|
|
644
645
|
* ```ts
|
|
@@ -672,6 +673,7 @@ function getNextSnapshot(actorLogic, snapshot, event) {
|
|
|
672
673
|
|
|
673
674
|
// at the moment we allow extra actors - ones that are not specified by `children`
|
|
674
675
|
// this could be reconsidered in the future
|
|
676
|
+
|
|
675
677
|
function setup({
|
|
676
678
|
schemas,
|
|
677
679
|
actors,
|
|
@@ -692,6 +694,9 @@ function setup({
|
|
|
692
694
|
};
|
|
693
695
|
}
|
|
694
696
|
|
|
697
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
698
|
+
|
|
699
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
695
700
|
class SimulatedClock {
|
|
696
701
|
constructor() {
|
|
697
702
|
this.timeouts = new Map();
|
|
@@ -792,6 +797,39 @@ function toPromise(actor) {
|
|
|
792
797
|
});
|
|
793
798
|
}
|
|
794
799
|
|
|
800
|
+
/**
|
|
801
|
+
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
|
|
802
|
+
* `nextSnapshot` and `actions` to execute.
|
|
803
|
+
*
|
|
804
|
+
* This is a pure function that does not execute `actions`.
|
|
805
|
+
*/
|
|
806
|
+
function transition(logic, snapshot, event) {
|
|
807
|
+
const executableActions = [];
|
|
808
|
+
const actorScope = createInertActorScope(logic);
|
|
809
|
+
actorScope.actionExecutor = action => {
|
|
810
|
+
executableActions.push(action);
|
|
811
|
+
};
|
|
812
|
+
const nextSnapshot = logic.transition(snapshot, event, actorScope);
|
|
813
|
+
return [nextSnapshot, executableActions];
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Given actor `logic` and optional `input`, returns a tuple of the
|
|
818
|
+
* `nextSnapshot` and `actions` to execute from the initial transition (no
|
|
819
|
+
* previous state).
|
|
820
|
+
*
|
|
821
|
+
* This is a pure function that does not execute `actions`.
|
|
822
|
+
*/
|
|
823
|
+
function initialTransition(logic, ...[input]) {
|
|
824
|
+
const executableActions = [];
|
|
825
|
+
const actorScope = createInertActorScope(logic);
|
|
826
|
+
actorScope.actionExecutor = action => {
|
|
827
|
+
executableActions.push(action);
|
|
828
|
+
};
|
|
829
|
+
const nextSnapshot = logic.getInitialSnapshot(actorScope, input);
|
|
830
|
+
return [nextSnapshot, executableActions];
|
|
831
|
+
}
|
|
832
|
+
|
|
795
833
|
const defaultWaitForOptions = {
|
|
796
834
|
timeout: Infinity // much more than 10 seconds
|
|
797
835
|
};
|
|
@@ -827,6 +865,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
827
865
|
signal
|
|
828
866
|
} = resolvedOptions;
|
|
829
867
|
if (signal?.aborted) {
|
|
868
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
830
869
|
rej(signal.reason);
|
|
831
870
|
return;
|
|
832
871
|
}
|
|
@@ -855,6 +894,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
855
894
|
* `abort` event
|
|
856
895
|
*/
|
|
857
896
|
let abortListener;
|
|
897
|
+
// eslint-disable-next-line prefer-const
|
|
858
898
|
let sub; // avoid TDZ when disposing synchronously
|
|
859
899
|
|
|
860
900
|
// See if the current snapshot already matches the predicate
|
|
@@ -868,6 +908,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
868
908
|
abortListener = () => {
|
|
869
909
|
dispose();
|
|
870
910
|
// XState does not "own" the signal, so we should reject with its reason (if any)
|
|
911
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
871
912
|
rej(signal.reason);
|
|
872
913
|
};
|
|
873
914
|
signal.addEventListener('abort', abortListener);
|
|
@@ -876,6 +917,7 @@ function waitFor(actorRef, predicate, options) {
|
|
|
876
917
|
next: checkEmitted,
|
|
877
918
|
error: err => {
|
|
878
919
|
dispose();
|
|
920
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
879
921
|
rej(err);
|
|
880
922
|
},
|
|
881
923
|
complete: () => {
|
|
@@ -928,6 +970,8 @@ exports.assertEvent = assertEvent;
|
|
|
928
970
|
exports.createMachine = createMachine;
|
|
929
971
|
exports.getInitialSnapshot = getInitialSnapshot;
|
|
930
972
|
exports.getNextSnapshot = getNextSnapshot;
|
|
973
|
+
exports.initialTransition = initialTransition;
|
|
931
974
|
exports.setup = setup;
|
|
932
975
|
exports.toPromise = toPromise;
|
|
976
|
+
exports.transition = transition;
|
|
933
977
|
exports.waitFor = waitFor;
|
package/dist/xstate.cjs.mjs
CHANGED
|
@@ -23,6 +23,7 @@ export {
|
|
|
23
23
|
getInitialSnapshot,
|
|
24
24
|
getNextSnapshot,
|
|
25
25
|
getStateNodes,
|
|
26
|
+
initialTransition,
|
|
26
27
|
interpret,
|
|
27
28
|
isMachineSnapshot,
|
|
28
29
|
log,
|
|
@@ -40,5 +41,6 @@ export {
|
|
|
40
41
|
stopChild,
|
|
41
42
|
toObserver,
|
|
42
43
|
toPromise,
|
|
44
|
+
transition,
|
|
43
45
|
waitFor
|
|
44
46
|
} from "./xstate.cjs.js";
|