xstate 5.18.0 → 5.18.2

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 (55) hide show
  1. package/actions/dist/xstate-actions.cjs.d.mts +1 -1
  2. package/actions/dist/xstate-actions.cjs.d.ts +1 -1
  3. package/actions/dist/xstate-actions.cjs.js +2 -2
  4. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  5. package/actions/dist/xstate-actions.development.esm.js +2 -2
  6. package/actions/dist/xstate-actions.esm.js +2 -2
  7. package/actions/dist/xstate-actions.umd.min.js +1 -1
  8. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  9. package/actors/dist/xstate-actors.cjs.d.mts +1 -1
  10. package/actors/dist/xstate-actors.cjs.d.ts +1 -1
  11. package/actors/dist/xstate-actors.cjs.js +1 -1
  12. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  13. package/actors/dist/xstate-actors.development.esm.js +1 -1
  14. package/actors/dist/xstate-actors.esm.js +1 -1
  15. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  16. package/dev/dist/xstate-dev.cjs.d.mts +1 -1
  17. package/dev/dist/xstate-dev.cjs.d.ts +1 -1
  18. package/dist/declarations/src/State.d.ts +1 -1
  19. package/dist/declarations/src/createActor.d.ts +3 -4
  20. package/dist/declarations/src/index.d.ts +5 -5
  21. package/dist/declarations/src/inspection.d.ts +2 -2
  22. package/dist/{log-54d038f7.esm.js → log-15d0f775.esm.js} +9 -2
  23. package/dist/{log-4f8360d3.development.esm.js → log-38475d87.development.esm.js} +9 -2
  24. package/dist/{log-f7dcaa97.cjs.js → log-98fcce74.cjs.js} +9 -2
  25. package/dist/{log-40d606d3.development.cjs.js → log-b7ed1b61.development.cjs.js} +9 -2
  26. package/dist/{State-cdbc7940.esm.js → raise-0f7cf128.esm.js} +191 -192
  27. package/dist/{State-34039d2a.development.esm.js → raise-5ea71f04.development.esm.js} +206 -207
  28. package/dist/{State-30c95050.cjs.js → raise-b1e0b9a9.cjs.js} +190 -191
  29. package/dist/{State-a2464a1e.development.cjs.js → raise-e919c5d4.development.cjs.js} +205 -206
  30. package/dist/xstate.cjs.d.mts +1 -1
  31. package/dist/xstate.cjs.d.ts +1 -1
  32. package/dist/xstate.cjs.js +106 -104
  33. package/dist/xstate.development.cjs.js +106 -104
  34. package/dist/xstate.development.esm.js +102 -100
  35. package/dist/xstate.esm.js +102 -100
  36. package/dist/xstate.umd.min.js +1 -1
  37. package/dist/xstate.umd.min.js.map +1 -1
  38. package/guards/dist/xstate-guards.cjs.d.mts +1 -1
  39. package/guards/dist/xstate-guards.cjs.d.ts +1 -1
  40. package/guards/dist/xstate-guards.cjs.js +1 -1
  41. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  42. package/guards/dist/xstate-guards.development.esm.js +1 -1
  43. package/guards/dist/xstate-guards.esm.js +1 -1
  44. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  45. package/package.json +7 -7
  46. package/actions/dist/xstate-actions.cjs.d.mts.map +0 -1
  47. package/actions/dist/xstate-actions.cjs.d.ts.map +0 -1
  48. package/actors/dist/xstate-actors.cjs.d.mts.map +0 -1
  49. package/actors/dist/xstate-actors.cjs.d.ts.map +0 -1
  50. package/dev/dist/xstate-dev.cjs.d.mts.map +0 -1
  51. package/dev/dist/xstate-dev.cjs.d.ts.map +0 -1
  52. package/dist/xstate.cjs.d.mts.map +0 -1
  53. package/dist/xstate.cjs.d.ts.map +0 -1
  54. package/guards/dist/xstate-guards.cjs.d.mts.map +0 -1
  55. package/guards/dist/xstate-guards.cjs.d.ts.map +0 -1
@@ -1139,6 +1139,145 @@ function cancel(sendId) {
1139
1139
  return cancel;
1140
1140
  }
1141
1141
 
1142
+ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
1143
+ id,
1144
+ systemId,
1145
+ src,
1146
+ input,
1147
+ syncSnapshot
1148
+ }) {
1149
+ const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
1150
+ const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
1151
+ let actorRef;
1152
+ if (logic) {
1153
+ actorRef = createActor(logic, {
1154
+ id: resolvedId,
1155
+ src,
1156
+ parent: actorScope.self,
1157
+ syncSnapshot,
1158
+ systemId,
1159
+ input: typeof input === 'function' ? input({
1160
+ context: snapshot.context,
1161
+ event: actionArgs.event,
1162
+ self: actorScope.self
1163
+ }) : input
1164
+ });
1165
+ }
1166
+ if (!actorRef) {
1167
+ console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
1168
+ }
1169
+ return [cloneMachineSnapshot(snapshot, {
1170
+ children: {
1171
+ ...snapshot.children,
1172
+ [resolvedId]: actorRef
1173
+ }
1174
+ }), {
1175
+ id,
1176
+ actorRef
1177
+ }];
1178
+ }
1179
+ function executeSpawn(actorScope, {
1180
+ id,
1181
+ actorRef
1182
+ }) {
1183
+ if (!actorRef) {
1184
+ return;
1185
+ }
1186
+ actorScope.defer(() => {
1187
+ if (actorRef._processingStatus === ProcessingStatus.Stopped) {
1188
+ return;
1189
+ }
1190
+ actorRef.start();
1191
+ });
1192
+ }
1193
+ function spawnChild(...[src, {
1194
+ id,
1195
+ systemId,
1196
+ input,
1197
+ syncSnapshot = false
1198
+ } = {}]) {
1199
+ function spawnChild(args, params) {
1200
+ {
1201
+ throw new Error(`This isn't supposed to be called`);
1202
+ }
1203
+ }
1204
+ spawnChild.type = 'snapshot.spawnChild';
1205
+ spawnChild.id = id;
1206
+ spawnChild.systemId = systemId;
1207
+ spawnChild.src = src;
1208
+ spawnChild.input = input;
1209
+ spawnChild.syncSnapshot = syncSnapshot;
1210
+ spawnChild.resolve = resolveSpawn;
1211
+ spawnChild.execute = executeSpawn;
1212
+ return spawnChild;
1213
+ }
1214
+
1215
+ function resolveStop(_, snapshot, args, actionParams, {
1216
+ actorRef
1217
+ }) {
1218
+ const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
1219
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
1220
+ let children = snapshot.children;
1221
+ if (resolvedActorRef) {
1222
+ children = {
1223
+ ...children
1224
+ };
1225
+ delete children[resolvedActorRef.id];
1226
+ }
1227
+ return [cloneMachineSnapshot(snapshot, {
1228
+ children
1229
+ }), resolvedActorRef];
1230
+ }
1231
+ function executeStop(actorScope, actorRef) {
1232
+ if (!actorRef) {
1233
+ return;
1234
+ }
1235
+
1236
+ // we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
1237
+ // since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
1238
+ // this could throw on `systemId` collision, for example, when dealing with reentering transitions
1239
+ actorScope.system._unregister(actorRef);
1240
+
1241
+ // this allows us to prevent an actor from being started if it gets stopped within the same macrostep
1242
+ // this can happen, for example, when the invoking state is being exited immediately by an always transition
1243
+ if (actorRef._processingStatus !== ProcessingStatus.Running) {
1244
+ actorScope.stopChild(actorRef);
1245
+ return;
1246
+ }
1247
+ // stopping a child enqueues a stop event in the child actor's mailbox
1248
+ // we need for all of the already enqueued events to be processed before we stop the child
1249
+ // the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
1250
+ // and we don't want to ignore those events
1251
+ actorScope.defer(() => {
1252
+ actorScope.stopChild(actorRef);
1253
+ });
1254
+ }
1255
+ /**
1256
+ * Stops a child actor.
1257
+ *
1258
+ * @param actorRef The actor to stop.
1259
+ */
1260
+ function stopChild(actorRef) {
1261
+ function stop(args, params) {
1262
+ {
1263
+ throw new Error(`This isn't supposed to be called`);
1264
+ }
1265
+ }
1266
+ stop.type = 'xstate.stopChild';
1267
+ stop.actorRef = actorRef;
1268
+ stop.resolve = resolveStop;
1269
+ stop.execute = executeStop;
1270
+ return stop;
1271
+ }
1272
+
1273
+ /**
1274
+ * Stops a child actor.
1275
+ *
1276
+ * @deprecated Use `stopChild(...)` instead
1277
+ * @alias
1278
+ */
1279
+ const stop = stopChild;
1280
+
1142
1281
  function checkStateIn(snapshot, _, {
1143
1282
  stateValue
1144
1283
  }) {
@@ -1335,211 +1474,6 @@ function evaluateGuard(guard, context, event, snapshot) {
1335
1474
  );
1336
1475
  }
1337
1476
 
1338
- function resolveRaise(_, snapshot, args, actionParams, {
1339
- event: eventOrExpr,
1340
- id,
1341
- delay
1342
- }, {
1343
- internalQueue
1344
- }) {
1345
- const delaysMap = snapshot.machine.implementations.delays;
1346
- if (typeof eventOrExpr === 'string') {
1347
- throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
1348
- }
1349
- const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
1350
- let resolvedDelay;
1351
- if (typeof delay === 'string') {
1352
- const configDelay = delaysMap && delaysMap[delay];
1353
- resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
1354
- } else {
1355
- resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
1356
- }
1357
- if (typeof resolvedDelay !== 'number') {
1358
- internalQueue.push(resolvedEvent);
1359
- }
1360
- return [snapshot, {
1361
- event: resolvedEvent,
1362
- id,
1363
- delay: resolvedDelay
1364
- }];
1365
- }
1366
- function executeRaise(actorScope, params) {
1367
- const {
1368
- event,
1369
- delay,
1370
- id
1371
- } = params;
1372
- if (typeof delay === 'number') {
1373
- actorScope.defer(() => {
1374
- const self = actorScope.self;
1375
- actorScope.system.scheduler.schedule(self, self, event, delay, id);
1376
- });
1377
- return;
1378
- }
1379
- }
1380
- /**
1381
- * Raises an event. This places the event in the internal event queue, so that
1382
- * the event is immediately consumed by the machine in the current step.
1383
- *
1384
- * @param eventType The event to raise.
1385
- */
1386
- function raise(eventOrExpr, options) {
1387
- if (exports.executingCustomAction) {
1388
- 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.');
1389
- }
1390
- function raise(args, params) {
1391
- {
1392
- throw new Error(`This isn't supposed to be called`);
1393
- }
1394
- }
1395
- raise.type = 'xstate.raise';
1396
- raise.event = eventOrExpr;
1397
- raise.id = options?.id;
1398
- raise.delay = options?.delay;
1399
- raise.resolve = resolveRaise;
1400
- raise.execute = executeRaise;
1401
- return raise;
1402
- }
1403
-
1404
- function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
1405
- id,
1406
- systemId,
1407
- src,
1408
- input,
1409
- syncSnapshot
1410
- }) {
1411
- const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
1412
- const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
1413
- let actorRef;
1414
- if (logic) {
1415
- actorRef = createActor(logic, {
1416
- id: resolvedId,
1417
- src,
1418
- parent: actorScope.self,
1419
- syncSnapshot,
1420
- systemId,
1421
- input: typeof input === 'function' ? input({
1422
- context: snapshot.context,
1423
- event: actionArgs.event,
1424
- self: actorScope.self
1425
- }) : input
1426
- });
1427
- }
1428
- if (!actorRef) {
1429
- console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
1430
- }
1431
- return [cloneMachineSnapshot(snapshot, {
1432
- children: {
1433
- ...snapshot.children,
1434
- [resolvedId]: actorRef
1435
- }
1436
- }), {
1437
- id,
1438
- actorRef
1439
- }];
1440
- }
1441
- function executeSpawn(actorScope, {
1442
- id,
1443
- actorRef
1444
- }) {
1445
- if (!actorRef) {
1446
- return;
1447
- }
1448
- actorScope.defer(() => {
1449
- if (actorRef._processingStatus === ProcessingStatus.Stopped) {
1450
- return;
1451
- }
1452
- actorRef.start();
1453
- });
1454
- }
1455
- function spawnChild(...[src, {
1456
- id,
1457
- systemId,
1458
- input,
1459
- syncSnapshot = false
1460
- } = {}]) {
1461
- function spawnChild(args, params) {
1462
- {
1463
- throw new Error(`This isn't supposed to be called`);
1464
- }
1465
- }
1466
- spawnChild.type = 'snapshot.spawnChild';
1467
- spawnChild.id = id;
1468
- spawnChild.systemId = systemId;
1469
- spawnChild.src = src;
1470
- spawnChild.input = input;
1471
- spawnChild.syncSnapshot = syncSnapshot;
1472
- spawnChild.resolve = resolveSpawn;
1473
- spawnChild.execute = executeSpawn;
1474
- return spawnChild;
1475
- }
1476
-
1477
- function resolveStop(_, snapshot, args, actionParams, {
1478
- actorRef
1479
- }) {
1480
- const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
1481
- const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
1482
- let children = snapshot.children;
1483
- if (resolvedActorRef) {
1484
- children = {
1485
- ...children
1486
- };
1487
- delete children[resolvedActorRef.id];
1488
- }
1489
- return [cloneMachineSnapshot(snapshot, {
1490
- children
1491
- }), resolvedActorRef];
1492
- }
1493
- function executeStop(actorScope, actorRef) {
1494
- if (!actorRef) {
1495
- return;
1496
- }
1497
-
1498
- // we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
1499
- // since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
1500
- // this could throw on `systemId` collision, for example, when dealing with reentering transitions
1501
- actorScope.system._unregister(actorRef);
1502
-
1503
- // this allows us to prevent an actor from being started if it gets stopped within the same macrostep
1504
- // this can happen, for example, when the invoking state is being exited immediately by an always transition
1505
- if (actorRef._processingStatus !== ProcessingStatus.Running) {
1506
- actorScope.stopChild(actorRef);
1507
- return;
1508
- }
1509
- // stopping a child enqueues a stop event in the child actor's mailbox
1510
- // we need for all of the already enqueued events to be processed before we stop the child
1511
- // the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
1512
- // and we don't want to ignore those events
1513
- actorScope.defer(() => {
1514
- actorScope.stopChild(actorRef);
1515
- });
1516
- }
1517
- /**
1518
- * Stops a child actor.
1519
- *
1520
- * @param actorRef The actor to stop.
1521
- */
1522
- function stopChild(actorRef) {
1523
- function stop(args, params) {
1524
- {
1525
- throw new Error(`This isn't supposed to be called`);
1526
- }
1527
- }
1528
- stop.type = 'xstate.stopChild';
1529
- stop.actorRef = actorRef;
1530
- stop.resolve = resolveStop;
1531
- stop.execute = executeStop;
1532
- return stop;
1533
- }
1534
-
1535
- /**
1536
- * Stops a child actor.
1537
- *
1538
- * @deprecated Use `stopChild(...)` instead
1539
- * @alias
1540
- */
1541
- const stop = stopChild;
1542
-
1543
1477
  const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
1544
1478
  function getChildren(stateNode) {
1545
1479
  return Object.values(stateNode.states).filter(sn => sn.type !== 'history');
@@ -1599,7 +1533,6 @@ function getValueFromAdj(baseNode, adjList) {
1599
1533
  if (!childStateNodes) {
1600
1534
  return {}; // todo: fix?
1601
1535
  }
1602
-
1603
1536
  if (baseNode.type === 'compound') {
1604
1537
  const childStateNode = childStateNodes[0];
1605
1538
  if (childStateNode) {
@@ -2664,6 +2597,72 @@ function persistContext(contextPart) {
2664
2597
  return copy ?? contextPart;
2665
2598
  }
2666
2599
 
2600
+ function resolveRaise(_, snapshot, args, actionParams, {
2601
+ event: eventOrExpr,
2602
+ id,
2603
+ delay
2604
+ }, {
2605
+ internalQueue
2606
+ }) {
2607
+ const delaysMap = snapshot.machine.implementations.delays;
2608
+ if (typeof eventOrExpr === 'string') {
2609
+ throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2610
+ }
2611
+ const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
2612
+ let resolvedDelay;
2613
+ if (typeof delay === 'string') {
2614
+ const configDelay = delaysMap && delaysMap[delay];
2615
+ resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
2616
+ } else {
2617
+ resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
2618
+ }
2619
+ if (typeof resolvedDelay !== 'number') {
2620
+ internalQueue.push(resolvedEvent);
2621
+ }
2622
+ return [snapshot, {
2623
+ event: resolvedEvent,
2624
+ id,
2625
+ delay: resolvedDelay
2626
+ }];
2627
+ }
2628
+ function executeRaise(actorScope, params) {
2629
+ const {
2630
+ event,
2631
+ delay,
2632
+ id
2633
+ } = params;
2634
+ if (typeof delay === 'number') {
2635
+ actorScope.defer(() => {
2636
+ const self = actorScope.self;
2637
+ actorScope.system.scheduler.schedule(self, self, event, delay, id);
2638
+ });
2639
+ return;
2640
+ }
2641
+ }
2642
+ /**
2643
+ * Raises an event. This places the event in the internal event queue, so that
2644
+ * the event is immediately consumed by the machine in the current step.
2645
+ *
2646
+ * @param eventType The event to raise.
2647
+ */
2648
+ function raise(eventOrExpr, options) {
2649
+ if (exports.executingCustomAction) {
2650
+ console.warn('Custom actions should not call `raise()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
2651
+ }
2652
+ function raise(args, params) {
2653
+ {
2654
+ throw new Error(`This isn't supposed to be called`);
2655
+ }
2656
+ }
2657
+ raise.type = 'xstate.raise';
2658
+ raise.event = eventOrExpr;
2659
+ raise.id = options?.id;
2660
+ raise.delay = options?.delay;
2661
+ raise.resolve = resolveRaise;
2662
+ raise.execute = executeRaise;
2663
+ return raise;
2664
+ }
2665
+
2667
2666
  exports.$$ACTOR_TYPE = $$ACTOR_TYPE;
2668
2667
  exports.Actor = Actor;
2669
2668
  exports.NULL_EVENT = NULL_EVENT;
@@ -1,2 +1,2 @@
1
1
  export * from "./declarations/src/index.js";
2
- //# sourceMappingURL=xstate.cjs.d.mts.map
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieHN0YXRlLmNqcy5kLm10cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
@@ -1,2 +1,2 @@
1
1
  export * from "./declarations/src/index";
2
- //# sourceMappingURL=xstate.cjs.d.ts.map
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoieHN0YXRlLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==