xstate 5.18.0 → 5.18.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.
Files changed (32) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  6. package/actors/dist/xstate-actors.cjs.js +1 -1
  7. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.esm.js +1 -1
  9. package/actors/dist/xstate-actors.esm.js +1 -1
  10. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  11. package/dist/declarations/src/State.d.ts +1 -1
  12. package/dist/declarations/src/createActor.d.ts +3 -4
  13. package/dist/declarations/src/index.d.ts +5 -5
  14. package/dist/{log-f7dcaa97.cjs.js → log-098d2ed5.cjs.js} +1 -1
  15. package/dist/{log-54d038f7.esm.js → log-a2c94240.esm.js} +1 -1
  16. package/dist/{log-4f8360d3.development.esm.js → log-c92a07bc.development.esm.js} +1 -1
  17. package/dist/{log-40d606d3.development.cjs.js → log-d26be77d.development.cjs.js} +1 -1
  18. package/dist/{State-34039d2a.development.esm.js → raise-206d3d29.development.esm.js} +206 -206
  19. package/dist/{State-cdbc7940.esm.js → raise-c0e3c984.esm.js} +191 -191
  20. package/dist/xstate.cjs.js +102 -102
  21. package/dist/xstate.development.cjs.js +102 -102
  22. package/dist/xstate.development.esm.js +98 -98
  23. package/dist/xstate.esm.js +98 -98
  24. package/dist/xstate.umd.min.js +1 -1
  25. package/dist/xstate.umd.min.js.map +1 -1
  26. package/guards/dist/xstate-guards.cjs.js +1 -1
  27. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  28. package/guards/dist/xstate-guards.development.esm.js +1 -1
  29. package/guards/dist/xstate-guards.esm.js +1 -1
  30. package/package.json +1 -1
  31. package/dist/{State-a2464a1e.development.cjs.js → raise-830a98f7.development.cjs.js} +205 -205
  32. package/dist/{State-30c95050.cjs.js → raise-cde45f56.cjs.js} +190 -190
@@ -1122,6 +1122,136 @@ function cancel(sendId) {
1122
1122
  return cancel;
1123
1123
  }
1124
1124
 
1125
+ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
1126
+ id,
1127
+ systemId,
1128
+ src,
1129
+ input,
1130
+ syncSnapshot
1131
+ }) {
1132
+ const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
1133
+ const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
1134
+ let actorRef;
1135
+ if (logic) {
1136
+ actorRef = createActor(logic, {
1137
+ id: resolvedId,
1138
+ src,
1139
+ parent: actorScope.self,
1140
+ syncSnapshot,
1141
+ systemId,
1142
+ input: typeof input === 'function' ? input({
1143
+ context: snapshot.context,
1144
+ event: actionArgs.event,
1145
+ self: actorScope.self
1146
+ }) : input
1147
+ });
1148
+ }
1149
+ return [cloneMachineSnapshot(snapshot, {
1150
+ children: {
1151
+ ...snapshot.children,
1152
+ [resolvedId]: actorRef
1153
+ }
1154
+ }), {
1155
+ id,
1156
+ actorRef
1157
+ }];
1158
+ }
1159
+ function executeSpawn(actorScope, {
1160
+ id,
1161
+ actorRef
1162
+ }) {
1163
+ if (!actorRef) {
1164
+ return;
1165
+ }
1166
+ actorScope.defer(() => {
1167
+ if (actorRef._processingStatus === ProcessingStatus.Stopped) {
1168
+ return;
1169
+ }
1170
+ actorRef.start();
1171
+ });
1172
+ }
1173
+ function spawnChild(...[src, {
1174
+ id,
1175
+ systemId,
1176
+ input,
1177
+ syncSnapshot = false
1178
+ } = {}]) {
1179
+ function spawnChild(args, params) {
1180
+ }
1181
+ spawnChild.type = 'snapshot.spawnChild';
1182
+ spawnChild.id = id;
1183
+ spawnChild.systemId = systemId;
1184
+ spawnChild.src = src;
1185
+ spawnChild.input = input;
1186
+ spawnChild.syncSnapshot = syncSnapshot;
1187
+ spawnChild.resolve = resolveSpawn;
1188
+ spawnChild.execute = executeSpawn;
1189
+ return spawnChild;
1190
+ }
1191
+
1192
+ function resolveStop(_, snapshot, args, actionParams, {
1193
+ actorRef
1194
+ }) {
1195
+ const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
1196
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
1197
+ let children = snapshot.children;
1198
+ if (resolvedActorRef) {
1199
+ children = {
1200
+ ...children
1201
+ };
1202
+ delete children[resolvedActorRef.id];
1203
+ }
1204
+ return [cloneMachineSnapshot(snapshot, {
1205
+ children
1206
+ }), resolvedActorRef];
1207
+ }
1208
+ function executeStop(actorScope, actorRef) {
1209
+ if (!actorRef) {
1210
+ return;
1211
+ }
1212
+
1213
+ // we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
1214
+ // since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
1215
+ // this could throw on `systemId` collision, for example, when dealing with reentering transitions
1216
+ actorScope.system._unregister(actorRef);
1217
+
1218
+ // this allows us to prevent an actor from being started if it gets stopped within the same macrostep
1219
+ // this can happen, for example, when the invoking state is being exited immediately by an always transition
1220
+ if (actorRef._processingStatus !== ProcessingStatus.Running) {
1221
+ actorScope.stopChild(actorRef);
1222
+ return;
1223
+ }
1224
+ // stopping a child enqueues a stop event in the child actor's mailbox
1225
+ // we need for all of the already enqueued events to be processed before we stop the child
1226
+ // the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
1227
+ // and we don't want to ignore those events
1228
+ actorScope.defer(() => {
1229
+ actorScope.stopChild(actorRef);
1230
+ });
1231
+ }
1232
+ /**
1233
+ * Stops a child actor.
1234
+ *
1235
+ * @param actorRef The actor to stop.
1236
+ */
1237
+ function stopChild(actorRef) {
1238
+ function stop(args, params) {
1239
+ }
1240
+ stop.type = 'xstate.stopChild';
1241
+ stop.actorRef = actorRef;
1242
+ stop.resolve = resolveStop;
1243
+ stop.execute = executeStop;
1244
+ return stop;
1245
+ }
1246
+
1247
+ /**
1248
+ * Stops a child actor.
1249
+ *
1250
+ * @deprecated Use `stopChild(...)` instead
1251
+ * @alias
1252
+ */
1253
+ const stop = stopChild;
1254
+
1125
1255
  function checkStateIn(snapshot, _, {
1126
1256
  stateValue
1127
1257
  }) {
@@ -1310,196 +1440,6 @@ function evaluateGuard(guard, context, event, snapshot) {
1310
1440
  );
1311
1441
  }
1312
1442
 
1313
- function resolveRaise(_, snapshot, args, actionParams, {
1314
- event: eventOrExpr,
1315
- id,
1316
- delay
1317
- }, {
1318
- internalQueue
1319
- }) {
1320
- const delaysMap = snapshot.machine.implementations.delays;
1321
- if (typeof eventOrExpr === 'string') {
1322
- throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
1323
- }
1324
- const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
1325
- let resolvedDelay;
1326
- if (typeof delay === 'string') {
1327
- const configDelay = delaysMap && delaysMap[delay];
1328
- resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
1329
- } else {
1330
- resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
1331
- }
1332
- if (typeof resolvedDelay !== 'number') {
1333
- internalQueue.push(resolvedEvent);
1334
- }
1335
- return [snapshot, {
1336
- event: resolvedEvent,
1337
- id,
1338
- delay: resolvedDelay
1339
- }];
1340
- }
1341
- function executeRaise(actorScope, params) {
1342
- const {
1343
- event,
1344
- delay,
1345
- id
1346
- } = params;
1347
- if (typeof delay === 'number') {
1348
- actorScope.defer(() => {
1349
- const self = actorScope.self;
1350
- actorScope.system.scheduler.schedule(self, self, event, delay, id);
1351
- });
1352
- return;
1353
- }
1354
- }
1355
- /**
1356
- * Raises an event. This places the event in the internal event queue, so that
1357
- * the event is immediately consumed by the machine in the current step.
1358
- *
1359
- * @param eventType The event to raise.
1360
- */
1361
- function raise(eventOrExpr, options) {
1362
- function raise(args, params) {
1363
- }
1364
- raise.type = 'xstate.raise';
1365
- raise.event = eventOrExpr;
1366
- raise.id = options?.id;
1367
- raise.delay = options?.delay;
1368
- raise.resolve = resolveRaise;
1369
- raise.execute = executeRaise;
1370
- return raise;
1371
- }
1372
-
1373
- function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
1374
- id,
1375
- systemId,
1376
- src,
1377
- input,
1378
- syncSnapshot
1379
- }) {
1380
- const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
1381
- const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
1382
- let actorRef;
1383
- if (logic) {
1384
- actorRef = createActor(logic, {
1385
- id: resolvedId,
1386
- src,
1387
- parent: actorScope.self,
1388
- syncSnapshot,
1389
- systemId,
1390
- input: typeof input === 'function' ? input({
1391
- context: snapshot.context,
1392
- event: actionArgs.event,
1393
- self: actorScope.self
1394
- }) : input
1395
- });
1396
- }
1397
- return [cloneMachineSnapshot(snapshot, {
1398
- children: {
1399
- ...snapshot.children,
1400
- [resolvedId]: actorRef
1401
- }
1402
- }), {
1403
- id,
1404
- actorRef
1405
- }];
1406
- }
1407
- function executeSpawn(actorScope, {
1408
- id,
1409
- actorRef
1410
- }) {
1411
- if (!actorRef) {
1412
- return;
1413
- }
1414
- actorScope.defer(() => {
1415
- if (actorRef._processingStatus === ProcessingStatus.Stopped) {
1416
- return;
1417
- }
1418
- actorRef.start();
1419
- });
1420
- }
1421
- function spawnChild(...[src, {
1422
- id,
1423
- systemId,
1424
- input,
1425
- syncSnapshot = false
1426
- } = {}]) {
1427
- function spawnChild(args, params) {
1428
- }
1429
- spawnChild.type = 'snapshot.spawnChild';
1430
- spawnChild.id = id;
1431
- spawnChild.systemId = systemId;
1432
- spawnChild.src = src;
1433
- spawnChild.input = input;
1434
- spawnChild.syncSnapshot = syncSnapshot;
1435
- spawnChild.resolve = resolveSpawn;
1436
- spawnChild.execute = executeSpawn;
1437
- return spawnChild;
1438
- }
1439
-
1440
- function resolveStop(_, snapshot, args, actionParams, {
1441
- actorRef
1442
- }) {
1443
- const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
1444
- const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
1445
- let children = snapshot.children;
1446
- if (resolvedActorRef) {
1447
- children = {
1448
- ...children
1449
- };
1450
- delete children[resolvedActorRef.id];
1451
- }
1452
- return [cloneMachineSnapshot(snapshot, {
1453
- children
1454
- }), resolvedActorRef];
1455
- }
1456
- function executeStop(actorScope, actorRef) {
1457
- if (!actorRef) {
1458
- return;
1459
- }
1460
-
1461
- // we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
1462
- // since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
1463
- // this could throw on `systemId` collision, for example, when dealing with reentering transitions
1464
- actorScope.system._unregister(actorRef);
1465
-
1466
- // this allows us to prevent an actor from being started if it gets stopped within the same macrostep
1467
- // this can happen, for example, when the invoking state is being exited immediately by an always transition
1468
- if (actorRef._processingStatus !== ProcessingStatus.Running) {
1469
- actorScope.stopChild(actorRef);
1470
- return;
1471
- }
1472
- // stopping a child enqueues a stop event in the child actor's mailbox
1473
- // we need for all of the already enqueued events to be processed before we stop the child
1474
- // the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
1475
- // and we don't want to ignore those events
1476
- actorScope.defer(() => {
1477
- actorScope.stopChild(actorRef);
1478
- });
1479
- }
1480
- /**
1481
- * Stops a child actor.
1482
- *
1483
- * @param actorRef The actor to stop.
1484
- */
1485
- function stopChild(actorRef) {
1486
- function stop(args, params) {
1487
- }
1488
- stop.type = 'xstate.stopChild';
1489
- stop.actorRef = actorRef;
1490
- stop.resolve = resolveStop;
1491
- stop.execute = executeStop;
1492
- return stop;
1493
- }
1494
-
1495
- /**
1496
- * Stops a child actor.
1497
- *
1498
- * @deprecated Use `stopChild(...)` instead
1499
- * @alias
1500
- */
1501
- const stop = stopChild;
1502
-
1503
1443
  const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
1504
1444
  function getChildren(stateNode) {
1505
1445
  return Object.values(stateNode.states).filter(sn => sn.type !== 'history');
@@ -2604,6 +2544,66 @@ function persistContext(contextPart) {
2604
2544
  return copy ?? contextPart;
2605
2545
  }
2606
2546
 
2547
+ function resolveRaise(_, snapshot, args, actionParams, {
2548
+ event: eventOrExpr,
2549
+ id,
2550
+ delay
2551
+ }, {
2552
+ internalQueue
2553
+ }) {
2554
+ const delaysMap = snapshot.machine.implementations.delays;
2555
+ if (typeof eventOrExpr === 'string') {
2556
+ throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2557
+ }
2558
+ const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
2559
+ let resolvedDelay;
2560
+ if (typeof delay === 'string') {
2561
+ const configDelay = delaysMap && delaysMap[delay];
2562
+ resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
2563
+ } else {
2564
+ resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
2565
+ }
2566
+ if (typeof resolvedDelay !== 'number') {
2567
+ internalQueue.push(resolvedEvent);
2568
+ }
2569
+ return [snapshot, {
2570
+ event: resolvedEvent,
2571
+ id,
2572
+ delay: resolvedDelay
2573
+ }];
2574
+ }
2575
+ function executeRaise(actorScope, params) {
2576
+ const {
2577
+ event,
2578
+ delay,
2579
+ id
2580
+ } = params;
2581
+ if (typeof delay === 'number') {
2582
+ actorScope.defer(() => {
2583
+ const self = actorScope.self;
2584
+ actorScope.system.scheduler.schedule(self, self, event, delay, id);
2585
+ });
2586
+ return;
2587
+ }
2588
+ }
2589
+ /**
2590
+ * Raises an event. This places the event in the internal event queue, so that
2591
+ * the event is immediately consumed by the machine in the current step.
2592
+ *
2593
+ * @param eventType The event to raise.
2594
+ */
2595
+ function raise(eventOrExpr, options) {
2596
+ function raise(args, params) {
2597
+ }
2598
+ raise.type = 'xstate.raise';
2599
+ raise.event = eventOrExpr;
2600
+ raise.id = options?.id;
2601
+ raise.delay = options?.delay;
2602
+ raise.resolve = resolveRaise;
2603
+ raise.execute = executeRaise;
2604
+ return raise;
2605
+ }
2606
+
2607
2607
  exports.$$ACTOR_TYPE = $$ACTOR_TYPE;
2608
2608
  exports.Actor = Actor;
2609
2609
  exports.NULL_EVENT = NULL_EVENT;