xstate 5.16.0 → 5.17.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.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/dist/{raise-a6298350.cjs.js → State-30c95050.cjs.js} +199 -191
- package/dist/{raise-7d030497.development.esm.js → State-34039d2a.development.esm.js} +215 -207
- package/dist/{raise-bad6a97b.development.cjs.js → State-a2464a1e.development.cjs.js} +214 -206
- package/dist/{raise-2cfe6b8f.esm.js → State-cdbc7940.esm.js} +200 -192
- package/dist/declarations/src/State.d.ts +8 -8
- package/dist/declarations/src/StateMachine.d.ts +10 -12
- package/dist/declarations/src/actions/stopChild.d.ts +1 -0
- package/dist/declarations/src/actors/callback.d.ts +3 -2
- package/dist/declarations/src/createActor.d.ts +6 -6
- package/dist/declarations/src/index.d.ts +11 -12
- package/dist/declarations/src/inspection.d.ts +3 -2
- package/dist/declarations/src/setup.d.ts +1 -1
- package/dist/declarations/src/stateUtils.d.ts +1 -13
- package/dist/declarations/src/system.d.ts +3 -2
- package/dist/declarations/src/types.d.ts +7 -1
- package/dist/declarations/src/utils.d.ts +1 -5
- package/dist/{log-f9587b82.cjs.js → log-19086852.cjs.js} +1 -1
- package/dist/{log-8320f5e6.esm.js → log-4a38a98a.esm.js} +1 -1
- package/dist/{log-17f4495d.development.esm.js → log-62f17756.development.esm.js} +1 -1
- package/dist/{log-31321d85.development.cjs.js → log-ec36113c.development.cjs.js} +1 -1
- package/dist/xstate.cjs.js +92 -92
- package/dist/xstate.development.cjs.js +95 -95
- package/dist/xstate.development.esm.js +91 -91
- package/dist/xstate.esm.js +88 -88
- 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.map +1 -1
- package/package.json +1 -3
|
@@ -324,7 +324,9 @@ function createSystem(rootActor, options) {
|
|
|
324
324
|
const timeout = timerMap[scheduledEventId];
|
|
325
325
|
delete timerMap[scheduledEventId];
|
|
326
326
|
delete system._snapshot._scheduledEvents[scheduledEventId];
|
|
327
|
-
|
|
327
|
+
if (timeout !== undefined) {
|
|
328
|
+
clock.clearTimeout(timeout);
|
|
329
|
+
}
|
|
328
330
|
},
|
|
329
331
|
cancelAll: actorRef => {
|
|
330
332
|
for (const scheduledEventId in system._snapshot._scheduledEvents) {
|
|
@@ -421,6 +423,7 @@ function createSystem(rootActor, options) {
|
|
|
421
423
|
}
|
|
422
424
|
|
|
423
425
|
const $$ACTOR_TYPE = 1;
|
|
426
|
+
|
|
424
427
|
// those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
|
|
425
428
|
let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
|
|
426
429
|
ProcessingStatus[ProcessingStatus["NotStarted"] = 0] = "NotStarted";
|
|
@@ -1069,10 +1072,14 @@ function createActor(logic, ...[options]) {
|
|
|
1069
1072
|
* options, if any.
|
|
1070
1073
|
*
|
|
1071
1074
|
* @deprecated Use `createActor` instead
|
|
1075
|
+
* @alias
|
|
1072
1076
|
*/
|
|
1073
1077
|
const interpret = createActor;
|
|
1074
1078
|
|
|
1075
|
-
/**
|
|
1079
|
+
/**
|
|
1080
|
+
* @deprecated Use `Actor` instead.
|
|
1081
|
+
* @alias
|
|
1082
|
+
*/
|
|
1076
1083
|
|
|
1077
1084
|
function resolveCancel(_, snapshot, actionArgs, actionParams, {
|
|
1078
1085
|
sendId
|
|
@@ -1130,144 +1137,6 @@ function cancel(sendId) {
|
|
|
1130
1137
|
return cancel;
|
|
1131
1138
|
}
|
|
1132
1139
|
|
|
1133
|
-
function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
1134
|
-
id,
|
|
1135
|
-
systemId,
|
|
1136
|
-
src,
|
|
1137
|
-
input,
|
|
1138
|
-
syncSnapshot
|
|
1139
|
-
}) {
|
|
1140
|
-
const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
|
|
1141
|
-
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
1142
|
-
let actorRef;
|
|
1143
|
-
if (logic) {
|
|
1144
|
-
actorRef = createActor(logic, {
|
|
1145
|
-
id: resolvedId,
|
|
1146
|
-
src,
|
|
1147
|
-
parent: actorScope.self,
|
|
1148
|
-
syncSnapshot,
|
|
1149
|
-
systemId,
|
|
1150
|
-
input: typeof input === 'function' ? input({
|
|
1151
|
-
context: snapshot.context,
|
|
1152
|
-
event: actionArgs.event,
|
|
1153
|
-
self: actorScope.self
|
|
1154
|
-
}) : input
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
if (!actorRef) {
|
|
1158
|
-
console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
|
|
1159
|
-
}
|
|
1160
|
-
return [cloneMachineSnapshot(snapshot, {
|
|
1161
|
-
children: {
|
|
1162
|
-
...snapshot.children,
|
|
1163
|
-
[resolvedId]: actorRef
|
|
1164
|
-
}
|
|
1165
|
-
}), {
|
|
1166
|
-
id,
|
|
1167
|
-
actorRef
|
|
1168
|
-
}];
|
|
1169
|
-
}
|
|
1170
|
-
function executeSpawn(actorScope, {
|
|
1171
|
-
id,
|
|
1172
|
-
actorRef
|
|
1173
|
-
}) {
|
|
1174
|
-
if (!actorRef) {
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
actorScope.defer(() => {
|
|
1178
|
-
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
1179
|
-
return;
|
|
1180
|
-
}
|
|
1181
|
-
actorRef.start();
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
function spawnChild(...[src, {
|
|
1185
|
-
id,
|
|
1186
|
-
systemId,
|
|
1187
|
-
input,
|
|
1188
|
-
syncSnapshot = false
|
|
1189
|
-
} = {}]) {
|
|
1190
|
-
function spawnChild(args, params) {
|
|
1191
|
-
{
|
|
1192
|
-
throw new Error(`This isn't supposed to be called`);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
spawnChild.type = 'snapshot.spawnChild';
|
|
1196
|
-
spawnChild.id = id;
|
|
1197
|
-
spawnChild.systemId = systemId;
|
|
1198
|
-
spawnChild.src = src;
|
|
1199
|
-
spawnChild.input = input;
|
|
1200
|
-
spawnChild.syncSnapshot = syncSnapshot;
|
|
1201
|
-
spawnChild.resolve = resolveSpawn;
|
|
1202
|
-
spawnChild.execute = executeSpawn;
|
|
1203
|
-
return spawnChild;
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
function resolveStop(_, snapshot, args, actionParams, {
|
|
1207
|
-
actorRef
|
|
1208
|
-
}) {
|
|
1209
|
-
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
|
|
1210
|
-
const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
|
|
1211
|
-
let children = snapshot.children;
|
|
1212
|
-
if (resolvedActorRef) {
|
|
1213
|
-
children = {
|
|
1214
|
-
...children
|
|
1215
|
-
};
|
|
1216
|
-
delete children[resolvedActorRef.id];
|
|
1217
|
-
}
|
|
1218
|
-
return [cloneMachineSnapshot(snapshot, {
|
|
1219
|
-
children
|
|
1220
|
-
}), resolvedActorRef];
|
|
1221
|
-
}
|
|
1222
|
-
function executeStop(actorScope, actorRef) {
|
|
1223
|
-
if (!actorRef) {
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
1228
|
-
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
1229
|
-
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
1230
|
-
actorScope.system._unregister(actorRef);
|
|
1231
|
-
|
|
1232
|
-
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
1233
|
-
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
1234
|
-
if (actorRef._processingStatus !== ProcessingStatus.Running) {
|
|
1235
|
-
actorScope.stopChild(actorRef);
|
|
1236
|
-
return;
|
|
1237
|
-
}
|
|
1238
|
-
// stopping a child enqueues a stop event in the child actor's mailbox
|
|
1239
|
-
// we need for all of the already enqueued events to be processed before we stop the child
|
|
1240
|
-
// the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
|
|
1241
|
-
// and we don't want to ignore those events
|
|
1242
|
-
actorScope.defer(() => {
|
|
1243
|
-
actorScope.stopChild(actorRef);
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
/**
|
|
1247
|
-
* Stops a child actor.
|
|
1248
|
-
*
|
|
1249
|
-
* @param actorRef The actor to stop.
|
|
1250
|
-
*/
|
|
1251
|
-
function stopChild(actorRef) {
|
|
1252
|
-
function stop(args, params) {
|
|
1253
|
-
{
|
|
1254
|
-
throw new Error(`This isn't supposed to be called`);
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
stop.type = 'xstate.stopChild';
|
|
1258
|
-
stop.actorRef = actorRef;
|
|
1259
|
-
stop.resolve = resolveStop;
|
|
1260
|
-
stop.execute = executeStop;
|
|
1261
|
-
return stop;
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
/**
|
|
1265
|
-
* Stops a child actor.
|
|
1266
|
-
*
|
|
1267
|
-
* @deprecated Use `stopChild(...)` instead
|
|
1268
|
-
*/
|
|
1269
|
-
const stop = stopChild;
|
|
1270
|
-
|
|
1271
1140
|
function checkStateIn(snapshot, _, {
|
|
1272
1141
|
stateValue
|
|
1273
1142
|
}) {
|
|
@@ -1464,6 +1333,211 @@ function evaluateGuard(guard, context, event, snapshot) {
|
|
|
1464
1333
|
);
|
|
1465
1334
|
}
|
|
1466
1335
|
|
|
1336
|
+
function resolveRaise(_, snapshot, args, actionParams, {
|
|
1337
|
+
event: eventOrExpr,
|
|
1338
|
+
id,
|
|
1339
|
+
delay
|
|
1340
|
+
}, {
|
|
1341
|
+
internalQueue
|
|
1342
|
+
}) {
|
|
1343
|
+
const delaysMap = snapshot.machine.implementations.delays;
|
|
1344
|
+
if (typeof eventOrExpr === 'string') {
|
|
1345
|
+
throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
|
|
1346
|
+
}
|
|
1347
|
+
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
1348
|
+
let resolvedDelay;
|
|
1349
|
+
if (typeof delay === 'string') {
|
|
1350
|
+
const configDelay = delaysMap && delaysMap[delay];
|
|
1351
|
+
resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
|
|
1352
|
+
} else {
|
|
1353
|
+
resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
|
|
1354
|
+
}
|
|
1355
|
+
if (typeof resolvedDelay !== 'number') {
|
|
1356
|
+
internalQueue.push(resolvedEvent);
|
|
1357
|
+
}
|
|
1358
|
+
return [snapshot, {
|
|
1359
|
+
event: resolvedEvent,
|
|
1360
|
+
id,
|
|
1361
|
+
delay: resolvedDelay
|
|
1362
|
+
}];
|
|
1363
|
+
}
|
|
1364
|
+
function executeRaise(actorScope, params) {
|
|
1365
|
+
const {
|
|
1366
|
+
event,
|
|
1367
|
+
delay,
|
|
1368
|
+
id
|
|
1369
|
+
} = params;
|
|
1370
|
+
if (typeof delay === 'number') {
|
|
1371
|
+
actorScope.defer(() => {
|
|
1372
|
+
const self = actorScope.self;
|
|
1373
|
+
actorScope.system.scheduler.schedule(self, self, event, delay, id);
|
|
1374
|
+
});
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* Raises an event. This places the event in the internal event queue, so that
|
|
1380
|
+
* the event is immediately consumed by the machine in the current step.
|
|
1381
|
+
*
|
|
1382
|
+
* @param eventType The event to raise.
|
|
1383
|
+
*/
|
|
1384
|
+
function raise(eventOrExpr, options) {
|
|
1385
|
+
if (executingCustomAction) {
|
|
1386
|
+
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.');
|
|
1387
|
+
}
|
|
1388
|
+
function raise(args, params) {
|
|
1389
|
+
{
|
|
1390
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
raise.type = 'xstate.raise';
|
|
1394
|
+
raise.event = eventOrExpr;
|
|
1395
|
+
raise.id = options?.id;
|
|
1396
|
+
raise.delay = options?.delay;
|
|
1397
|
+
raise.resolve = resolveRaise;
|
|
1398
|
+
raise.execute = executeRaise;
|
|
1399
|
+
return raise;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
|
|
1403
|
+
id,
|
|
1404
|
+
systemId,
|
|
1405
|
+
src,
|
|
1406
|
+
input,
|
|
1407
|
+
syncSnapshot
|
|
1408
|
+
}) {
|
|
1409
|
+
const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
|
|
1410
|
+
const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
|
|
1411
|
+
let actorRef;
|
|
1412
|
+
if (logic) {
|
|
1413
|
+
actorRef = createActor(logic, {
|
|
1414
|
+
id: resolvedId,
|
|
1415
|
+
src,
|
|
1416
|
+
parent: actorScope.self,
|
|
1417
|
+
syncSnapshot,
|
|
1418
|
+
systemId,
|
|
1419
|
+
input: typeof input === 'function' ? input({
|
|
1420
|
+
context: snapshot.context,
|
|
1421
|
+
event: actionArgs.event,
|
|
1422
|
+
self: actorScope.self
|
|
1423
|
+
}) : input
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
if (!actorRef) {
|
|
1427
|
+
console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
|
|
1428
|
+
}
|
|
1429
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
1430
|
+
children: {
|
|
1431
|
+
...snapshot.children,
|
|
1432
|
+
[resolvedId]: actorRef
|
|
1433
|
+
}
|
|
1434
|
+
}), {
|
|
1435
|
+
id,
|
|
1436
|
+
actorRef
|
|
1437
|
+
}];
|
|
1438
|
+
}
|
|
1439
|
+
function executeSpawn(actorScope, {
|
|
1440
|
+
id,
|
|
1441
|
+
actorRef
|
|
1442
|
+
}) {
|
|
1443
|
+
if (!actorRef) {
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
actorScope.defer(() => {
|
|
1447
|
+
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
actorRef.start();
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
function spawnChild(...[src, {
|
|
1454
|
+
id,
|
|
1455
|
+
systemId,
|
|
1456
|
+
input,
|
|
1457
|
+
syncSnapshot = false
|
|
1458
|
+
} = {}]) {
|
|
1459
|
+
function spawnChild(args, params) {
|
|
1460
|
+
{
|
|
1461
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
spawnChild.type = 'snapshot.spawnChild';
|
|
1465
|
+
spawnChild.id = id;
|
|
1466
|
+
spawnChild.systemId = systemId;
|
|
1467
|
+
spawnChild.src = src;
|
|
1468
|
+
spawnChild.input = input;
|
|
1469
|
+
spawnChild.syncSnapshot = syncSnapshot;
|
|
1470
|
+
spawnChild.resolve = resolveSpawn;
|
|
1471
|
+
spawnChild.execute = executeSpawn;
|
|
1472
|
+
return spawnChild;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
function resolveStop(_, snapshot, args, actionParams, {
|
|
1476
|
+
actorRef
|
|
1477
|
+
}) {
|
|
1478
|
+
const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
|
|
1479
|
+
const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
|
|
1480
|
+
let children = snapshot.children;
|
|
1481
|
+
if (resolvedActorRef) {
|
|
1482
|
+
children = {
|
|
1483
|
+
...children
|
|
1484
|
+
};
|
|
1485
|
+
delete children[resolvedActorRef.id];
|
|
1486
|
+
}
|
|
1487
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
1488
|
+
children
|
|
1489
|
+
}), resolvedActorRef];
|
|
1490
|
+
}
|
|
1491
|
+
function executeStop(actorScope, actorRef) {
|
|
1492
|
+
if (!actorRef) {
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
1497
|
+
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
1498
|
+
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
1499
|
+
actorScope.system._unregister(actorRef);
|
|
1500
|
+
|
|
1501
|
+
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
1502
|
+
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
1503
|
+
if (actorRef._processingStatus !== ProcessingStatus.Running) {
|
|
1504
|
+
actorScope.stopChild(actorRef);
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
// stopping a child enqueues a stop event in the child actor's mailbox
|
|
1508
|
+
// we need for all of the already enqueued events to be processed before we stop the child
|
|
1509
|
+
// the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
|
|
1510
|
+
// and we don't want to ignore those events
|
|
1511
|
+
actorScope.defer(() => {
|
|
1512
|
+
actorScope.stopChild(actorRef);
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Stops a child actor.
|
|
1517
|
+
*
|
|
1518
|
+
* @param actorRef The actor to stop.
|
|
1519
|
+
*/
|
|
1520
|
+
function stopChild(actorRef) {
|
|
1521
|
+
function stop(args, params) {
|
|
1522
|
+
{
|
|
1523
|
+
throw new Error(`This isn't supposed to be called`);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
stop.type = 'xstate.stopChild';
|
|
1527
|
+
stop.actorRef = actorRef;
|
|
1528
|
+
stop.resolve = resolveStop;
|
|
1529
|
+
stop.execute = executeStop;
|
|
1530
|
+
return stop;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
/**
|
|
1534
|
+
* Stops a child actor.
|
|
1535
|
+
*
|
|
1536
|
+
* @deprecated Use `stopChild(...)` instead
|
|
1537
|
+
* @alias
|
|
1538
|
+
*/
|
|
1539
|
+
const stop = stopChild;
|
|
1540
|
+
|
|
1467
1541
|
const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
1468
1542
|
function getChildren(stateNode) {
|
|
1469
1543
|
return Object.values(stateNode.states).filter(sn => sn.type !== 'history');
|
|
@@ -2588,70 +2662,4 @@ function persistContext(contextPart) {
|
|
|
2588
2662
|
return copy ?? contextPart;
|
|
2589
2663
|
}
|
|
2590
2664
|
|
|
2591
|
-
|
|
2592
|
-
event: eventOrExpr,
|
|
2593
|
-
id,
|
|
2594
|
-
delay
|
|
2595
|
-
}, {
|
|
2596
|
-
internalQueue
|
|
2597
|
-
}) {
|
|
2598
|
-
const delaysMap = snapshot.machine.implementations.delays;
|
|
2599
|
-
if (typeof eventOrExpr === 'string') {
|
|
2600
|
-
throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
|
|
2601
|
-
}
|
|
2602
|
-
const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
|
|
2603
|
-
let resolvedDelay;
|
|
2604
|
-
if (typeof delay === 'string') {
|
|
2605
|
-
const configDelay = delaysMap && delaysMap[delay];
|
|
2606
|
-
resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
|
|
2607
|
-
} else {
|
|
2608
|
-
resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
|
|
2609
|
-
}
|
|
2610
|
-
if (typeof resolvedDelay !== 'number') {
|
|
2611
|
-
internalQueue.push(resolvedEvent);
|
|
2612
|
-
}
|
|
2613
|
-
return [snapshot, {
|
|
2614
|
-
event: resolvedEvent,
|
|
2615
|
-
id,
|
|
2616
|
-
delay: resolvedDelay
|
|
2617
|
-
}];
|
|
2618
|
-
}
|
|
2619
|
-
function executeRaise(actorScope, params) {
|
|
2620
|
-
const {
|
|
2621
|
-
event,
|
|
2622
|
-
delay,
|
|
2623
|
-
id
|
|
2624
|
-
} = params;
|
|
2625
|
-
if (typeof delay === 'number') {
|
|
2626
|
-
actorScope.defer(() => {
|
|
2627
|
-
const self = actorScope.self;
|
|
2628
|
-
actorScope.system.scheduler.schedule(self, self, event, delay, id);
|
|
2629
|
-
});
|
|
2630
|
-
return;
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
/**
|
|
2634
|
-
* Raises an event. This places the event in the internal event queue, so that
|
|
2635
|
-
* the event is immediately consumed by the machine in the current step.
|
|
2636
|
-
*
|
|
2637
|
-
* @param eventType The event to raise.
|
|
2638
|
-
*/
|
|
2639
|
-
function raise(eventOrExpr, options) {
|
|
2640
|
-
if (executingCustomAction) {
|
|
2641
|
-
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.');
|
|
2642
|
-
}
|
|
2643
|
-
function raise(args, params) {
|
|
2644
|
-
{
|
|
2645
|
-
throw new Error(`This isn't supposed to be called`);
|
|
2646
|
-
}
|
|
2647
|
-
}
|
|
2648
|
-
raise.type = 'xstate.raise';
|
|
2649
|
-
raise.event = eventOrExpr;
|
|
2650
|
-
raise.id = options?.id;
|
|
2651
|
-
raise.delay = options?.delay;
|
|
2652
|
-
raise.resolve = resolveRaise;
|
|
2653
|
-
raise.execute = executeRaise;
|
|
2654
|
-
return raise;
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
export { $$ACTOR_TYPE as $, createActor as A, Actor as B, interpret as C, isMachineSnapshot as D, and as E, not as F, or as G, stateIn as H, getAllOwnEventDescriptors as I, matchesState as J, pathToStateValue as K, toObserver as L, cancel as M, NULL_EVENT as N, raise as O, spawnChild as P, stop as Q, stopChild as R, STATE_DELIMITER as S, ProcessingStatus as T, cloneMachineSnapshot as U, executingCustomAction as V, XSTATE_ERROR as W, XSTATE_STOP as X, createErrorActorEvent as Y, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, macrostep as n, transitionNode as o, resolveActionsAndContext as p, createInitEvent as q, resolveStateValue as r, microstep as s, toArray as t, getInitialStateNodes as u, toStatePath as v, isStateId as w, getStateNodeByPath as x, getPersistedSnapshot as y, resolveReferencedActor as z };
|
|
2665
|
+
export { $$ACTOR_TYPE as $, createActor as A, isMachineSnapshot as B, Actor as C, interpret as D, and as E, not as F, or as G, stateIn as H, getAllOwnEventDescriptors as I, matchesState as J, pathToStateValue as K, toObserver as L, cancel as M, NULL_EVENT as N, raise as O, spawnChild as P, stop as Q, stopChild as R, STATE_DELIMITER as S, ProcessingStatus as T, executingCustomAction as U, cloneMachineSnapshot as V, XSTATE_ERROR as W, XSTATE_STOP as X, createErrorActorEvent as Y, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, macrostep as n, transitionNode as o, resolveActionsAndContext as p, createInitEvent as q, resolveStateValue as r, microstep as s, toArray as t, getInitialStateNodes as u, toStatePath as v, isStateId as w, getStateNodeByPath as x, getPersistedSnapshot as y, resolveReferencedActor as z };
|