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
@@ -1137,6 +1137,145 @@ function cancel(sendId) {
1137
1137
  return cancel;
1138
1138
  }
1139
1139
 
1140
+ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
1141
+ id,
1142
+ systemId,
1143
+ src,
1144
+ input,
1145
+ syncSnapshot
1146
+ }) {
1147
+ const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
1148
+ const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
1149
+ let actorRef;
1150
+ if (logic) {
1151
+ actorRef = createActor(logic, {
1152
+ id: resolvedId,
1153
+ src,
1154
+ parent: actorScope.self,
1155
+ syncSnapshot,
1156
+ systemId,
1157
+ input: typeof input === 'function' ? input({
1158
+ context: snapshot.context,
1159
+ event: actionArgs.event,
1160
+ self: actorScope.self
1161
+ }) : input
1162
+ });
1163
+ }
1164
+ if (!actorRef) {
1165
+ console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
1166
+ }
1167
+ return [cloneMachineSnapshot(snapshot, {
1168
+ children: {
1169
+ ...snapshot.children,
1170
+ [resolvedId]: actorRef
1171
+ }
1172
+ }), {
1173
+ id,
1174
+ actorRef
1175
+ }];
1176
+ }
1177
+ function executeSpawn(actorScope, {
1178
+ id,
1179
+ actorRef
1180
+ }) {
1181
+ if (!actorRef) {
1182
+ return;
1183
+ }
1184
+ actorScope.defer(() => {
1185
+ if (actorRef._processingStatus === ProcessingStatus.Stopped) {
1186
+ return;
1187
+ }
1188
+ actorRef.start();
1189
+ });
1190
+ }
1191
+ function spawnChild(...[src, {
1192
+ id,
1193
+ systemId,
1194
+ input,
1195
+ syncSnapshot = false
1196
+ } = {}]) {
1197
+ function spawnChild(args, params) {
1198
+ {
1199
+ throw new Error(`This isn't supposed to be called`);
1200
+ }
1201
+ }
1202
+ spawnChild.type = 'snapshot.spawnChild';
1203
+ spawnChild.id = id;
1204
+ spawnChild.systemId = systemId;
1205
+ spawnChild.src = src;
1206
+ spawnChild.input = input;
1207
+ spawnChild.syncSnapshot = syncSnapshot;
1208
+ spawnChild.resolve = resolveSpawn;
1209
+ spawnChild.execute = executeSpawn;
1210
+ return spawnChild;
1211
+ }
1212
+
1213
+ function resolveStop(_, snapshot, args, actionParams, {
1214
+ actorRef
1215
+ }) {
1216
+ const actorRefOrString = typeof actorRef === 'function' ? actorRef(args, actionParams) : actorRef;
1217
+ const resolvedActorRef = typeof actorRefOrString === 'string' ? snapshot.children[actorRefOrString] : actorRefOrString;
1218
+ let children = snapshot.children;
1219
+ if (resolvedActorRef) {
1220
+ children = {
1221
+ ...children
1222
+ };
1223
+ delete children[resolvedActorRef.id];
1224
+ }
1225
+ return [cloneMachineSnapshot(snapshot, {
1226
+ children
1227
+ }), resolvedActorRef];
1228
+ }
1229
+ function executeStop(actorScope, actorRef) {
1230
+ if (!actorRef) {
1231
+ return;
1232
+ }
1233
+
1234
+ // we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
1235
+ // since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
1236
+ // this could throw on `systemId` collision, for example, when dealing with reentering transitions
1237
+ actorScope.system._unregister(actorRef);
1238
+
1239
+ // this allows us to prevent an actor from being started if it gets stopped within the same macrostep
1240
+ // this can happen, for example, when the invoking state is being exited immediately by an always transition
1241
+ if (actorRef._processingStatus !== ProcessingStatus.Running) {
1242
+ actorScope.stopChild(actorRef);
1243
+ return;
1244
+ }
1245
+ // stopping a child enqueues a stop event in the child actor's mailbox
1246
+ // we need for all of the already enqueued events to be processed before we stop the child
1247
+ // the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
1248
+ // and we don't want to ignore those events
1249
+ actorScope.defer(() => {
1250
+ actorScope.stopChild(actorRef);
1251
+ });
1252
+ }
1253
+ /**
1254
+ * Stops a child actor.
1255
+ *
1256
+ * @param actorRef The actor to stop.
1257
+ */
1258
+ function stopChild(actorRef) {
1259
+ function stop(args, params) {
1260
+ {
1261
+ throw new Error(`This isn't supposed to be called`);
1262
+ }
1263
+ }
1264
+ stop.type = 'xstate.stopChild';
1265
+ stop.actorRef = actorRef;
1266
+ stop.resolve = resolveStop;
1267
+ stop.execute = executeStop;
1268
+ return stop;
1269
+ }
1270
+
1271
+ /**
1272
+ * Stops a child actor.
1273
+ *
1274
+ * @deprecated Use `stopChild(...)` instead
1275
+ * @alias
1276
+ */
1277
+ const stop = stopChild;
1278
+
1140
1279
  function checkStateIn(snapshot, _, {
1141
1280
  stateValue
1142
1281
  }) {
@@ -1333,211 +1472,6 @@ function evaluateGuard(guard, context, event, snapshot) {
1333
1472
  );
1334
1473
  }
1335
1474
 
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
-
1541
1475
  const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
1542
1476
  function getChildren(stateNode) {
1543
1477
  return Object.values(stateNode.states).filter(sn => sn.type !== 'history');
@@ -2662,4 +2596,70 @@ function persistContext(contextPart) {
2662
2596
  return copy ?? contextPart;
2663
2597
  }
2664
2598
 
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 };
2599
+ function resolveRaise(_, snapshot, args, actionParams, {
2600
+ event: eventOrExpr,
2601
+ id,
2602
+ delay
2603
+ }, {
2604
+ internalQueue
2605
+ }) {
2606
+ const delaysMap = snapshot.machine.implementations.delays;
2607
+ if (typeof eventOrExpr === 'string') {
2608
+ throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2609
+ }
2610
+ const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
2611
+ let resolvedDelay;
2612
+ if (typeof delay === 'string') {
2613
+ const configDelay = delaysMap && delaysMap[delay];
2614
+ resolvedDelay = typeof configDelay === 'function' ? configDelay(args, actionParams) : configDelay;
2615
+ } else {
2616
+ resolvedDelay = typeof delay === 'function' ? delay(args, actionParams) : delay;
2617
+ }
2618
+ if (typeof resolvedDelay !== 'number') {
2619
+ internalQueue.push(resolvedEvent);
2620
+ }
2621
+ return [snapshot, {
2622
+ event: resolvedEvent,
2623
+ id,
2624
+ delay: resolvedDelay
2625
+ }];
2626
+ }
2627
+ function executeRaise(actorScope, params) {
2628
+ const {
2629
+ event,
2630
+ delay,
2631
+ id
2632
+ } = params;
2633
+ if (typeof delay === 'number') {
2634
+ actorScope.defer(() => {
2635
+ const self = actorScope.self;
2636
+ actorScope.system.scheduler.schedule(self, self, event, delay, id);
2637
+ });
2638
+ return;
2639
+ }
2640
+ }
2641
+ /**
2642
+ * Raises an event. This places the event in the internal event queue, so that
2643
+ * the event is immediately consumed by the machine in the current step.
2644
+ *
2645
+ * @param eventType The event to raise.
2646
+ */
2647
+ function raise(eventOrExpr, options) {
2648
+ if (executingCustomAction) {
2649
+ 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.');
2650
+ }
2651
+ function raise(args, params) {
2652
+ {
2653
+ throw new Error(`This isn't supposed to be called`);
2654
+ }
2655
+ }
2656
+ raise.type = 'xstate.raise';
2657
+ raise.event = eventOrExpr;
2658
+ raise.id = options?.id;
2659
+ raise.delay = options?.delay;
2660
+ raise.resolve = resolveRaise;
2661
+ raise.execute = executeRaise;
2662
+ return raise;
2663
+ }
2664
+
2665
+ export { $$ACTOR_TYPE as $, createActor as A, Actor as B, interpret as C, and as D, not as E, or as F, stateIn as G, isMachineSnapshot 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 };