xstate 5.18.2 → 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.
Files changed (51) 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 +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dev/dist/xstate-dev.cjs.js +1 -1
  14. package/dev/dist/xstate-dev.development.cjs.js +1 -1
  15. package/dev/dist/xstate-dev.development.esm.js +1 -1
  16. package/dev/dist/xstate-dev.esm.js +1 -1
  17. package/dev/dist/xstate-dev.umd.min.js.map +1 -1
  18. package/dist/declarations/src/State.d.ts +1 -1
  19. package/dist/declarations/src/actions/raise.d.ts +9 -1
  20. package/dist/declarations/src/actions/send.d.ts +10 -1
  21. package/dist/declarations/src/createActor.d.ts +2 -1
  22. package/dist/declarations/src/getNextSnapshot.d.ts +2 -0
  23. package/dist/declarations/src/index.d.ts +1 -0
  24. package/dist/declarations/src/inspection.d.ts +1 -1
  25. package/dist/declarations/src/stateUtils.d.ts +17 -7
  26. package/dist/declarations/src/transition.d.ts +16 -0
  27. package/dist/declarations/src/types.d.ts +47 -14
  28. package/dist/declarations/src/utils.d.ts +1 -1
  29. package/dist/{log-b7ed1b61.development.cjs.js → log-17337367.development.cjs.js} +22 -19
  30. package/dist/{log-15d0f775.esm.js → log-2a773d37.esm.js} +21 -15
  31. package/dist/{log-98fcce74.cjs.js → log-b0ee96de.cjs.js} +21 -15
  32. package/dist/{log-38475d87.development.esm.js → log-ef30c65f.development.esm.js} +22 -19
  33. package/dist/{raise-5ea71f04.development.esm.js → raise-1db27a82.development.esm.js} +98 -72
  34. package/dist/{raise-e919c5d4.development.cjs.js → raise-4acdb210.development.cjs.js} +98 -72
  35. package/dist/{raise-b1e0b9a9.cjs.js → raise-60cebf03.cjs.js} +94 -70
  36. package/dist/{raise-0f7cf128.esm.js → raise-c17ec2bc.esm.js} +94 -70
  37. package/dist/xstate.cjs.js +57 -15
  38. package/dist/xstate.cjs.mjs +2 -0
  39. package/dist/xstate.development.cjs.js +57 -15
  40. package/dist/xstate.development.cjs.mjs +2 -0
  41. package/dist/xstate.development.esm.js +58 -18
  42. package/dist/xstate.esm.js +58 -18
  43. package/dist/xstate.umd.min.js +1 -1
  44. package/dist/xstate.umd.min.js.map +1 -1
  45. package/guards/dist/xstate-guards.cjs.js +1 -1
  46. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  47. package/guards/dist/xstate-guards.development.esm.js +1 -1
  48. package/guards/dist/xstate-guards.esm.js +1 -1
  49. package/guards/dist/xstate-guards.umd.min.js +1 -1
  50. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  51. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-b1e0b9a9.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-60cebf03.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -85,7 +85,7 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
85
85
  ...snapshot.children,
86
86
  ...spawnedChildren
87
87
  } : snapshot.children
88
- })];
88
+ }), undefined, undefined];
89
89
  }
90
90
  /**
91
91
  * Updates the current context of the machine.
@@ -122,7 +122,7 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
122
122
  * update.
123
123
  */
124
124
  function assign(assignment) {
125
- function assign(args, params) {
125
+ function assign(_args, _params) {
126
126
  }
127
127
  assign.type = 'xstate.assign';
128
128
  assign.assignment = assignment;
@@ -136,7 +136,7 @@ function resolveEmit(_, snapshot, args, actionParams, {
136
136
  const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
137
137
  return [snapshot, {
138
138
  event: resolvedEvent
139
- }];
139
+ }, undefined];
140
140
  }
141
141
  function executeEmit(actorScope, {
142
142
  event
@@ -181,7 +181,7 @@ function executeEmit(actorScope, {
181
181
  */
182
182
  function emit(/** The event to emit, or an expression that returns an event to emit. */
183
183
  eventOrExpr) {
184
- function emit(args, params) {
184
+ function emit(_args, _params) {
185
185
  }
186
186
  emit.type = 'xstate.emit';
187
187
  emit.event = eventOrExpr;
@@ -226,8 +226,6 @@ eventOrExpr) {
226
226
  * "someChildState" }`.
227
227
  */
228
228
 
229
- // TODO: remove once TS fixes this type-widening issue
230
-
231
229
  /** @deprecated Use `AnyMachineSnapshot` instead */
232
230
 
233
231
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
@@ -258,6 +256,8 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
258
256
 
259
257
  /** @deprecated */
260
258
 
259
+ // TODO: cover all that can be actually returned
260
+
261
261
  function resolveSendTo(actorScope, snapshot, args, actionParams, {
262
262
  to,
263
263
  event: eventOrExpr,
@@ -266,7 +266,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
266
266
  }, extra) {
267
267
  const delaysMap = snapshot.machine.implementations.delays;
268
268
  if (typeof eventOrExpr === 'string') {
269
- throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
269
+ throw new Error(
270
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
271
+ `Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
270
272
  }
271
273
  const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
272
274
  let resolvedDelay;
@@ -279,9 +281,12 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
279
281
  const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
280
282
  let targetActorRef;
281
283
  if (typeof resolvedTarget === 'string') {
284
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
282
285
  if (resolvedTarget === SpecialTargets.Parent) {
283
286
  targetActorRef = actorScope.self._parent;
284
- } else if (resolvedTarget === SpecialTargets.Internal) {
287
+ }
288
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
289
+ else if (resolvedTarget === SpecialTargets.Internal) {
285
290
  targetActorRef = actorScope.self;
286
291
  } else if (resolvedTarget.startsWith('#_')) {
287
292
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
@@ -298,10 +303,11 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
298
303
  }
299
304
  return [snapshot, {
300
305
  to: targetActorRef,
306
+ targetId: typeof resolvedTarget === 'string' ? resolvedTarget : undefined,
301
307
  event: resolvedEvent,
302
308
  id,
303
309
  delay: resolvedDelay
304
- }];
310
+ }, undefined];
305
311
  }
306
312
  function retryResolveSendTo(_, snapshot, params) {
307
313
  if (typeof params.to === 'string') {
@@ -340,9 +346,9 @@ function executeSendTo(actorScope, params) {
340
346
  * - `delay` - The number of milliseconds to delay the sending of the event.
341
347
  */
342
348
  function sendTo(to, eventOrExpr, options) {
343
- function sendTo(args, params) {
349
+ function sendTo(_args, _params) {
344
350
  }
345
- sendTo.type = 'xsnapshot.sendTo';
351
+ sendTo.type = 'xstate.sendTo';
346
352
  sendTo.to = to;
347
353
  sendTo.event = eventOrExpr;
348
354
  sendTo.id = options?.id;
@@ -442,7 +448,7 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
442
448
  * ```
443
449
  */
444
450
  function enqueueActions(collect) {
445
- function enqueueActions(args, params) {
451
+ function enqueueActions(_args, _params) {
446
452
  }
447
453
  enqueueActions.type = 'xstate.enqueueActions';
448
454
  enqueueActions.collect = collect;
@@ -457,7 +463,7 @@ function resolveLog(_, snapshot, actionArgs, actionParams, {
457
463
  return [snapshot, {
458
464
  value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
459
465
  label
460
- }];
466
+ }, undefined];
461
467
  }
462
468
  function executeLog({
463
469
  logger
@@ -487,7 +493,7 @@ function log(value = ({
487
493
  context,
488
494
  event
489
495
  }), label) {
490
- function log(args, params) {
496
+ function log(_args, _params) {
491
497
  }
492
498
  log.type = 'xstate.log';
493
499
  log.value = value;
@@ -1,4 +1,4 @@
1
- import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as executingCustomAction, W as XSTATE_ERROR, Y as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-5ea71f04.development.esm.js';
1
+ import { T as ProcessingStatus, z as resolveReferencedActor, A as createActor, U as cloneMachineSnapshot, V as executingCustomAction, W as XSTATE_ERROR, Y as createErrorActorEvent, e as evaluateGuard, M as cancel, O as raise, P as spawnChild, R as stopChild } from './raise-1db27a82.development.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, {
4
4
  machine,
@@ -83,7 +83,7 @@ function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
83
83
  ...snapshot.children,
84
84
  ...spawnedChildren
85
85
  } : snapshot.children
86
- })];
86
+ }), undefined, undefined];
87
87
  }
88
88
  /**
89
89
  * Updates the current context of the machine.
@@ -123,7 +123,7 @@ function assign(assignment) {
123
123
  if (executingCustomAction) {
124
124
  console.warn('Custom actions should not call `assign()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
125
125
  }
126
- function assign(args, params) {
126
+ function assign(_args, _params) {
127
127
  {
128
128
  throw new Error(`This isn't supposed to be called`);
129
129
  }
@@ -137,13 +137,10 @@ function assign(assignment) {
137
137
  function resolveEmit(_, snapshot, args, actionParams, {
138
138
  event: eventOrExpr
139
139
  }) {
140
- if (typeof eventOrExpr === 'string') {
141
- throw new Error(`Only event objects may be used with emit; use emit({ type: "${eventOrExpr}" }) instead`);
142
- }
143
140
  const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
144
141
  return [snapshot, {
145
142
  event: resolvedEvent
146
- }];
143
+ }, undefined];
147
144
  }
148
145
  function executeEmit(actorScope, {
149
146
  event
@@ -191,7 +188,7 @@ eventOrExpr) {
191
188
  if (executingCustomAction) {
192
189
  console.warn('Custom actions should not call `emit()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
193
190
  }
194
- function emit(args, params) {
191
+ function emit(_args, _params) {
195
192
  {
196
193
  throw new Error(`This isn't supposed to be called`);
197
194
  }
@@ -239,8 +236,6 @@ eventOrExpr) {
239
236
  * "someChildState" }`.
240
237
  */
241
238
 
242
- // TODO: remove once TS fixes this type-widening issue
243
-
244
239
  /** @deprecated Use `AnyMachineSnapshot` instead */
245
240
 
246
241
  // TODO: possibly refactor this somehow, use even a simpler type, and maybe even make `machine.options` private or something
@@ -271,6 +266,8 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
271
266
 
272
267
  /** @deprecated */
273
268
 
269
+ // TODO: cover all that can be actually returned
270
+
274
271
  function resolveSendTo(actorScope, snapshot, args, actionParams, {
275
272
  to,
276
273
  event: eventOrExpr,
@@ -279,7 +276,9 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
279
276
  }, extra) {
280
277
  const delaysMap = snapshot.machine.implementations.delays;
281
278
  if (typeof eventOrExpr === 'string') {
282
- throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
279
+ throw new Error(
280
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
281
+ `Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
283
282
  }
284
283
  const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
285
284
  let resolvedDelay;
@@ -292,9 +291,12 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
292
291
  const resolvedTarget = typeof to === 'function' ? to(args, actionParams) : to;
293
292
  let targetActorRef;
294
293
  if (typeof resolvedTarget === 'string') {
294
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
295
295
  if (resolvedTarget === SpecialTargets.Parent) {
296
296
  targetActorRef = actorScope.self._parent;
297
- } else if (resolvedTarget === SpecialTargets.Internal) {
297
+ }
298
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
299
+ else if (resolvedTarget === SpecialTargets.Internal) {
298
300
  targetActorRef = actorScope.self;
299
301
  } else if (resolvedTarget.startsWith('#_')) {
300
302
  // SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
@@ -311,10 +313,11 @@ function resolveSendTo(actorScope, snapshot, args, actionParams, {
311
313
  }
312
314
  return [snapshot, {
313
315
  to: targetActorRef,
316
+ targetId: typeof resolvedTarget === 'string' ? resolvedTarget : undefined,
314
317
  event: resolvedEvent,
315
318
  id,
316
319
  delay: resolvedDelay
317
- }];
320
+ }, undefined];
318
321
  }
319
322
  function retryResolveSendTo(_, snapshot, params) {
320
323
  if (typeof params.to === 'string') {
@@ -354,14 +357,14 @@ function executeSendTo(actorScope, params) {
354
357
  */
355
358
  function sendTo(to, eventOrExpr, options) {
356
359
  if (executingCustomAction) {
357
- 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.');
360
+ console.warn('Custom actions should not call `sendTo()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
358
361
  }
359
- function sendTo(args, params) {
362
+ function sendTo(_args, _params) {
360
363
  {
361
364
  throw new Error(`This isn't supposed to be called`);
362
365
  }
363
366
  }
364
- sendTo.type = 'xsnapshot.sendTo';
367
+ sendTo.type = 'xstate.sendTo';
365
368
  sendTo.to = to;
366
369
  sendTo.event = eventOrExpr;
367
370
  sendTo.id = options?.id;
@@ -471,7 +474,7 @@ function resolveEnqueueActions(actorScope, snapshot, args, actionParams, {
471
474
  * ```
472
475
  */
473
476
  function enqueueActions(collect) {
474
- function enqueueActions(args, params) {
477
+ function enqueueActions(_args, _params) {
475
478
  {
476
479
  throw new Error(`This isn't supposed to be called`);
477
480
  }
@@ -489,7 +492,7 @@ function resolveLog(_, snapshot, actionArgs, actionParams, {
489
492
  return [snapshot, {
490
493
  value: typeof value === 'function' ? value(actionArgs, actionParams) : value,
491
494
  label
492
- }];
495
+ }, undefined];
493
496
  }
494
497
  function executeLog({
495
498
  logger
@@ -519,7 +522,7 @@ function log(value = ({
519
522
  context,
520
523
  event
521
524
  }), label) {
522
- function log(args, params) {
525
+ function log(_args, _params) {
523
526
  {
524
527
  throw new Error(`This isn't supposed to be called`);
525
528
  }
@@ -154,7 +154,7 @@ function toStatePath(stateId) {
154
154
  if (isArray(stateId)) {
155
155
  return stateId;
156
156
  }
157
- let result = [];
157
+ const result = [];
158
158
  let segment = '';
159
159
  for (let i = 0; i < stateId.length; i++) {
160
160
  const char = stateId.charCodeAt(i);
@@ -234,7 +234,7 @@ function resolveOutput(mapper, context, event, self) {
234
234
  });
235
235
  }
236
236
  if (!!mapper && typeof mapper === 'object' && Object.values(mapper).some(val => typeof val === 'function')) {
237
- console.warn(`Dynamically mapping values to individual properties is deprecated. Use a single function that returns the mapped object instead.\nFound object containing properties whose values are possibly mapping functions: ${Object.entries(mapper).filter(([key, value]) => typeof value === 'function').map(([key, value]) => `\n - ${key}: ${value.toString().replace(/\n\s*/g, '')}`).join('')}`);
237
+ console.warn(`Dynamically mapping values to individual properties is deprecated. Use a single function that returns the mapped object instead.\nFound object containing properties whose values are possibly mapping functions: ${Object.entries(mapper).filter(([, value]) => typeof value === 'function').map(([key, value]) => `\n - ${key}: ${value.toString().replace(/\n\s*/g, '')}`).join('')}`);
238
238
  }
239
239
  return mapper;
240
240
  }
@@ -422,6 +422,7 @@ function createSystem(rootActor, options) {
422
422
  return system;
423
423
  }
424
424
 
425
+ let executingCustomAction = false;
425
426
  const $$ACTOR_TYPE = 1;
426
427
 
427
428
  // those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
@@ -542,10 +543,37 @@ class Actor {
542
543
  if (!listeners && !wildcardListener) {
543
544
  return;
544
545
  }
545
- const allListeners = new Set([...(listeners ? listeners.values() : []), ...(wildcardListener ? wildcardListener.values() : [])]);
546
- for (const handler of Array.from(allListeners)) {
546
+ const allListeners = [...(listeners ? listeners.values() : []), ...(wildcardListener ? wildcardListener.values() : [])];
547
+ for (const handler of allListeners) {
547
548
  handler(emittedEvent);
548
549
  }
550
+ },
551
+ actionExecutor: action => {
552
+ const exec = () => {
553
+ this._actorScope.system._sendInspectionEvent({
554
+ type: '@xstate.action',
555
+ actorRef: this,
556
+ action: {
557
+ type: action.type,
558
+ params: action.params
559
+ }
560
+ });
561
+ if (!action.exec) {
562
+ return;
563
+ }
564
+ const saveExecutingCustomAction = executingCustomAction;
565
+ try {
566
+ executingCustomAction = true;
567
+ action.exec(action.info, action.params);
568
+ } finally {
569
+ executingCustomAction = saveExecutingCustomAction;
570
+ }
571
+ };
572
+ if (this._processingStatus === ProcessingStatus.Running) {
573
+ exec();
574
+ } else {
575
+ this._deferred.push(exec);
576
+ }
549
577
  }
550
578
  };
551
579
 
@@ -1085,11 +1113,13 @@ function resolveCancel(_, snapshot, actionArgs, actionParams, {
1085
1113
  sendId
1086
1114
  }) {
1087
1115
  const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
1088
- return [snapshot, resolvedSendId];
1116
+ return [snapshot, {
1117
+ sendId: resolvedSendId
1118
+ }, undefined];
1089
1119
  }
1090
- function executeCancel(actorScope, resolvedSendId) {
1120
+ function executeCancel(actorScope, params) {
1091
1121
  actorScope.defer(() => {
1092
- actorScope.system.scheduler.cancel(actorScope.self, resolvedSendId);
1122
+ actorScope.system.scheduler.cancel(actorScope.self, params.sendId);
1093
1123
  });
1094
1124
  }
1095
1125
  /**
@@ -1125,7 +1155,7 @@ function executeCancel(actorScope, resolvedSendId) {
1125
1155
  * @param sendId The `id` of the `sendTo(...)` action to cancel.
1126
1156
  */
1127
1157
  function cancel(sendId) {
1128
- function cancel(args, params) {
1158
+ function cancel(_args, _params) {
1129
1159
  {
1130
1160
  throw new Error(`This isn't supposed to be called`);
1131
1161
  }
@@ -1147,22 +1177,26 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
1147
1177
  const logic = typeof src === 'string' ? resolveReferencedActor(snapshot.machine, src) : src;
1148
1178
  const resolvedId = typeof id === 'function' ? id(actionArgs) : id;
1149
1179
  let actorRef;
1180
+ let resolvedInput = undefined;
1150
1181
  if (logic) {
1182
+ resolvedInput = typeof input === 'function' ? input({
1183
+ context: snapshot.context,
1184
+ event: actionArgs.event,
1185
+ self: actorScope.self
1186
+ }) : input;
1151
1187
  actorRef = createActor(logic, {
1152
1188
  id: resolvedId,
1153
1189
  src,
1154
1190
  parent: actorScope.self,
1155
1191
  syncSnapshot,
1156
1192
  systemId,
1157
- input: typeof input === 'function' ? input({
1158
- context: snapshot.context,
1159
- event: actionArgs.event,
1160
- self: actorScope.self
1161
- }) : input
1193
+ input: resolvedInput
1162
1194
  });
1163
1195
  }
1164
1196
  if (!actorRef) {
1165
- console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
1197
+ console.warn(
1198
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-base-to-string
1199
+ `Actor type '${src}' not found in machine '${actorScope.id}'.`);
1166
1200
  }
1167
1201
  return [cloneMachineSnapshot(snapshot, {
1168
1202
  children: {
@@ -1171,11 +1205,13 @@ function resolveSpawn(actorScope, snapshot, actionArgs, _actionParams, {
1171
1205
  }
1172
1206
  }), {
1173
1207
  id,
1174
- actorRef
1175
- }];
1208
+ systemId,
1209
+ actorRef,
1210
+ src,
1211
+ input: resolvedInput
1212
+ }, undefined];
1176
1213
  }
1177
1214
  function executeSpawn(actorScope, {
1178
- id,
1179
1215
  actorRef
1180
1216
  }) {
1181
1217
  if (!actorRef) {
@@ -1194,12 +1230,12 @@ function spawnChild(...[src, {
1194
1230
  input,
1195
1231
  syncSnapshot = false
1196
1232
  } = {}]) {
1197
- function spawnChild(args, params) {
1233
+ function spawnChild(_args, _params) {
1198
1234
  {
1199
1235
  throw new Error(`This isn't supposed to be called`);
1200
1236
  }
1201
1237
  }
1202
- spawnChild.type = 'snapshot.spawnChild';
1238
+ spawnChild.type = 'xstate.spawnChild';
1203
1239
  spawnChild.id = id;
1204
1240
  spawnChild.systemId = systemId;
1205
1241
  spawnChild.src = src;
@@ -1224,7 +1260,7 @@ function resolveStop(_, snapshot, args, actionParams, {
1224
1260
  }
1225
1261
  return [cloneMachineSnapshot(snapshot, {
1226
1262
  children
1227
- }), resolvedActorRef];
1263
+ }), resolvedActorRef, undefined];
1228
1264
  }
1229
1265
  function executeStop(actorScope, actorRef) {
1230
1266
  if (!actorRef) {
@@ -1256,7 +1292,7 @@ function executeStop(actorScope, actorRef) {
1256
1292
  * @param actorRef The actor to stop.
1257
1293
  */
1258
1294
  function stopChild(actorRef) {
1259
- function stop(args, params) {
1295
+ function stop(_args, _params) {
1260
1296
  {
1261
1297
  throw new Error(`This isn't supposed to be called`);
1262
1298
  }
@@ -1286,7 +1322,7 @@ function checkStateIn(snapshot, _, {
1286
1322
  return snapshot.matches(stateValue);
1287
1323
  }
1288
1324
  function stateIn(stateValue) {
1289
- function stateIn(args, params) {
1325
+ function stateIn() {
1290
1326
  {
1291
1327
  throw new Error(`This isn't supposed to be called`);
1292
1328
  }
@@ -1334,7 +1370,7 @@ function checkNot(snapshot, {
1334
1370
  * @returns A guard
1335
1371
  */
1336
1372
  function not(guard) {
1337
- function not(args, params) {
1373
+ function not(_args, _params) {
1338
1374
  {
1339
1375
  throw new Error(`This isn't supposed to be called`);
1340
1376
  }
@@ -1382,7 +1418,7 @@ function checkAnd(snapshot, {
1382
1418
  * @returns A guard action object
1383
1419
  */
1384
1420
  function and(guards) {
1385
- function and(args, params) {
1421
+ function and(_args, _params) {
1386
1422
  {
1387
1423
  throw new Error(`This isn't supposed to be called`);
1388
1424
  }
@@ -1430,7 +1466,7 @@ function checkOr(snapshot, {
1430
1466
  * @returns A guard action object
1431
1467
  */
1432
1468
  function or(guards) {
1433
- function or(args, params) {
1469
+ function or(_args, _params) {
1434
1470
  {
1435
1471
  throw new Error(`This isn't supposed to be called`);
1436
1472
  }
@@ -1616,7 +1652,7 @@ function getDelayedTransitions(stateNode) {
1616
1652
  if (!afterConfig) {
1617
1653
  return [];
1618
1654
  }
1619
- const mutateEntryExit = (delay, i) => {
1655
+ const mutateEntryExit = delay => {
1620
1656
  const afterEvent = createAfterEvent(delay, stateNode.id);
1621
1657
  const eventType = afterEvent.type;
1622
1658
  stateNode.entry.push(raise(afterEvent, {
@@ -1626,7 +1662,7 @@ function getDelayedTransitions(stateNode) {
1626
1662
  stateNode.exit.push(cancel(eventType));
1627
1663
  return eventType;
1628
1664
  };
1629
- const delayedTransitions = Object.keys(afterConfig).flatMap((delay, i) => {
1665
+ const delayedTransitions = Object.keys(afterConfig).flatMap(delay => {
1630
1666
  const configTransition = afterConfig[delay];
1631
1667
  const resolvedTransition = typeof configTransition === 'string' ? {
1632
1668
  target: configTransition
@@ -1716,7 +1752,9 @@ function formatTransitions(stateNode) {
1716
1752
  function formatInitialTransition(stateNode, _target) {
1717
1753
  const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
1718
1754
  if (!resolvedTarget && _target) {
1719
- throw new Error(`Initial state node "${_target}" not found on parent state node #${stateNode.id}`);
1755
+ throw new Error(
1756
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-base-to-string
1757
+ `Initial state node "${_target}" not found on parent state node #${stateNode.id}`);
1720
1758
  }
1721
1759
  const transition = {
1722
1760
  source: stateNode,
@@ -1826,7 +1864,7 @@ function getStateNodeByPath(stateNode, statePath) {
1826
1864
  if (typeof statePath === 'string' && isStateId(statePath)) {
1827
1865
  try {
1828
1866
  return stateNode.machine.getStateNodeById(statePath);
1829
- } catch (e) {
1867
+ } catch {
1830
1868
  // try individual paths
1831
1869
  // throw e;
1832
1870
  }
@@ -2055,18 +2093,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2055
2093
 
2056
2094
  // Exit states
2057
2095
  if (!isInitial) {
2058
- [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
2096
+ [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue, actorScope.actionExecutor);
2059
2097
  }
2060
2098
 
2061
2099
  // Execute transition content
2062
- nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
2100
+ nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue, undefined);
2063
2101
 
2064
2102
  // Enter states
2065
2103
  nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
2066
2104
  const nextStateNodes = [...mutStateNodeSet];
2067
2105
  if (nextState.status === 'done') {
2068
- nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
2106
+ nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue, undefined);
2069
2107
  }
2108
+
2109
+ // eslint-disable-next-line no-useless-catch
2070
2110
  try {
2071
2111
  if (historyValue === currentSnapshot.historyValue && areStateNodeCollectionsEqual(currentSnapshot._nodes, mutStateNodeSet)) {
2072
2112
  return nextState;
@@ -2236,7 +2276,7 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
2236
2276
  function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
2237
2277
  addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
2238
2278
  }
2239
- function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
2279
+ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue, _actionExecutor) {
2240
2280
  let nextSnapshot = currentSnapshot;
2241
2281
  const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
2242
2282
  statesToExit.sort((a, b) => b.order - a.order);
@@ -2260,12 +2300,14 @@ function exitStates(currentSnapshot, event, actorScope, transitions, mutStateNod
2260
2300
  }
2261
2301
  }
2262
2302
  for (const s of statesToExit) {
2263
- nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue);
2303
+ nextSnapshot = resolveActionsAndContext(nextSnapshot, event, actorScope, [...s.exit, ...s.invoke.map(def => stopChild(def.id))], internalQueue, undefined);
2264
2304
  mutStateNodeSet.delete(s);
2265
2305
  }
2266
2306
  return [nextSnapshot, changedHistory || historyValue];
2267
2307
  }
2268
- let executingCustomAction = false;
2308
+ function getAction(machine, actionType) {
2309
+ return machine.implementations.actions[actionType];
2310
+ }
2269
2311
  function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope, actions, extra, retries) {
2270
2312
  const {
2271
2313
  machine
@@ -2277,10 +2319,8 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
2277
2319
  // the existing type of `.actions` assumes non-nullable `TExpressionAction`
2278
2320
  // it's fine to cast this here to get a common type and lack of errors in the rest of the code
2279
2321
  // our logic below makes sure that we call those 2 "variants" correctly
2280
- machine.implementations.actions[typeof action === 'string' ? action : action.type];
2281
- if (!resolvedAction) {
2282
- continue;
2283
- }
2322
+
2323
+ getAction(machine, typeof action === 'string' ? action : action.type);
2284
2324
  const actionArgs = {
2285
2325
  context: intermediateSnapshot.context,
2286
2326
  event,
@@ -2291,30 +2331,13 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
2291
2331
  context: intermediateSnapshot.context,
2292
2332
  event
2293
2333
  }) : action.params : undefined;
2294
- function executeAction() {
2295
- actorScope.system._sendInspectionEvent({
2296
- type: '@xstate.action',
2297
- actorRef: actorScope.self,
2298
- action: {
2299
- type: typeof action === 'string' ? action : typeof action === 'object' ? action.type : action.name || '(anonymous)',
2300
- params: actionParams
2301
- }
2334
+ if (!resolvedAction || !('resolve' in resolvedAction)) {
2335
+ actorScope.actionExecutor({
2336
+ type: typeof action === 'string' ? action : typeof action === 'object' ? action.type : action.name || '(anonymous)',
2337
+ info: actionArgs,
2338
+ params: actionParams,
2339
+ exec: resolvedAction
2302
2340
  });
2303
- try {
2304
- executingCustomAction = resolvedAction;
2305
- resolvedAction(actionArgs, actionParams);
2306
- } finally {
2307
- executingCustomAction = false;
2308
- }
2309
- }
2310
- if (!('resolve' in resolvedAction)) {
2311
- if (actorScope.self._processingStatus === ProcessingStatus.Running) {
2312
- executeAction();
2313
- } else {
2314
- actorScope.defer(() => {
2315
- executeAction();
2316
- });
2317
- }
2318
2341
  continue;
2319
2342
  }
2320
2343
  const builtinAction = resolvedAction;
@@ -2326,11 +2349,12 @@ function resolveAndExecuteActionsWithContext(currentSnapshot, event, actorScope,
2326
2349
  retries?.push([builtinAction, params]);
2327
2350
  }
2328
2351
  if ('execute' in builtinAction) {
2329
- if (actorScope.self._processingStatus === ProcessingStatus.Running) {
2330
- builtinAction.execute(actorScope, params);
2331
- } else {
2332
- actorScope.defer(builtinAction.execute.bind(null, actorScope, params));
2333
- }
2352
+ actorScope.actionExecutor({
2353
+ type: builtinAction.type,
2354
+ info: actionArgs,
2355
+ params,
2356
+ exec: builtinAction.execute.bind(null, actorScope, params)
2357
+ });
2334
2358
  }
2335
2359
  if (actions) {
2336
2360
  intermediateSnapshot = resolveAndExecuteActionsWithContext(intermediateSnapshot, event, actorScope, actions, extra, retries);
@@ -2349,7 +2373,7 @@ function resolveActionsAndContext(currentSnapshot, event, actorScope, actions, i
2349
2373
  });
2350
2374
  return nextState;
2351
2375
  }
2352
- function macrostep(snapshot, event, actorScope, internalQueue = []) {
2376
+ function macrostep(snapshot, event, actorScope, internalQueue) {
2353
2377
  if (event.type === WILDCARD) {
2354
2378
  throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
2355
2379
  }
@@ -2431,7 +2455,7 @@ function macrostep(snapshot, event, actorScope, internalQueue = []) {
2431
2455
  };
2432
2456
  }
2433
2457
  function stopChildren(nextState, event, actorScope) {
2434
- return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stopChild(child)), []);
2458
+ return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stopChild(child)), [], undefined);
2435
2459
  }
2436
2460
  function selectTransitions(event, nextState) {
2437
2461
  return nextState.machine.getTransitionData(nextState, event);
@@ -2604,7 +2628,9 @@ function resolveRaise(_, snapshot, args, actionParams, {
2604
2628
  }) {
2605
2629
  const delaysMap = snapshot.machine.implementations.delays;
2606
2630
  if (typeof eventOrExpr === 'string') {
2607
- throw new Error(`Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2631
+ throw new Error(
2632
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
2633
+ `Only event objects may be used with raise; use raise({ type: "${eventOrExpr}" }) instead`);
2608
2634
  }
2609
2635
  const resolvedEvent = typeof eventOrExpr === 'function' ? eventOrExpr(args, actionParams) : eventOrExpr;
2610
2636
  let resolvedDelay;
@@ -2621,7 +2647,7 @@ function resolveRaise(_, snapshot, args, actionParams, {
2621
2647
  event: resolvedEvent,
2622
2648
  id,
2623
2649
  delay: resolvedDelay
2624
- }];
2650
+ }, undefined];
2625
2651
  }
2626
2652
  function executeRaise(actorScope, params) {
2627
2653
  const {
@@ -2647,7 +2673,7 @@ function raise(eventOrExpr, options) {
2647
2673
  if (executingCustomAction) {
2648
2674
  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.');
2649
2675
  }
2650
- function raise(args, params) {
2676
+ function raise(_args, _params) {
2651
2677
  {
2652
2678
  throw new Error(`This isn't supposed to be called`);
2653
2679
  }