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.
- 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/dev/dist/xstate-dev.cjs.js +1 -1
- package/dev/dist/xstate-dev.development.cjs.js +1 -1
- package/dev/dist/xstate-dev.development.esm.js +1 -1
- package/dev/dist/xstate-dev.esm.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/actions/raise.d.ts +9 -1
- package/dist/declarations/src/actions/send.d.ts +10 -1
- package/dist/declarations/src/createActor.d.ts +2 -1
- package/dist/declarations/src/getNextSnapshot.d.ts +2 -0
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/inspection.d.ts +1 -1
- package/dist/declarations/src/stateUtils.d.ts +17 -7
- package/dist/declarations/src/transition.d.ts +16 -0
- package/dist/declarations/src/types.d.ts +47 -14
- package/dist/declarations/src/utils.d.ts +1 -1
- package/dist/{log-b7ed1b61.development.cjs.js → log-17337367.development.cjs.js} +22 -19
- package/dist/{log-15d0f775.esm.js → log-2a773d37.esm.js} +21 -15
- package/dist/{log-98fcce74.cjs.js → log-b0ee96de.cjs.js} +21 -15
- package/dist/{log-38475d87.development.esm.js → log-ef30c65f.development.esm.js} +22 -19
- package/dist/{raise-5ea71f04.development.esm.js → raise-1db27a82.development.esm.js} +98 -72
- package/dist/{raise-e919c5d4.development.cjs.js → raise-4acdb210.development.cjs.js} +98 -72
- package/dist/{raise-b1e0b9a9.cjs.js → raise-60cebf03.cjs.js} +94 -70
- package/dist/{raise-0f7cf128.esm.js → raise-c17ec2bc.esm.js} +94 -70
- package/dist/xstate.cjs.js +57 -15
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +57 -15
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +58 -18
- package/dist/xstate.esm.js +58 -18
- 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 +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
}
|
|
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(
|
|
349
|
+
function sendTo(_args, _params) {
|
|
344
350
|
}
|
|
345
|
-
sendTo.type = '
|
|
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(
|
|
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(
|
|
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-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
}
|
|
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 `
|
|
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(
|
|
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 = '
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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(([
|
|
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 =
|
|
546
|
-
for (const handler of
|
|
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,
|
|
1116
|
+
return [snapshot, {
|
|
1117
|
+
sendId: resolvedSendId
|
|
1118
|
+
}, undefined];
|
|
1089
1119
|
}
|
|
1090
|
-
function executeCancel(actorScope,
|
|
1120
|
+
function executeCancel(actorScope, params) {
|
|
1091
1121
|
actorScope.defer(() => {
|
|
1092
|
-
actorScope.system.scheduler.cancel(actorScope.self,
|
|
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(
|
|
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:
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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 = '
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 =
|
|
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(
|
|
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(
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
2281
|
-
|
|
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
|
-
|
|
2295
|
-
actorScope.
|
|
2296
|
-
type: '
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
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
|
-
|
|
2330
|
-
builtinAction.
|
|
2331
|
-
|
|
2332
|
-
|
|
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(
|
|
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(
|
|
2676
|
+
function raise(_args, _params) {
|
|
2651
2677
|
{
|
|
2652
2678
|
throw new Error(`This isn't supposed to be called`);
|
|
2653
2679
|
}
|