xstate 6.0.0-alpha.23 → 6.0.0-alpha.24
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/dist/{StateMachine-aad57180.cjs.js → StateMachine-0d7aa36b.cjs.js} +54 -26
- package/dist/{StateMachine-53114dce.development.cjs.js → StateMachine-27ce068a.development.cjs.js} +54 -26
- package/dist/{StateMachine-022864fd.esm.js → StateMachine-4f3ebd99.esm.js} +54 -26
- package/dist/{StateMachine-d2247245.development.esm.js → StateMachine-f3d5f2d8.development.esm.js} +54 -26
- package/dist/declarations/src/StateNode.d.ts +2 -2
- package/dist/declarations/src/createMachineFromConfig.d.ts +1 -0
- package/dist/declarations/src/stateUtils.d.ts +3 -1
- package/dist/declarations/src/types.d.ts +32 -10
- package/dist/declarations/src/types.v6.d.ts +10 -8
- package/dist/declarations/src/utils.d.ts +1 -0
- package/dist/{index-434fac23.cjs.js → index-0ef8d20d.cjs.js} +204 -40
- package/dist/{index-f5407323.development.esm.js → index-1a180503.development.esm.js} +200 -40
- package/dist/{index-41c0375c.development.cjs.js → index-46c96e83.development.cjs.js} +204 -40
- package/dist/{index-3609e096.esm.js → index-cf2e8954.esm.js} +200 -40
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +9 -13
- package/dist/xstate-graph.development.cjs.js +9 -13
- package/dist/xstate-graph.development.esm.js +9 -13
- package/dist/xstate-graph.esm.js +9 -13
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +8 -2
- package/dist/xstate.development.cjs.js +8 -2
- package/dist/xstate.development.esm.js +10 -4
- package/dist/xstate.esm.js +10 -4
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-0ef8d20d.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, actorSources, spawnedChildren) {
|
|
6
6
|
return (src, options) => {
|
|
@@ -184,8 +184,8 @@ class StateNode {
|
|
|
184
184
|
*/
|
|
185
185
|
this.meta = void 0;
|
|
186
186
|
/**
|
|
187
|
-
* The output data sent with the
|
|
188
|
-
*
|
|
187
|
+
* The output data sent with the `xstate.done.state` event if this is a final
|
|
188
|
+
* state node.
|
|
189
189
|
*/
|
|
190
190
|
this.output = void 0;
|
|
191
191
|
/**
|
|
@@ -302,8 +302,7 @@ class StateNode {
|
|
|
302
302
|
|
|
303
303
|
/** @internal */
|
|
304
304
|
next(snapshot, event, self) {
|
|
305
|
-
const
|
|
306
|
-
const candidates = memo(this, `candidates-${eventType}`, () => dist_xstateActors.getCandidates(this, eventType));
|
|
305
|
+
const candidates = memo(this, `candidates-${dist_xstateActors.getEventDescriptorKey(event)}`, () => dist_xstateActors.getCandidates(this, event));
|
|
307
306
|
for (const candidate of candidates) {
|
|
308
307
|
const guardPassed = dist_xstateActors.evaluateCandidate(candidate, event, snapshot, this, self);
|
|
309
308
|
if (guardPassed) {
|
|
@@ -344,6 +343,9 @@ function mapTransitionConfigs(transitionsConfig, mapper) {
|
|
|
344
343
|
}
|
|
345
344
|
function formatTransitions(stateNode) {
|
|
346
345
|
const transitions = new Map();
|
|
346
|
+
const addTransitions = (descriptor, additions) => {
|
|
347
|
+
transitions.set(descriptor, [...(transitions.get(descriptor) ?? []), ...additions]);
|
|
348
|
+
};
|
|
347
349
|
if (stateNode.config.on) {
|
|
348
350
|
for (const descriptor of Object.keys(stateNode.config.on)) {
|
|
349
351
|
if (descriptor === dist_xstateActors.NULL_EVENT) {
|
|
@@ -354,20 +356,30 @@ function formatTransitions(stateNode) {
|
|
|
354
356
|
}
|
|
355
357
|
}
|
|
356
358
|
if (stateNode.config.onDone) {
|
|
357
|
-
const descriptor =
|
|
358
|
-
|
|
359
|
+
const descriptor = 'xstate.done.state';
|
|
360
|
+
addTransitions(descriptor, mapTransitionConfigs(stateNode.config.onDone, transition => dist_xstateActors.formatTransition(stateNode, descriptor, {
|
|
361
|
+
...transition,
|
|
362
|
+
matches: {
|
|
363
|
+
...transition.matches,
|
|
364
|
+
stateId: stateNode.id
|
|
365
|
+
}
|
|
366
|
+
})));
|
|
359
367
|
}
|
|
360
368
|
if (stateNode.config.onError) {
|
|
361
369
|
const descriptor = 'xstate.error.*';
|
|
362
370
|
transitions.set(descriptor, mapTransitionConfigs(stateNode.config.onError, transition => dist_xstateActors.formatTransition(stateNode, descriptor, transition)));
|
|
363
371
|
}
|
|
364
|
-
const createCancelInvokeTimeoutTransition = (descriptor,
|
|
372
|
+
const createCancelInvokeTimeoutTransition = (descriptor, timeoutEventId, actorId) => dist_xstateActors.formatTransition(stateNode, descriptor, {
|
|
373
|
+
matches: {
|
|
374
|
+
actorId
|
|
375
|
+
},
|
|
376
|
+
_eventMatcher: (event, snapshot) => dist_xstateActors.matchesActorSession(event, snapshot, actorId),
|
|
365
377
|
to: (_args, enq) => {
|
|
366
|
-
enq.cancel(
|
|
378
|
+
enq.cancel(timeoutEventId);
|
|
367
379
|
return {};
|
|
368
380
|
}
|
|
369
381
|
});
|
|
370
|
-
const formatInvokeCompletionTransition = (descriptor, transitionConfig,
|
|
382
|
+
const formatInvokeCompletionTransition = (descriptor, transitionConfig, timeoutEventId) => {
|
|
371
383
|
const {
|
|
372
384
|
target,
|
|
373
385
|
to,
|
|
@@ -398,11 +410,11 @@ function formatTransitions(stateNode) {
|
|
|
398
410
|
});
|
|
399
411
|
const result = to(args, trackingEnqueue);
|
|
400
412
|
if (result !== undefined || didEnqueue) {
|
|
401
|
-
enq.cancel(
|
|
413
|
+
enq.cancel(timeoutEventId);
|
|
402
414
|
}
|
|
403
415
|
return result;
|
|
404
416
|
}
|
|
405
|
-
enq.cancel(
|
|
417
|
+
enq.cancel(timeoutEventId);
|
|
406
418
|
return {
|
|
407
419
|
target,
|
|
408
420
|
reenter
|
|
@@ -411,25 +423,39 @@ function formatTransitions(stateNode) {
|
|
|
411
423
|
});
|
|
412
424
|
};
|
|
413
425
|
for (const invokeDef of stateNode.invoke) {
|
|
414
|
-
const
|
|
426
|
+
const withInvokeMatch = transition => ({
|
|
427
|
+
...transition,
|
|
428
|
+
matches: {
|
|
429
|
+
...transition.matches,
|
|
430
|
+
actorId: invokeDef.id
|
|
431
|
+
},
|
|
432
|
+
_eventMatcher: (event, snapshot) => dist_xstateActors.matchesActorSession(event, snapshot, invokeDef.id)
|
|
433
|
+
});
|
|
434
|
+
const invokeTimeoutEventId = invokeDef.timeout !== undefined ? dist_xstateActors.createInvokeTimeoutEventId(invokeDef.id) : undefined;
|
|
415
435
|
if (invokeDef.onDone) {
|
|
416
|
-
const descriptor =
|
|
417
|
-
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone,
|
|
418
|
-
|
|
419
|
-
|
|
436
|
+
const descriptor = 'xstate.done.actor';
|
|
437
|
+
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone, rawTransition => {
|
|
438
|
+
const transition = withInvokeMatch(rawTransition);
|
|
439
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : dist_xstateActors.formatTransition(stateNode, descriptor, transition);
|
|
440
|
+
});
|
|
441
|
+
if (invokeTimeoutEventId) {
|
|
442
|
+
invokeDoneTransitions.push(createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id));
|
|
420
443
|
}
|
|
421
|
-
|
|
422
|
-
} else if (
|
|
423
|
-
const descriptor =
|
|
424
|
-
|
|
444
|
+
addTransitions(descriptor, invokeDoneTransitions);
|
|
445
|
+
} else if (invokeTimeoutEventId) {
|
|
446
|
+
const descriptor = 'xstate.done.actor';
|
|
447
|
+
addTransitions(descriptor, [createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id)]);
|
|
425
448
|
}
|
|
426
449
|
if (invokeDef.onError) {
|
|
427
|
-
const descriptor =
|
|
428
|
-
|
|
450
|
+
const descriptor = 'xstate.error.actor';
|
|
451
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onError, rawTransition => {
|
|
452
|
+
const transition = withInvokeMatch(rawTransition);
|
|
453
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : dist_xstateActors.formatTransition(stateNode, descriptor, transition);
|
|
454
|
+
}));
|
|
429
455
|
}
|
|
430
456
|
if (invokeDef.onSnapshot) {
|
|
431
|
-
const descriptor =
|
|
432
|
-
|
|
457
|
+
const descriptor = 'xstate.snapshot.actor';
|
|
458
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onSnapshot, transition => dist_xstateActors.formatTransition(stateNode, descriptor, withInvokeMatch(transition))));
|
|
433
459
|
}
|
|
434
460
|
}
|
|
435
461
|
for (const delayedTransition of stateNode.after) {
|
|
@@ -885,7 +911,8 @@ class StateMachine {
|
|
|
885
911
|
const src = actorData.src;
|
|
886
912
|
const logic = typeof src === 'string' ? dist_xstateActors.resolveReferencedActor(this, src) : src;
|
|
887
913
|
if (!logic) {
|
|
888
|
-
|
|
914
|
+
const sourceId = typeof src === 'string' ? src : '<unknown>';
|
|
915
|
+
throw new Error(`Unable to restore child actor '${actorId}': child source '${sourceId}' is not provided in machine '${this.id}'.`);
|
|
889
916
|
}
|
|
890
917
|
const actor = resolvedActorScope.system.createActorRef(logic, {
|
|
891
918
|
id: actorId,
|
|
@@ -893,6 +920,7 @@ class StateMachine {
|
|
|
893
920
|
syncSnapshot: actorData.syncSnapshot,
|
|
894
921
|
snapshot: childState,
|
|
895
922
|
src,
|
|
923
|
+
_sessionId: actorData.sessionId,
|
|
896
924
|
registryKey: actorData.registryKey
|
|
897
925
|
});
|
|
898
926
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
package/dist/{StateMachine-53114dce.development.cjs.js → StateMachine-27ce068a.development.cjs.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-46c96e83.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, actorSources, spawnedChildren) {
|
|
6
6
|
return (src, options) => {
|
|
@@ -185,8 +185,8 @@ class StateNode {
|
|
|
185
185
|
*/
|
|
186
186
|
this.meta = void 0;
|
|
187
187
|
/**
|
|
188
|
-
* The output data sent with the
|
|
189
|
-
*
|
|
188
|
+
* The output data sent with the `xstate.done.state` event if this is a final
|
|
189
|
+
* state node.
|
|
190
190
|
*/
|
|
191
191
|
this.output = void 0;
|
|
192
192
|
/**
|
|
@@ -303,8 +303,7 @@ class StateNode {
|
|
|
303
303
|
|
|
304
304
|
/** @internal */
|
|
305
305
|
next(snapshot, event, self) {
|
|
306
|
-
const
|
|
307
|
-
const candidates = memo(this, `candidates-${eventType}`, () => dist_xstateActors.getCandidates(this, eventType));
|
|
306
|
+
const candidates = memo(this, `candidates-${dist_xstateActors.getEventDescriptorKey(event)}`, () => dist_xstateActors.getCandidates(this, event));
|
|
308
307
|
for (const candidate of candidates) {
|
|
309
308
|
const guardPassed = dist_xstateActors.evaluateCandidate(candidate, event, snapshot, this, self);
|
|
310
309
|
if (guardPassed) {
|
|
@@ -362,6 +361,9 @@ function mapTransitionConfigs(transitionsConfig, mapper) {
|
|
|
362
361
|
}
|
|
363
362
|
function formatTransitions(stateNode) {
|
|
364
363
|
const transitions = new Map();
|
|
364
|
+
const addTransitions = (descriptor, additions) => {
|
|
365
|
+
transitions.set(descriptor, [...(transitions.get(descriptor) ?? []), ...additions]);
|
|
366
|
+
};
|
|
365
367
|
if (stateNode.config.on) {
|
|
366
368
|
for (const descriptor of Object.keys(stateNode.config.on)) {
|
|
367
369
|
if (descriptor === dist_xstateActors.NULL_EVENT) {
|
|
@@ -372,20 +374,30 @@ function formatTransitions(stateNode) {
|
|
|
372
374
|
}
|
|
373
375
|
}
|
|
374
376
|
if (stateNode.config.onDone) {
|
|
375
|
-
const descriptor =
|
|
376
|
-
|
|
377
|
+
const descriptor = 'xstate.done.state';
|
|
378
|
+
addTransitions(descriptor, mapTransitionConfigs(stateNode.config.onDone, transition => dist_xstateActors.formatTransition(stateNode, descriptor, {
|
|
379
|
+
...transition,
|
|
380
|
+
matches: {
|
|
381
|
+
...transition.matches,
|
|
382
|
+
stateId: stateNode.id
|
|
383
|
+
}
|
|
384
|
+
})));
|
|
377
385
|
}
|
|
378
386
|
if (stateNode.config.onError) {
|
|
379
387
|
const descriptor = 'xstate.error.*';
|
|
380
388
|
transitions.set(descriptor, mapTransitionConfigs(stateNode.config.onError, transition => dist_xstateActors.formatTransition(stateNode, descriptor, transition)));
|
|
381
389
|
}
|
|
382
|
-
const createCancelInvokeTimeoutTransition = (descriptor,
|
|
390
|
+
const createCancelInvokeTimeoutTransition = (descriptor, timeoutEventId, actorId) => dist_xstateActors.formatTransition(stateNode, descriptor, {
|
|
391
|
+
matches: {
|
|
392
|
+
actorId
|
|
393
|
+
},
|
|
394
|
+
_eventMatcher: (event, snapshot) => dist_xstateActors.matchesActorSession(event, snapshot, actorId),
|
|
383
395
|
to: (_args, enq) => {
|
|
384
|
-
enq.cancel(
|
|
396
|
+
enq.cancel(timeoutEventId);
|
|
385
397
|
return {};
|
|
386
398
|
}
|
|
387
399
|
});
|
|
388
|
-
const formatInvokeCompletionTransition = (descriptor, transitionConfig,
|
|
400
|
+
const formatInvokeCompletionTransition = (descriptor, transitionConfig, timeoutEventId) => {
|
|
389
401
|
const {
|
|
390
402
|
target,
|
|
391
403
|
to,
|
|
@@ -416,11 +428,11 @@ function formatTransitions(stateNode) {
|
|
|
416
428
|
});
|
|
417
429
|
const result = to(args, trackingEnqueue);
|
|
418
430
|
if (result !== undefined || didEnqueue) {
|
|
419
|
-
enq.cancel(
|
|
431
|
+
enq.cancel(timeoutEventId);
|
|
420
432
|
}
|
|
421
433
|
return result;
|
|
422
434
|
}
|
|
423
|
-
enq.cancel(
|
|
435
|
+
enq.cancel(timeoutEventId);
|
|
424
436
|
return {
|
|
425
437
|
target,
|
|
426
438
|
reenter
|
|
@@ -429,25 +441,39 @@ function formatTransitions(stateNode) {
|
|
|
429
441
|
});
|
|
430
442
|
};
|
|
431
443
|
for (const invokeDef of stateNode.invoke) {
|
|
432
|
-
const
|
|
444
|
+
const withInvokeMatch = transition => ({
|
|
445
|
+
...transition,
|
|
446
|
+
matches: {
|
|
447
|
+
...transition.matches,
|
|
448
|
+
actorId: invokeDef.id
|
|
449
|
+
},
|
|
450
|
+
_eventMatcher: (event, snapshot) => dist_xstateActors.matchesActorSession(event, snapshot, invokeDef.id)
|
|
451
|
+
});
|
|
452
|
+
const invokeTimeoutEventId = invokeDef.timeout !== undefined ? dist_xstateActors.createInvokeTimeoutEventId(invokeDef.id) : undefined;
|
|
433
453
|
if (invokeDef.onDone) {
|
|
434
|
-
const descriptor =
|
|
435
|
-
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone,
|
|
436
|
-
|
|
437
|
-
|
|
454
|
+
const descriptor = 'xstate.done.actor';
|
|
455
|
+
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone, rawTransition => {
|
|
456
|
+
const transition = withInvokeMatch(rawTransition);
|
|
457
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : dist_xstateActors.formatTransition(stateNode, descriptor, transition);
|
|
458
|
+
});
|
|
459
|
+
if (invokeTimeoutEventId) {
|
|
460
|
+
invokeDoneTransitions.push(createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id));
|
|
438
461
|
}
|
|
439
|
-
|
|
440
|
-
} else if (
|
|
441
|
-
const descriptor =
|
|
442
|
-
|
|
462
|
+
addTransitions(descriptor, invokeDoneTransitions);
|
|
463
|
+
} else if (invokeTimeoutEventId) {
|
|
464
|
+
const descriptor = 'xstate.done.actor';
|
|
465
|
+
addTransitions(descriptor, [createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id)]);
|
|
443
466
|
}
|
|
444
467
|
if (invokeDef.onError) {
|
|
445
|
-
const descriptor =
|
|
446
|
-
|
|
468
|
+
const descriptor = 'xstate.error.actor';
|
|
469
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onError, rawTransition => {
|
|
470
|
+
const transition = withInvokeMatch(rawTransition);
|
|
471
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : dist_xstateActors.formatTransition(stateNode, descriptor, transition);
|
|
472
|
+
}));
|
|
447
473
|
}
|
|
448
474
|
if (invokeDef.onSnapshot) {
|
|
449
|
-
const descriptor =
|
|
450
|
-
|
|
475
|
+
const descriptor = 'xstate.snapshot.actor';
|
|
476
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onSnapshot, transition => dist_xstateActors.formatTransition(stateNode, descriptor, withInvokeMatch(transition))));
|
|
451
477
|
}
|
|
452
478
|
}
|
|
453
479
|
for (const delayedTransition of stateNode.after) {
|
|
@@ -914,7 +940,8 @@ class StateMachine {
|
|
|
914
940
|
const src = actorData.src;
|
|
915
941
|
const logic = typeof src === 'string' ? dist_xstateActors.resolveReferencedActor(this, src) : src;
|
|
916
942
|
if (!logic) {
|
|
917
|
-
|
|
943
|
+
const sourceId = typeof src === 'string' ? src : '<unknown>';
|
|
944
|
+
throw new Error(`Unable to restore child actor '${actorId}': child source '${sourceId}' is not provided in machine '${this.id}'.`);
|
|
918
945
|
}
|
|
919
946
|
const actor = resolvedActorScope.system.createActorRef(logic, {
|
|
920
947
|
id: actorId,
|
|
@@ -922,6 +949,7 @@ class StateMachine {
|
|
|
922
949
|
syncSnapshot: actorData.syncSnapshot,
|
|
923
950
|
snapshot: childState,
|
|
924
951
|
src,
|
|
952
|
+
_sessionId: actorData.sessionId,
|
|
925
953
|
registryKey: actorData.registryKey
|
|
926
954
|
});
|
|
927
955
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as
|
|
1
|
+
import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as getCandidates, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as $$ACTOR_TYPE } from './index-cf2e8954.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, actorSources, spawnedChildren) {
|
|
4
4
|
return (src, options) => {
|
|
@@ -182,8 +182,8 @@ class StateNode {
|
|
|
182
182
|
*/
|
|
183
183
|
this.meta = void 0;
|
|
184
184
|
/**
|
|
185
|
-
* The output data sent with the
|
|
186
|
-
*
|
|
185
|
+
* The output data sent with the `xstate.done.state` event if this is a final
|
|
186
|
+
* state node.
|
|
187
187
|
*/
|
|
188
188
|
this.output = void 0;
|
|
189
189
|
/**
|
|
@@ -300,8 +300,7 @@ class StateNode {
|
|
|
300
300
|
|
|
301
301
|
/** @internal */
|
|
302
302
|
next(snapshot, event, self) {
|
|
303
|
-
const
|
|
304
|
-
const candidates = memo(this, `candidates-${eventType}`, () => getCandidates(this, eventType));
|
|
303
|
+
const candidates = memo(this, `candidates-${getEventDescriptorKey(event)}`, () => getCandidates(this, event));
|
|
305
304
|
for (const candidate of candidates) {
|
|
306
305
|
const guardPassed = evaluateCandidate(candidate, event, snapshot, this, self);
|
|
307
306
|
if (guardPassed) {
|
|
@@ -342,6 +341,9 @@ function mapTransitionConfigs(transitionsConfig, mapper) {
|
|
|
342
341
|
}
|
|
343
342
|
function formatTransitions(stateNode) {
|
|
344
343
|
const transitions = new Map();
|
|
344
|
+
const addTransitions = (descriptor, additions) => {
|
|
345
|
+
transitions.set(descriptor, [...(transitions.get(descriptor) ?? []), ...additions]);
|
|
346
|
+
};
|
|
345
347
|
if (stateNode.config.on) {
|
|
346
348
|
for (const descriptor of Object.keys(stateNode.config.on)) {
|
|
347
349
|
if (descriptor === NULL_EVENT) {
|
|
@@ -352,20 +354,30 @@ function formatTransitions(stateNode) {
|
|
|
352
354
|
}
|
|
353
355
|
}
|
|
354
356
|
if (stateNode.config.onDone) {
|
|
355
|
-
const descriptor =
|
|
356
|
-
|
|
357
|
+
const descriptor = 'xstate.done.state';
|
|
358
|
+
addTransitions(descriptor, mapTransitionConfigs(stateNode.config.onDone, transition => formatTransition(stateNode, descriptor, {
|
|
359
|
+
...transition,
|
|
360
|
+
matches: {
|
|
361
|
+
...transition.matches,
|
|
362
|
+
stateId: stateNode.id
|
|
363
|
+
}
|
|
364
|
+
})));
|
|
357
365
|
}
|
|
358
366
|
if (stateNode.config.onError) {
|
|
359
367
|
const descriptor = 'xstate.error.*';
|
|
360
368
|
transitions.set(descriptor, mapTransitionConfigs(stateNode.config.onError, transition => formatTransition(stateNode, descriptor, transition)));
|
|
361
369
|
}
|
|
362
|
-
const createCancelInvokeTimeoutTransition = (descriptor,
|
|
370
|
+
const createCancelInvokeTimeoutTransition = (descriptor, timeoutEventId, actorId) => formatTransition(stateNode, descriptor, {
|
|
371
|
+
matches: {
|
|
372
|
+
actorId
|
|
373
|
+
},
|
|
374
|
+
_eventMatcher: (event, snapshot) => matchesActorSession(event, snapshot, actorId),
|
|
363
375
|
to: (_args, enq) => {
|
|
364
|
-
enq.cancel(
|
|
376
|
+
enq.cancel(timeoutEventId);
|
|
365
377
|
return {};
|
|
366
378
|
}
|
|
367
379
|
});
|
|
368
|
-
const formatInvokeCompletionTransition = (descriptor, transitionConfig,
|
|
380
|
+
const formatInvokeCompletionTransition = (descriptor, transitionConfig, timeoutEventId) => {
|
|
369
381
|
const {
|
|
370
382
|
target,
|
|
371
383
|
to,
|
|
@@ -396,11 +408,11 @@ function formatTransitions(stateNode) {
|
|
|
396
408
|
});
|
|
397
409
|
const result = to(args, trackingEnqueue);
|
|
398
410
|
if (result !== undefined || didEnqueue) {
|
|
399
|
-
enq.cancel(
|
|
411
|
+
enq.cancel(timeoutEventId);
|
|
400
412
|
}
|
|
401
413
|
return result;
|
|
402
414
|
}
|
|
403
|
-
enq.cancel(
|
|
415
|
+
enq.cancel(timeoutEventId);
|
|
404
416
|
return {
|
|
405
417
|
target,
|
|
406
418
|
reenter
|
|
@@ -409,25 +421,39 @@ function formatTransitions(stateNode) {
|
|
|
409
421
|
});
|
|
410
422
|
};
|
|
411
423
|
for (const invokeDef of stateNode.invoke) {
|
|
412
|
-
const
|
|
424
|
+
const withInvokeMatch = transition => ({
|
|
425
|
+
...transition,
|
|
426
|
+
matches: {
|
|
427
|
+
...transition.matches,
|
|
428
|
+
actorId: invokeDef.id
|
|
429
|
+
},
|
|
430
|
+
_eventMatcher: (event, snapshot) => matchesActorSession(event, snapshot, invokeDef.id)
|
|
431
|
+
});
|
|
432
|
+
const invokeTimeoutEventId = invokeDef.timeout !== undefined ? createInvokeTimeoutEventId(invokeDef.id) : undefined;
|
|
413
433
|
if (invokeDef.onDone) {
|
|
414
|
-
const descriptor =
|
|
415
|
-
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone,
|
|
416
|
-
|
|
417
|
-
|
|
434
|
+
const descriptor = 'xstate.done.actor';
|
|
435
|
+
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone, rawTransition => {
|
|
436
|
+
const transition = withInvokeMatch(rawTransition);
|
|
437
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : formatTransition(stateNode, descriptor, transition);
|
|
438
|
+
});
|
|
439
|
+
if (invokeTimeoutEventId) {
|
|
440
|
+
invokeDoneTransitions.push(createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id));
|
|
418
441
|
}
|
|
419
|
-
|
|
420
|
-
} else if (
|
|
421
|
-
const descriptor =
|
|
422
|
-
|
|
442
|
+
addTransitions(descriptor, invokeDoneTransitions);
|
|
443
|
+
} else if (invokeTimeoutEventId) {
|
|
444
|
+
const descriptor = 'xstate.done.actor';
|
|
445
|
+
addTransitions(descriptor, [createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id)]);
|
|
423
446
|
}
|
|
424
447
|
if (invokeDef.onError) {
|
|
425
|
-
const descriptor =
|
|
426
|
-
|
|
448
|
+
const descriptor = 'xstate.error.actor';
|
|
449
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onError, rawTransition => {
|
|
450
|
+
const transition = withInvokeMatch(rawTransition);
|
|
451
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : formatTransition(stateNode, descriptor, transition);
|
|
452
|
+
}));
|
|
427
453
|
}
|
|
428
454
|
if (invokeDef.onSnapshot) {
|
|
429
|
-
const descriptor =
|
|
430
|
-
|
|
455
|
+
const descriptor = 'xstate.snapshot.actor';
|
|
456
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onSnapshot, transition => formatTransition(stateNode, descriptor, withInvokeMatch(transition))));
|
|
431
457
|
}
|
|
432
458
|
}
|
|
433
459
|
for (const delayedTransition of stateNode.after) {
|
|
@@ -883,7 +909,8 @@ class StateMachine {
|
|
|
883
909
|
const src = actorData.src;
|
|
884
910
|
const logic = typeof src === 'string' ? resolveReferencedActor(this, src) : src;
|
|
885
911
|
if (!logic) {
|
|
886
|
-
|
|
912
|
+
const sourceId = typeof src === 'string' ? src : '<unknown>';
|
|
913
|
+
throw new Error(`Unable to restore child actor '${actorId}': child source '${sourceId}' is not provided in machine '${this.id}'.`);
|
|
887
914
|
}
|
|
888
915
|
const actor = resolvedActorScope.system.createActorRef(logic, {
|
|
889
916
|
id: actorId,
|
|
@@ -891,6 +918,7 @@ class StateMachine {
|
|
|
891
918
|
syncSnapshot: actorData.syncSnapshot,
|
|
892
919
|
snapshot: childState,
|
|
893
920
|
src,
|
|
921
|
+
_sessionId: actorData.sessionId,
|
|
894
922
|
registryKey: actorData.registryKey
|
|
895
923
|
});
|
|
896
924
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
package/dist/{StateMachine-d2247245.development.esm.js → StateMachine-f3d5f2d8.development.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as
|
|
1
|
+
import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as getCandidates, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as $$ACTOR_TYPE } from './index-1a180503.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, actorSources, spawnedChildren) {
|
|
4
4
|
return (src, options) => {
|
|
@@ -183,8 +183,8 @@ class StateNode {
|
|
|
183
183
|
*/
|
|
184
184
|
this.meta = void 0;
|
|
185
185
|
/**
|
|
186
|
-
* The output data sent with the
|
|
187
|
-
*
|
|
186
|
+
* The output data sent with the `xstate.done.state` event if this is a final
|
|
187
|
+
* state node.
|
|
188
188
|
*/
|
|
189
189
|
this.output = void 0;
|
|
190
190
|
/**
|
|
@@ -301,8 +301,7 @@ class StateNode {
|
|
|
301
301
|
|
|
302
302
|
/** @internal */
|
|
303
303
|
next(snapshot, event, self) {
|
|
304
|
-
const
|
|
305
|
-
const candidates = memo(this, `candidates-${eventType}`, () => getCandidates(this, eventType));
|
|
304
|
+
const candidates = memo(this, `candidates-${getEventDescriptorKey(event)}`, () => getCandidates(this, event));
|
|
306
305
|
for (const candidate of candidates) {
|
|
307
306
|
const guardPassed = evaluateCandidate(candidate, event, snapshot, this, self);
|
|
308
307
|
if (guardPassed) {
|
|
@@ -360,6 +359,9 @@ function mapTransitionConfigs(transitionsConfig, mapper) {
|
|
|
360
359
|
}
|
|
361
360
|
function formatTransitions(stateNode) {
|
|
362
361
|
const transitions = new Map();
|
|
362
|
+
const addTransitions = (descriptor, additions) => {
|
|
363
|
+
transitions.set(descriptor, [...(transitions.get(descriptor) ?? []), ...additions]);
|
|
364
|
+
};
|
|
363
365
|
if (stateNode.config.on) {
|
|
364
366
|
for (const descriptor of Object.keys(stateNode.config.on)) {
|
|
365
367
|
if (descriptor === NULL_EVENT) {
|
|
@@ -370,20 +372,30 @@ function formatTransitions(stateNode) {
|
|
|
370
372
|
}
|
|
371
373
|
}
|
|
372
374
|
if (stateNode.config.onDone) {
|
|
373
|
-
const descriptor =
|
|
374
|
-
|
|
375
|
+
const descriptor = 'xstate.done.state';
|
|
376
|
+
addTransitions(descriptor, mapTransitionConfigs(stateNode.config.onDone, transition => formatTransition(stateNode, descriptor, {
|
|
377
|
+
...transition,
|
|
378
|
+
matches: {
|
|
379
|
+
...transition.matches,
|
|
380
|
+
stateId: stateNode.id
|
|
381
|
+
}
|
|
382
|
+
})));
|
|
375
383
|
}
|
|
376
384
|
if (stateNode.config.onError) {
|
|
377
385
|
const descriptor = 'xstate.error.*';
|
|
378
386
|
transitions.set(descriptor, mapTransitionConfigs(stateNode.config.onError, transition => formatTransition(stateNode, descriptor, transition)));
|
|
379
387
|
}
|
|
380
|
-
const createCancelInvokeTimeoutTransition = (descriptor,
|
|
388
|
+
const createCancelInvokeTimeoutTransition = (descriptor, timeoutEventId, actorId) => formatTransition(stateNode, descriptor, {
|
|
389
|
+
matches: {
|
|
390
|
+
actorId
|
|
391
|
+
},
|
|
392
|
+
_eventMatcher: (event, snapshot) => matchesActorSession(event, snapshot, actorId),
|
|
381
393
|
to: (_args, enq) => {
|
|
382
|
-
enq.cancel(
|
|
394
|
+
enq.cancel(timeoutEventId);
|
|
383
395
|
return {};
|
|
384
396
|
}
|
|
385
397
|
});
|
|
386
|
-
const formatInvokeCompletionTransition = (descriptor, transitionConfig,
|
|
398
|
+
const formatInvokeCompletionTransition = (descriptor, transitionConfig, timeoutEventId) => {
|
|
387
399
|
const {
|
|
388
400
|
target,
|
|
389
401
|
to,
|
|
@@ -414,11 +426,11 @@ function formatTransitions(stateNode) {
|
|
|
414
426
|
});
|
|
415
427
|
const result = to(args, trackingEnqueue);
|
|
416
428
|
if (result !== undefined || didEnqueue) {
|
|
417
|
-
enq.cancel(
|
|
429
|
+
enq.cancel(timeoutEventId);
|
|
418
430
|
}
|
|
419
431
|
return result;
|
|
420
432
|
}
|
|
421
|
-
enq.cancel(
|
|
433
|
+
enq.cancel(timeoutEventId);
|
|
422
434
|
return {
|
|
423
435
|
target,
|
|
424
436
|
reenter
|
|
@@ -427,25 +439,39 @@ function formatTransitions(stateNode) {
|
|
|
427
439
|
});
|
|
428
440
|
};
|
|
429
441
|
for (const invokeDef of stateNode.invoke) {
|
|
430
|
-
const
|
|
442
|
+
const withInvokeMatch = transition => ({
|
|
443
|
+
...transition,
|
|
444
|
+
matches: {
|
|
445
|
+
...transition.matches,
|
|
446
|
+
actorId: invokeDef.id
|
|
447
|
+
},
|
|
448
|
+
_eventMatcher: (event, snapshot) => matchesActorSession(event, snapshot, invokeDef.id)
|
|
449
|
+
});
|
|
450
|
+
const invokeTimeoutEventId = invokeDef.timeout !== undefined ? createInvokeTimeoutEventId(invokeDef.id) : undefined;
|
|
431
451
|
if (invokeDef.onDone) {
|
|
432
|
-
const descriptor =
|
|
433
|
-
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone,
|
|
434
|
-
|
|
435
|
-
|
|
452
|
+
const descriptor = 'xstate.done.actor';
|
|
453
|
+
const invokeDoneTransitions = mapTransitionConfigs(invokeDef.onDone, rawTransition => {
|
|
454
|
+
const transition = withInvokeMatch(rawTransition);
|
|
455
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : formatTransition(stateNode, descriptor, transition);
|
|
456
|
+
});
|
|
457
|
+
if (invokeTimeoutEventId) {
|
|
458
|
+
invokeDoneTransitions.push(createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id));
|
|
436
459
|
}
|
|
437
|
-
|
|
438
|
-
} else if (
|
|
439
|
-
const descriptor =
|
|
440
|
-
|
|
460
|
+
addTransitions(descriptor, invokeDoneTransitions);
|
|
461
|
+
} else if (invokeTimeoutEventId) {
|
|
462
|
+
const descriptor = 'xstate.done.actor';
|
|
463
|
+
addTransitions(descriptor, [createCancelInvokeTimeoutTransition(descriptor, invokeTimeoutEventId, invokeDef.id)]);
|
|
441
464
|
}
|
|
442
465
|
if (invokeDef.onError) {
|
|
443
|
-
const descriptor =
|
|
444
|
-
|
|
466
|
+
const descriptor = 'xstate.error.actor';
|
|
467
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onError, rawTransition => {
|
|
468
|
+
const transition = withInvokeMatch(rawTransition);
|
|
469
|
+
return invokeTimeoutEventId ? formatInvokeCompletionTransition(descriptor, transition, invokeTimeoutEventId) : formatTransition(stateNode, descriptor, transition);
|
|
470
|
+
}));
|
|
445
471
|
}
|
|
446
472
|
if (invokeDef.onSnapshot) {
|
|
447
|
-
const descriptor =
|
|
448
|
-
|
|
473
|
+
const descriptor = 'xstate.snapshot.actor';
|
|
474
|
+
addTransitions(descriptor, mapTransitionConfigs(invokeDef.onSnapshot, transition => formatTransition(stateNode, descriptor, withInvokeMatch(transition))));
|
|
449
475
|
}
|
|
450
476
|
}
|
|
451
477
|
for (const delayedTransition of stateNode.after) {
|
|
@@ -912,7 +938,8 @@ class StateMachine {
|
|
|
912
938
|
const src = actorData.src;
|
|
913
939
|
const logic = typeof src === 'string' ? resolveReferencedActor(this, src) : src;
|
|
914
940
|
if (!logic) {
|
|
915
|
-
|
|
941
|
+
const sourceId = typeof src === 'string' ? src : '<unknown>';
|
|
942
|
+
throw new Error(`Unable to restore child actor '${actorId}': child source '${sourceId}' is not provided in machine '${this.id}'.`);
|
|
916
943
|
}
|
|
917
944
|
const actor = resolvedActorScope.system.createActorRef(logic, {
|
|
918
945
|
id: actorId,
|
|
@@ -920,6 +947,7 @@ class StateMachine {
|
|
|
920
947
|
syncSnapshot: actorData.syncSnapshot,
|
|
921
948
|
snapshot: childState,
|
|
922
949
|
src,
|
|
950
|
+
_sessionId: actorData.sessionId,
|
|
923
951
|
registryKey: actorData.registryKey
|
|
924
952
|
});
|
|
925
953
|
// Mark so `start()` knows to start this child (freshly invoked/spawned
|
|
@@ -50,8 +50,8 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
|
|
|
50
50
|
*/
|
|
51
51
|
meta?: any;
|
|
52
52
|
/**
|
|
53
|
-
* The output data sent with the
|
|
54
|
-
*
|
|
53
|
+
* The output data sent with the `xstate.done.state` event if this is a final
|
|
54
|
+
* state node.
|
|
55
55
|
*/
|
|
56
56
|
output?: Mapper<MachineContext, EventObject, unknown, EventObject> | NonReducibleUnknown;
|
|
57
57
|
/**
|