xstate 6.0.0-alpha.16 → 6.0.0-alpha.17
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/bin/xstate.js +36 -0
- package/dist/{StateMachine-dfe616b4.development.esm.js → StateMachine-114b1598.development.esm.js} +83 -4
- package/dist/{StateMachine-7572fbeb.development.cjs.js → StateMachine-4d17c47e.development.cjs.js} +83 -4
- package/dist/{StateMachine-18299be7.cjs.js → StateMachine-a10528bb.cjs.js} +83 -1
- package/dist/{StateMachine-4a0a8848.esm.js → StateMachine-c2d32ddd.esm.js} +83 -1
- package/dist/declarations/src/createActor.d.ts +2 -0
- package/dist/declarations/src/types.d.ts +17 -2
- package/dist/{index-64839116.cjs.js → index-1ac35571.cjs.js} +100 -150
- package/dist/{index-5d18ec0c.development.esm.js → index-31e8ad34.development.esm.js} +99 -151
- package/dist/{index-4a0afbfa.development.cjs.js → index-415cdd3a.development.cjs.js} +100 -150
- package/dist/{index-9fc97b9e.esm.js → index-addc01a2.esm.js} +99 -151
- 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 +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +5 -3
- package/dist/xstate.development.cjs.js +5 -3
- package/dist/xstate.development.esm.js +7 -5
- package/dist/xstate.esm.js +7 -5
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +6 -2
package/bin/xstate.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Lightweight `xstate` CLI. Heavy commands are delegated to dedicated
|
|
3
|
+
// packages fetched on demand so the core package stays dependency-free.
|
|
4
|
+
const { spawnSync } = require('child_process');
|
|
5
|
+
|
|
6
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
7
|
+
|
|
8
|
+
switch (command) {
|
|
9
|
+
case 'migrate': {
|
|
10
|
+
// Delegates to @xstate/codemod (ts-morph based v5 → v6 codemods).
|
|
11
|
+
const result = spawnSync(
|
|
12
|
+
process.platform === 'win32' ? 'npx.cmd' : 'npx',
|
|
13
|
+
['-y', '@xstate/codemod', 'migrate', ...rest],
|
|
14
|
+
{ stdio: 'inherit' }
|
|
15
|
+
);
|
|
16
|
+
process.exit(result.status ?? 1);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
case '--help':
|
|
20
|
+
case 'help':
|
|
21
|
+
case undefined:
|
|
22
|
+
console.log(
|
|
23
|
+
[
|
|
24
|
+
'Usage: xstate <command>',
|
|
25
|
+
'',
|
|
26
|
+
'Commands:',
|
|
27
|
+
' migrate [globs...] [--dry] Migrate source files to the current XState version',
|
|
28
|
+
' (delegates to @xstate/codemod)'
|
|
29
|
+
].join('\n')
|
|
30
|
+
);
|
|
31
|
+
process.exit(command ? 0 : 1);
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
console.error(`Unknown command: ${command}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
package/dist/{StateMachine-dfe616b4.development.esm.js → StateMachine-114b1598.development.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus, G as resolveReferencedActor, d as createActor, S as STATE_DELIMITER, H as mapValues, t as toArray, I as createInvokeId, J as getDelayedTransitions, K as evaluateCandidate, L as formatTransition, N as NULL_EVENT, M as toTransitionConfigArray, O as createInvokeTimeoutEvent, Q as getCandidates, R as formatRouteTransitions, U as resolveStateValue, V as getAllStateNodes, k as getStateNodes, W as createMachineSnapshot, Y as isInFinalState, e as macrostep, Z as cloneMachineSnapshot, _ as transitionNode, m as matchesEventDescriptor, r as resolveActionsWithContext, f as createInitEvent, g as initialMicrostep,
|
|
1
|
+
import { P as ProcessingStatus, G as resolveReferencedActor, d as createActor, S as STATE_DELIMITER, H as mapValues, t as toArray, I as createInvokeId, J as getDelayedTransitions, K as evaluateCandidate, L as formatTransition, N as NULL_EVENT, M as toTransitionConfigArray, O as createInvokeTimeoutEvent, Q as getCandidates, R as formatRouteTransitions, U as resolveStateValue, V as getAllStateNodes, k as getStateNodes, W as createMachineSnapshot, Y as isInFinalState, e as macrostep, Z as cloneMachineSnapshot, _ as transitionNode, m as matchesEventDescriptor, $ as getTransitionResult, a0 as hasEffect, a1 as createErrorPlatformEvent, r as resolveActionsWithContext, f as createInitEvent, g as initialMicrostep, a2 as toStatePath, a3 as isStateId, a4 as getStateNodeByPath, a5 as getPersistedSnapshot, a6 as $$ACTOR_TYPE } from './index-31e8ad34.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -403,6 +403,45 @@ function formatInitialTransition(stateNode, _target) {
|
|
|
403
403
|
}
|
|
404
404
|
|
|
405
405
|
const STATE_IDENTIFIER = '#';
|
|
406
|
+
let emptyCanActor;
|
|
407
|
+
let emptyCanActorScope;
|
|
408
|
+
function getEmptyCanActor() {
|
|
409
|
+
// A minimal inert actor used purely as the `self`/`parent` argument when
|
|
410
|
+
// dry-running transitions for `snapshot.can(...)`. Intentionally not built
|
|
411
|
+
// on `createLogic` so `can()` does not pull that machinery into bundles.
|
|
412
|
+
return emptyCanActor ??= createActor({
|
|
413
|
+
transition: snapshot => [snapshot, []],
|
|
414
|
+
initialTransition: () => [{
|
|
415
|
+
status: 'active',
|
|
416
|
+
output: undefined,
|
|
417
|
+
error: undefined
|
|
418
|
+
}, []],
|
|
419
|
+
getInitialSnapshot: () => ({
|
|
420
|
+
status: 'active',
|
|
421
|
+
output: undefined,
|
|
422
|
+
error: undefined
|
|
423
|
+
}),
|
|
424
|
+
getPersistedSnapshot: snapshot => snapshot
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
function getEmptyCanActorScope() {
|
|
428
|
+
if (emptyCanActorScope) {
|
|
429
|
+
return emptyCanActorScope;
|
|
430
|
+
}
|
|
431
|
+
const actor = getEmptyCanActor();
|
|
432
|
+
emptyCanActorScope = {
|
|
433
|
+
self: actor,
|
|
434
|
+
logger: () => {},
|
|
435
|
+
id: '',
|
|
436
|
+
sessionId: '',
|
|
437
|
+
defer: () => {},
|
|
438
|
+
system: actor.system,
|
|
439
|
+
stopChild: () => {},
|
|
440
|
+
emit: () => {},
|
|
441
|
+
actionExecutor: () => {}
|
|
442
|
+
};
|
|
443
|
+
return emptyCanActorScope;
|
|
444
|
+
}
|
|
406
445
|
class StateMachine {
|
|
407
446
|
constructor(/** The raw config used to create the machine. */
|
|
408
447
|
config, implementations) {
|
|
@@ -469,9 +508,6 @@ class StateMachine {
|
|
|
469
508
|
this.root._refreshEventMetadata();
|
|
470
509
|
this.states = this.root.states; // TODO: remove!
|
|
471
510
|
this.events = this.root.events;
|
|
472
|
-
if (!('output' in this.root) && Object.values(this.states).some(state => state.type === 'final' && 'output' in state)) {
|
|
473
|
-
console.warn('Missing `machine.output` declaration (top-level final state with output detected)');
|
|
474
|
-
}
|
|
475
511
|
}
|
|
476
512
|
|
|
477
513
|
/**
|
|
@@ -611,6 +647,49 @@ class StateMachine {
|
|
|
611
647
|
return false;
|
|
612
648
|
}
|
|
613
649
|
|
|
650
|
+
/**
|
|
651
|
+
* Determines whether sending the `event` to the given snapshot would select a
|
|
652
|
+
* non-forbidden transition. Backs `snapshot.can(...)`; lives here so that
|
|
653
|
+
* non-machine bundles don't pay for the transition-resolution machinery.
|
|
654
|
+
*
|
|
655
|
+
* @internal
|
|
656
|
+
*/
|
|
657
|
+
_canTransition(snapshot, event) {
|
|
658
|
+
const emptyActor = getEmptyCanActor();
|
|
659
|
+
const emptyActorScope = getEmptyCanActorScope();
|
|
660
|
+
const transitionData = this.getTransitionData(snapshot, event, emptyActor);
|
|
661
|
+
if (!transitionData?.length) {
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// Check that at least one transition is not forbidden
|
|
666
|
+
for (const transition of transitionData) {
|
|
667
|
+
if (transition.target !== undefined) {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
const res = getTransitionResult(transition, snapshot, event, emptyActorScope, {
|
|
671
|
+
resolveActions: false
|
|
672
|
+
});
|
|
673
|
+
if (res.targets?.length || res.context || hasEffect(transition, snapshot.context, event, snapshot, emptyActor)) {
|
|
674
|
+
return true;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Returns the error event that the actor should transition with to recover
|
|
682
|
+
* from an execution error, if any active state node declares `onError`.
|
|
683
|
+
*
|
|
684
|
+
* @internal
|
|
685
|
+
*/
|
|
686
|
+
getExecutionErrorEvent(snapshot, error) {
|
|
687
|
+
if (snapshot?.status !== 'active' || !snapshot._nodes?.some(stateNode => stateNode.config.onError)) {
|
|
688
|
+
return undefined;
|
|
689
|
+
}
|
|
690
|
+
return createErrorPlatformEvent('execution', error);
|
|
691
|
+
}
|
|
692
|
+
|
|
614
693
|
/**
|
|
615
694
|
* The initial state _before_ evaluating any microsteps. This "pre-initial"
|
|
616
695
|
* state is provided to initial actions executed in the initial state.
|
package/dist/{StateMachine-7572fbeb.development.cjs.js → StateMachine-4d17c47e.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-415cdd3a.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -405,6 +405,45 @@ function formatInitialTransition(stateNode, _target) {
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
const STATE_IDENTIFIER = '#';
|
|
408
|
+
let emptyCanActor;
|
|
409
|
+
let emptyCanActorScope;
|
|
410
|
+
function getEmptyCanActor() {
|
|
411
|
+
// A minimal inert actor used purely as the `self`/`parent` argument when
|
|
412
|
+
// dry-running transitions for `snapshot.can(...)`. Intentionally not built
|
|
413
|
+
// on `createLogic` so `can()` does not pull that machinery into bundles.
|
|
414
|
+
return emptyCanActor ??= dist_xstateActors.createActor({
|
|
415
|
+
transition: snapshot => [snapshot, []],
|
|
416
|
+
initialTransition: () => [{
|
|
417
|
+
status: 'active',
|
|
418
|
+
output: undefined,
|
|
419
|
+
error: undefined
|
|
420
|
+
}, []],
|
|
421
|
+
getInitialSnapshot: () => ({
|
|
422
|
+
status: 'active',
|
|
423
|
+
output: undefined,
|
|
424
|
+
error: undefined
|
|
425
|
+
}),
|
|
426
|
+
getPersistedSnapshot: snapshot => snapshot
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
function getEmptyCanActorScope() {
|
|
430
|
+
if (emptyCanActorScope) {
|
|
431
|
+
return emptyCanActorScope;
|
|
432
|
+
}
|
|
433
|
+
const actor = getEmptyCanActor();
|
|
434
|
+
emptyCanActorScope = {
|
|
435
|
+
self: actor,
|
|
436
|
+
logger: () => {},
|
|
437
|
+
id: '',
|
|
438
|
+
sessionId: '',
|
|
439
|
+
defer: () => {},
|
|
440
|
+
system: actor.system,
|
|
441
|
+
stopChild: () => {},
|
|
442
|
+
emit: () => {},
|
|
443
|
+
actionExecutor: () => {}
|
|
444
|
+
};
|
|
445
|
+
return emptyCanActorScope;
|
|
446
|
+
}
|
|
408
447
|
class StateMachine {
|
|
409
448
|
constructor(/** The raw config used to create the machine. */
|
|
410
449
|
config, implementations) {
|
|
@@ -471,9 +510,6 @@ class StateMachine {
|
|
|
471
510
|
this.root._refreshEventMetadata();
|
|
472
511
|
this.states = this.root.states; // TODO: remove!
|
|
473
512
|
this.events = this.root.events;
|
|
474
|
-
if (!('output' in this.root) && Object.values(this.states).some(state => state.type === 'final' && 'output' in state)) {
|
|
475
|
-
console.warn('Missing `machine.output` declaration (top-level final state with output detected)');
|
|
476
|
-
}
|
|
477
513
|
}
|
|
478
514
|
|
|
479
515
|
/**
|
|
@@ -613,6 +649,49 @@ class StateMachine {
|
|
|
613
649
|
return false;
|
|
614
650
|
}
|
|
615
651
|
|
|
652
|
+
/**
|
|
653
|
+
* Determines whether sending the `event` to the given snapshot would select a
|
|
654
|
+
* non-forbidden transition. Backs `snapshot.can(...)`; lives here so that
|
|
655
|
+
* non-machine bundles don't pay for the transition-resolution machinery.
|
|
656
|
+
*
|
|
657
|
+
* @internal
|
|
658
|
+
*/
|
|
659
|
+
_canTransition(snapshot, event) {
|
|
660
|
+
const emptyActor = getEmptyCanActor();
|
|
661
|
+
const emptyActorScope = getEmptyCanActorScope();
|
|
662
|
+
const transitionData = this.getTransitionData(snapshot, event, emptyActor);
|
|
663
|
+
if (!transitionData?.length) {
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// Check that at least one transition is not forbidden
|
|
668
|
+
for (const transition of transitionData) {
|
|
669
|
+
if (transition.target !== undefined) {
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
const res = dist_xstateActors.getTransitionResult(transition, snapshot, event, emptyActorScope, {
|
|
673
|
+
resolveActions: false
|
|
674
|
+
});
|
|
675
|
+
if (res.targets?.length || res.context || dist_xstateActors.hasEffect(transition, snapshot.context, event, snapshot, emptyActor)) {
|
|
676
|
+
return true;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Returns the error event that the actor should transition with to recover
|
|
684
|
+
* from an execution error, if any active state node declares `onError`.
|
|
685
|
+
*
|
|
686
|
+
* @internal
|
|
687
|
+
*/
|
|
688
|
+
getExecutionErrorEvent(snapshot, error) {
|
|
689
|
+
if (snapshot?.status !== 'active' || !snapshot._nodes?.some(stateNode => stateNode.config.onError)) {
|
|
690
|
+
return undefined;
|
|
691
|
+
}
|
|
692
|
+
return dist_xstateActors.createErrorPlatformEvent('execution', error);
|
|
693
|
+
}
|
|
694
|
+
|
|
616
695
|
/**
|
|
617
696
|
* The initial state _before_ evaluating any microsteps. This "pre-initial"
|
|
618
697
|
* state is provided to initial actions executed in the initial state.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-1ac35571.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, {
|
|
6
6
|
machine,
|
|
@@ -387,6 +387,45 @@ function formatInitialTransition(stateNode, _target) {
|
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
const STATE_IDENTIFIER = '#';
|
|
390
|
+
let emptyCanActor;
|
|
391
|
+
let emptyCanActorScope;
|
|
392
|
+
function getEmptyCanActor() {
|
|
393
|
+
// A minimal inert actor used purely as the `self`/`parent` argument when
|
|
394
|
+
// dry-running transitions for `snapshot.can(...)`. Intentionally not built
|
|
395
|
+
// on `createLogic` so `can()` does not pull that machinery into bundles.
|
|
396
|
+
return emptyCanActor ??= dist_xstateActors.createActor({
|
|
397
|
+
transition: snapshot => [snapshot, []],
|
|
398
|
+
initialTransition: () => [{
|
|
399
|
+
status: 'active',
|
|
400
|
+
output: undefined,
|
|
401
|
+
error: undefined
|
|
402
|
+
}, []],
|
|
403
|
+
getInitialSnapshot: () => ({
|
|
404
|
+
status: 'active',
|
|
405
|
+
output: undefined,
|
|
406
|
+
error: undefined
|
|
407
|
+
}),
|
|
408
|
+
getPersistedSnapshot: snapshot => snapshot
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
function getEmptyCanActorScope() {
|
|
412
|
+
if (emptyCanActorScope) {
|
|
413
|
+
return emptyCanActorScope;
|
|
414
|
+
}
|
|
415
|
+
const actor = getEmptyCanActor();
|
|
416
|
+
emptyCanActorScope = {
|
|
417
|
+
self: actor,
|
|
418
|
+
logger: () => {},
|
|
419
|
+
id: '',
|
|
420
|
+
sessionId: '',
|
|
421
|
+
defer: () => {},
|
|
422
|
+
system: actor.system,
|
|
423
|
+
stopChild: () => {},
|
|
424
|
+
emit: () => {},
|
|
425
|
+
actionExecutor: () => {}
|
|
426
|
+
};
|
|
427
|
+
return emptyCanActorScope;
|
|
428
|
+
}
|
|
390
429
|
class StateMachine {
|
|
391
430
|
constructor(/** The raw config used to create the machine. */
|
|
392
431
|
config, implementations) {
|
|
@@ -581,6 +620,49 @@ class StateMachine {
|
|
|
581
620
|
return false;
|
|
582
621
|
}
|
|
583
622
|
|
|
623
|
+
/**
|
|
624
|
+
* Determines whether sending the `event` to the given snapshot would select a
|
|
625
|
+
* non-forbidden transition. Backs `snapshot.can(...)`; lives here so that
|
|
626
|
+
* non-machine bundles don't pay for the transition-resolution machinery.
|
|
627
|
+
*
|
|
628
|
+
* @internal
|
|
629
|
+
*/
|
|
630
|
+
_canTransition(snapshot, event) {
|
|
631
|
+
const emptyActor = getEmptyCanActor();
|
|
632
|
+
const emptyActorScope = getEmptyCanActorScope();
|
|
633
|
+
const transitionData = this.getTransitionData(snapshot, event, emptyActor);
|
|
634
|
+
if (!transitionData?.length) {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Check that at least one transition is not forbidden
|
|
639
|
+
for (const transition of transitionData) {
|
|
640
|
+
if (transition.target !== undefined) {
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
const res = dist_xstateActors.getTransitionResult(transition, snapshot, event, emptyActorScope, {
|
|
644
|
+
resolveActions: false
|
|
645
|
+
});
|
|
646
|
+
if (res.targets?.length || res.context || dist_xstateActors.hasEffect(transition, snapshot.context, event, snapshot, emptyActor)) {
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Returns the error event that the actor should transition with to recover
|
|
655
|
+
* from an execution error, if any active state node declares `onError`.
|
|
656
|
+
*
|
|
657
|
+
* @internal
|
|
658
|
+
*/
|
|
659
|
+
getExecutionErrorEvent(snapshot, error) {
|
|
660
|
+
if (snapshot?.status !== 'active' || !snapshot._nodes?.some(stateNode => stateNode.config.onError)) {
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
663
|
+
return dist_xstateActors.createErrorPlatformEvent('execution', error);
|
|
664
|
+
}
|
|
665
|
+
|
|
584
666
|
/**
|
|
585
667
|
* The initial state _before_ evaluating any microsteps. This "pre-initial"
|
|
586
668
|
* state is provided to initial actions executed in the initial state.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ProcessingStatus, G as resolveReferencedActor, d as createActor, S as STATE_DELIMITER, H as mapValues, t as toArray, I as createInvokeId, J as getDelayedTransitions, K as evaluateCandidate, L as formatTransition, N as NULL_EVENT, M as toTransitionConfigArray, O as createInvokeTimeoutEvent, Q as getCandidates, R as formatRouteTransitions, U as resolveStateValue, V as getAllStateNodes, k as getStateNodes, W as createMachineSnapshot, Y as isInFinalState, e as macrostep, Z as cloneMachineSnapshot, _ as transitionNode, m as matchesEventDescriptor, r as resolveActionsWithContext, f as createInitEvent, g as initialMicrostep,
|
|
1
|
+
import { P as ProcessingStatus, G as resolveReferencedActor, d as createActor, S as STATE_DELIMITER, H as mapValues, t as toArray, I as createInvokeId, J as getDelayedTransitions, K as evaluateCandidate, L as formatTransition, N as NULL_EVENT, M as toTransitionConfigArray, O as createInvokeTimeoutEvent, Q as getCandidates, R as formatRouteTransitions, U as resolveStateValue, V as getAllStateNodes, k as getStateNodes, W as createMachineSnapshot, Y as isInFinalState, e as macrostep, Z as cloneMachineSnapshot, _ as transitionNode, m as matchesEventDescriptor, $ as getTransitionResult, a0 as hasEffect, a1 as createErrorPlatformEvent, r as resolveActionsWithContext, f as createInitEvent, g as initialMicrostep, a2 as toStatePath, a3 as isStateId, a4 as getStateNodeByPath, a5 as getPersistedSnapshot, a6 as $$ACTOR_TYPE } from './index-addc01a2.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, {
|
|
4
4
|
machine,
|
|
@@ -385,6 +385,45 @@ function formatInitialTransition(stateNode, _target) {
|
|
|
385
385
|
}
|
|
386
386
|
|
|
387
387
|
const STATE_IDENTIFIER = '#';
|
|
388
|
+
let emptyCanActor;
|
|
389
|
+
let emptyCanActorScope;
|
|
390
|
+
function getEmptyCanActor() {
|
|
391
|
+
// A minimal inert actor used purely as the `self`/`parent` argument when
|
|
392
|
+
// dry-running transitions for `snapshot.can(...)`. Intentionally not built
|
|
393
|
+
// on `createLogic` so `can()` does not pull that machinery into bundles.
|
|
394
|
+
return emptyCanActor ??= createActor({
|
|
395
|
+
transition: snapshot => [snapshot, []],
|
|
396
|
+
initialTransition: () => [{
|
|
397
|
+
status: 'active',
|
|
398
|
+
output: undefined,
|
|
399
|
+
error: undefined
|
|
400
|
+
}, []],
|
|
401
|
+
getInitialSnapshot: () => ({
|
|
402
|
+
status: 'active',
|
|
403
|
+
output: undefined,
|
|
404
|
+
error: undefined
|
|
405
|
+
}),
|
|
406
|
+
getPersistedSnapshot: snapshot => snapshot
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
function getEmptyCanActorScope() {
|
|
410
|
+
if (emptyCanActorScope) {
|
|
411
|
+
return emptyCanActorScope;
|
|
412
|
+
}
|
|
413
|
+
const actor = getEmptyCanActor();
|
|
414
|
+
emptyCanActorScope = {
|
|
415
|
+
self: actor,
|
|
416
|
+
logger: () => {},
|
|
417
|
+
id: '',
|
|
418
|
+
sessionId: '',
|
|
419
|
+
defer: () => {},
|
|
420
|
+
system: actor.system,
|
|
421
|
+
stopChild: () => {},
|
|
422
|
+
emit: () => {},
|
|
423
|
+
actionExecutor: () => {}
|
|
424
|
+
};
|
|
425
|
+
return emptyCanActorScope;
|
|
426
|
+
}
|
|
388
427
|
class StateMachine {
|
|
389
428
|
constructor(/** The raw config used to create the machine. */
|
|
390
429
|
config, implementations) {
|
|
@@ -579,6 +618,49 @@ class StateMachine {
|
|
|
579
618
|
return false;
|
|
580
619
|
}
|
|
581
620
|
|
|
621
|
+
/**
|
|
622
|
+
* Determines whether sending the `event` to the given snapshot would select a
|
|
623
|
+
* non-forbidden transition. Backs `snapshot.can(...)`; lives here so that
|
|
624
|
+
* non-machine bundles don't pay for the transition-resolution machinery.
|
|
625
|
+
*
|
|
626
|
+
* @internal
|
|
627
|
+
*/
|
|
628
|
+
_canTransition(snapshot, event) {
|
|
629
|
+
const emptyActor = getEmptyCanActor();
|
|
630
|
+
const emptyActorScope = getEmptyCanActorScope();
|
|
631
|
+
const transitionData = this.getTransitionData(snapshot, event, emptyActor);
|
|
632
|
+
if (!transitionData?.length) {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Check that at least one transition is not forbidden
|
|
637
|
+
for (const transition of transitionData) {
|
|
638
|
+
if (transition.target !== undefined) {
|
|
639
|
+
return true;
|
|
640
|
+
}
|
|
641
|
+
const res = getTransitionResult(transition, snapshot, event, emptyActorScope, {
|
|
642
|
+
resolveActions: false
|
|
643
|
+
});
|
|
644
|
+
if (res.targets?.length || res.context || hasEffect(transition, snapshot.context, event, snapshot, emptyActor)) {
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Returns the error event that the actor should transition with to recover
|
|
653
|
+
* from an execution error, if any active state node declares `onError`.
|
|
654
|
+
*
|
|
655
|
+
* @internal
|
|
656
|
+
*/
|
|
657
|
+
getExecutionErrorEvent(snapshot, error) {
|
|
658
|
+
if (snapshot?.status !== 'active' || !snapshot._nodes?.some(stateNode => stateNode.config.onError)) {
|
|
659
|
+
return undefined;
|
|
660
|
+
}
|
|
661
|
+
return createErrorPlatformEvent('execution', error);
|
|
662
|
+
}
|
|
663
|
+
|
|
582
664
|
/**
|
|
583
665
|
* The initial state _before_ evaluating any microsteps. This "pre-initial"
|
|
584
666
|
* state is provided to initial actions executed in the initial state.
|
|
@@ -58,6 +58,8 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
|
|
|
58
58
|
private _deferred;
|
|
59
59
|
private _pendingEffects?;
|
|
60
60
|
private _setErrorSnapshot;
|
|
61
|
+
/** Recover via the logic's error event if possible; otherwise error out. */
|
|
62
|
+
private _recoverOrError;
|
|
61
63
|
private _tryHandleExecutionError;
|
|
62
64
|
private _next;
|
|
63
65
|
private update;
|
|
@@ -327,7 +327,11 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
327
327
|
export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any, any>;
|
|
328
328
|
export type AnyStateNodeConfig = Next_StateNodeConfig<any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
329
329
|
export type AnyStateNode = StateNode<any, any> | StateNode<never, EventObject> | StateNode<any, EventObject> | StateNode<never, any>;
|
|
330
|
-
|
|
330
|
+
type LoosenMachineSnapshot<TSnapshot> = TSnapshot extends MachineSnapshot<any, any, any, any, any, any, any, any> ? Omit<TSnapshot, 'matches' | 'can'> & {
|
|
331
|
+
matches(partialStateValue: StateValue): boolean;
|
|
332
|
+
can(event: any): boolean;
|
|
333
|
+
} : never;
|
|
334
|
+
export type AnyMachineSnapshot = LoosenMachineSnapshot<MachineSnapshot<any, any, any, any, any, any, any, any>>;
|
|
331
335
|
export interface AnyStateMachine extends AnyActorLogic {
|
|
332
336
|
id: string;
|
|
333
337
|
root: AnyStateNode;
|
|
@@ -764,7 +768,11 @@ export type SendableEventFromLogic<TLogic extends AnyActorLogic> = TLogic extend
|
|
|
764
768
|
} ? ExcludeInternalEvents<TEvent, TConfig['internalEvents'] extends readonly EventDescriptor<TEvent>[] ? TConfig['internalEvents'] extends readonly (infer TDesc)[] ? Extract<TDesc, string> : never : never> : TEvent : EventFromLogic<TLogic>;
|
|
765
769
|
type OpaqueMachineSnapshot<TSnapshot extends Snapshot<unknown>> = TSnapshot extends MachineSnapshot<infer TContext, infer TEvent, infer TChildren, infer TStateValue, infer TTag, infer TOutput, infer TMeta, infer _TStateSchema> ? MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any> : TSnapshot;
|
|
766
770
|
export type ActorRefFromLogic<T extends AnyActorLogic> = ActorRef<OpaqueMachineSnapshot<SnapshotFrom<T>>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
|
|
767
|
-
export
|
|
771
|
+
export interface AnyActorRef extends Subscribable<any>, InteropObservable<any> {
|
|
772
|
+
send(event: any): void;
|
|
773
|
+
getSnapshot(): any;
|
|
774
|
+
on(type: string, handler: (emitted: any) => void): Subscription;
|
|
775
|
+
}
|
|
768
776
|
/** The concrete actor instance type produced from actor logic. */
|
|
769
777
|
export type ActorFromLogic<T extends AnyActorLogic> = ActorInstance<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
|
|
770
778
|
type SendableEventFromActorRef<TActorRef, TFallback extends EventObject = AnyEventObject> = [NonNullable<TActorRef>] extends [never] ? TFallback : NonNullable<TActorRef> extends infer TNonNullableActorRef ? TNonNullableActorRef extends {
|
|
@@ -883,6 +891,12 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
883
891
|
* returns such effects can omit this.
|
|
884
892
|
*/
|
|
885
893
|
executeEffects?: (effects: readonly unknown[], actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => void;
|
|
894
|
+
/**
|
|
895
|
+
* Returns an event that the actor should transition with to recover from an
|
|
896
|
+
* execution error, or `undefined` if the given snapshot cannot handle it.
|
|
897
|
+
* Actor logic without error-recovery semantics can omit this.
|
|
898
|
+
*/
|
|
899
|
+
getExecutionErrorEvent?: (snapshot: TSnapshot, error: unknown) => TEvent | undefined;
|
|
886
900
|
}
|
|
887
901
|
export interface AnyActorLogic {
|
|
888
902
|
config?: unknown;
|
|
@@ -893,6 +907,7 @@ export interface AnyActorLogic {
|
|
|
893
907
|
start?(snapshot: any, actorScope: any): void;
|
|
894
908
|
getPersistedSnapshot(snapshot: any, options?: unknown): Snapshot<unknown>;
|
|
895
909
|
executeEffects?(effects: readonly unknown[], actorScope: any): void;
|
|
910
|
+
getExecutionErrorEvent?(snapshot: any, error: unknown): any;
|
|
896
911
|
}
|
|
897
912
|
export type UnknownActorLogic = ActorLogic<any, // snapshot
|
|
898
913
|
any, // event
|