xstate 6.0.0-alpha.47 → 6.0.0-alpha.48
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/README.md +7 -1
- package/dist/{StateMachine-74929087.esm.js → StateMachine-8329769a.esm.js} +10 -7
- package/dist/{StateMachine-ee10f67e.development.esm.js → StateMachine-88b3c26a.development.esm.js} +10 -7
- package/dist/{StateMachine-7046f677.cjs.js → StateMachine-b09d2b00.cjs.js} +15 -12
- package/dist/{StateMachine-70c06bdd.development.cjs.js → StateMachine-b3a890bf.development.cjs.js} +15 -12
- package/dist/{createActor-915ea40c.esm.js → createActor-27287c65.esm.js} +78 -22
- package/dist/{createActor-ff132afa.development.esm.js → createActor-309d77eb.development.esm.js} +78 -22
- package/dist/{createActor-bfe8b6bd.cjs.js → createActor-9b41ade9.cjs.js} +78 -22
- package/dist/{createActor-6736cbbe.development.cjs.js → createActor-cc3d6dde.development.cjs.js} +78 -22
- package/dist/declarations/src/createMachineFromConfig.d.ts +5 -77
- package/dist/declarations/src/scxml/index.d.ts +1 -0
- package/dist/declarations/src/scxml/runtime.d.ts +251 -0
- package/dist/declarations/src/scxml/scxml.d.ts +19 -0
- package/dist/declarations/src/types.d.ts +1 -0
- package/dist/{effectDescriptor-fbe67d5a.development.esm.js → effectDescriptor-7707794b.development.esm.js} +1 -1
- package/dist/{effectDescriptor-3c699328.development.cjs.js → effectDescriptor-a1678d06.development.cjs.js} +1 -1
- package/dist/{effectDescriptor-8be60443.esm.js → effectDescriptor-b1f5deb6.esm.js} +1 -1
- package/dist/{effectDescriptor-a7e2d4d1.cjs.js → effectDescriptor-bd36a33e.cjs.js} +1 -1
- package/dist/types-1793b8b6.development.esm.js +185 -0
- package/dist/types-7e468202.development.cjs.js +189 -0
- package/dist/types-81d03bef.esm.js +185 -0
- package/dist/types-9c1bc85f.cjs.js +189 -0
- package/dist/validation-05f1d517.esm.js +8 -0
- package/dist/validation-4561b43c.cjs.js +10 -0
- package/dist/validation-e69470ad.development.esm.js +8 -0
- package/dist/validation-f2714a35.development.cjs.js +10 -0
- package/dist/xstate-actors.cjs.js +934 -9
- package/dist/xstate-actors.development.cjs.js +934 -9
- package/dist/xstate-actors.development.esm.js +932 -2
- package/dist/xstate-actors.esm.js +932 -2
- package/dist/xstate-durable.cjs.js +2 -2
- package/dist/xstate-durable.development.cjs.js +2 -2
- package/dist/xstate-durable.development.esm.js +2 -2
- package/dist/xstate-durable.esm.js +2 -2
- package/dist/xstate-graph.cjs.js +4 -3
- package/dist/xstate-graph.development.cjs.js +4 -3
- package/dist/xstate-graph.development.esm.js +4 -3
- package/dist/xstate-graph.esm.js +4 -3
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-scxml.cjs.d.mts +2 -0
- package/dist/xstate-scxml.cjs.d.ts +2 -0
- package/dist/xstate-scxml.cjs.js +2387 -0
- package/dist/xstate-scxml.cjs.mjs +3 -0
- package/dist/xstate-scxml.development.cjs.js +2387 -0
- package/dist/xstate-scxml.development.cjs.mjs +3 -0
- package/dist/xstate-scxml.development.esm.js +2383 -0
- package/dist/xstate-scxml.esm.js +2383 -0
- package/dist/xstate-scxml.umd.min.js +26 -0
- package/dist/xstate-scxml.umd.min.js.map +1 -0
- package/dist/xstate-validation.cjs.js +1 -1
- package/dist/xstate-validation.development.cjs.js +1 -1
- package/dist/xstate-validation.development.esm.js +1 -1
- package/dist/xstate-validation.esm.js +1 -1
- package/dist/xstate.cjs.js +141 -1036
- package/dist/xstate.development.cjs.js +141 -1036
- package/dist/xstate.development.esm.js +141 -1035
- package/dist/xstate.esm.js +141 -1035
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +20 -2
- package/scxml/package.json +8 -0
- package/dist/index-0f498ef2.development.cjs.js +0 -946
- package/dist/index-70d56425.development.esm.js +0 -937
- package/dist/index-b051c924.esm.js +0 -937
- package/dist/index-b3fe59bc.cjs.js +0 -946
package/README.md
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
<br />
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
<!-- runtime dependencies and public entry points from package.json -->
|
|
15
|
+
|
|
16
|
+
XState is a state management and orchestration solution for JavaScript and TypeScript apps. The main `xstate` entry point has _zero_ runtime dependencies; the optional `xstate/scxml` entry point uses an XML parser. XState is useful for frontend and backend application logic.
|
|
15
17
|
|
|
16
18
|
It uses event-driven programming, state machines, statecharts, and the actor model to handle complex logic in predictable, robust, and visual ways. XState provides a powerful and flexible way to manage application and workflow state by allowing developers to model logic as actors and state machines.
|
|
17
19
|
|
|
@@ -27,6 +29,10 @@ It uses event-driven programming, state machines, statecharts, and the actor mod
|
|
|
27
29
|
|
|
28
30
|
📑 Inspired by the [SCXML specification](https://www.w3.org/TR/scxml/)
|
|
29
31
|
|
|
32
|
+
<!-- public SCXML entry point from src/scxml/index.ts -->
|
|
33
|
+
|
|
34
|
+
Create machines from SCXML documents with the opt-in `xstate/scxml` entry point. See the [SCXML guide](../../docs/scxml.md).
|
|
35
|
+
|
|
30
36
|
💬 Chat on the [Stately Discord Community](https://discord.gg/xstate)
|
|
31
37
|
|
|
32
38
|
✍️ Browse through the many [XState examples](https://github.com/statelyai/xstate/tree/main/examples)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q as resolveRegisteredActorSource, R as allocateChildId, S as assertChildIdFree, T as reserveChildId, U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, x as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, aa as createInertActorScope, ab as setInertActorScopeSnapshot, a as beginSpawnAllocation, ac as attachSnapshotActorRef, ad as macrostep, ae as isInertActorScope, af as setSnapshotActorRef, ag as cloneMachineSnapshot, ah as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ai as getTransitionResult, aj as hasEffect, ak as createErrorPlatformEvent, al as withActorSelf, r as resolveActionsWithContext, am as takeSpawnAllocationCounters, an as mergeActorIdCounters, K as createInitEvent, ao as createSpawnEffect, ap as initialMicrostep, aq as toStatePath, ar as isStateId, as as getStateNodeByPath, at as getPersistedSnapshot, au as createRemoteActorRef, av as resolveReferencedActor, aw as createInvokeTimeoutEvent, ax as parseGeneratedActorId, ay as ACTOR_REF_TYPE, k as createActor } from './createActor-
|
|
2
|
-
import {
|
|
1
|
+
import { Q as resolveRegisteredActorSource, R as allocateChildId, S as assertChildIdFree, T as reserveChildId, U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, x as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, aa as createInertActorScope, ab as setInertActorScopeSnapshot, a as beginSpawnAllocation, ac as attachSnapshotActorRef, ad as macrostep, ae as isInertActorScope, af as setSnapshotActorRef, ag as cloneMachineSnapshot, ah as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ai as getTransitionResult, aj as hasEffect, ak as createErrorPlatformEvent, al as withActorSelf, r as resolveActionsWithContext, am as takeSpawnAllocationCounters, an as mergeActorIdCounters, K as createInitEvent, ao as createSpawnEffect, ap as initialMicrostep, aq as toStatePath, ar as isStateId, as as getStateNodeByPath, at as getPersistedSnapshot, au as createRemoteActorRef, av as resolveReferencedActor, aw as createInvokeTimeoutEvent, ax as parseGeneratedActorId, ay as ACTOR_REF_TYPE, k as createActor } from './createActor-27287c65.esm.js';
|
|
2
|
+
import { a as assertValid } from './validation-05f1d517.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
5
5
|
return (src, options) => {
|
|
@@ -385,14 +385,17 @@ function formatTransitions(stateNode) {
|
|
|
385
385
|
function formatInitialTransition(stateNode, _target) {
|
|
386
386
|
const targetString = typeof _target === 'object' && _target !== null ? _target.target : _target;
|
|
387
387
|
const input = typeof _target === 'object' && _target !== null ? _target.input : undefined;
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
const to = typeof _target === 'object' && _target !== null ? _target.to : undefined;
|
|
389
|
+
const targetStrings = Array.isArray(targetString) ? targetString : targetString ? [targetString] : [];
|
|
390
|
+
const resolvedTargets = targetStrings.map(target => target.startsWith('#') ? stateNode.machine.getStateNodeById(target.slice(1)) : stateNode.states[target]);
|
|
391
|
+
if (resolvedTargets.some(target => !target)) {
|
|
392
|
+
throw new Error(`Initial state not found on "#${stateNode.id}"`);
|
|
391
393
|
}
|
|
392
394
|
const transition = {
|
|
393
395
|
source: stateNode,
|
|
394
|
-
target:
|
|
395
|
-
input
|
|
396
|
+
target: resolvedTargets.length ? resolvedTargets : undefined,
|
|
397
|
+
input,
|
|
398
|
+
to
|
|
396
399
|
};
|
|
397
400
|
return transition;
|
|
398
401
|
}
|
package/dist/{StateMachine-ee10f67e.development.esm.js → StateMachine-88b3c26a.development.esm.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q as resolveRegisteredActorSource, R as allocateChildId, S as assertChildIdFree, T as reserveChildId, U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, x as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, aa as createInertActorScope, ab as setInertActorScopeSnapshot, a as beginSpawnAllocation, ac as attachSnapshotActorRef, ad as macrostep, ae as isInertActorScope, af as setSnapshotActorRef, ag as cloneMachineSnapshot, ah as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ai as getTransitionResult, aj as hasEffect, ak as createErrorPlatformEvent, al as withActorSelf, r as resolveActionsWithContext, am as takeSpawnAllocationCounters, an as mergeActorIdCounters, K as createInitEvent, ao as createSpawnEffect, ap as initialMicrostep, aq as toStatePath, ar as isStateId, as as getStateNodeByPath, at as getPersistedSnapshot, au as createRemoteActorRef, av as resolveReferencedActor, aw as createInvokeTimeoutEvent, ax as parseGeneratedActorId, ay as ACTOR_REF_TYPE, k as createActor } from './createActor-
|
|
2
|
-
import {
|
|
1
|
+
import { Q as resolveRegisteredActorSource, R as allocateChildId, S as assertChildIdFree, T as reserveChildId, U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, x as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, aa as createInertActorScope, ab as setInertActorScopeSnapshot, a as beginSpawnAllocation, ac as attachSnapshotActorRef, ad as macrostep, ae as isInertActorScope, af as setSnapshotActorRef, ag as cloneMachineSnapshot, ah as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ai as getTransitionResult, aj as hasEffect, ak as createErrorPlatformEvent, al as withActorSelf, r as resolveActionsWithContext, am as takeSpawnAllocationCounters, an as mergeActorIdCounters, K as createInitEvent, ao as createSpawnEffect, ap as initialMicrostep, aq as toStatePath, ar as isStateId, as as getStateNodeByPath, at as getPersistedSnapshot, au as createRemoteActorRef, av as resolveReferencedActor, aw as createInvokeTimeoutEvent, ax as parseGeneratedActorId, ay as ACTOR_REF_TYPE, k as createActor } from './createActor-309d77eb.development.esm.js';
|
|
2
|
+
import { a as assertValid } from './validation-e69470ad.development.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
5
5
|
return (src, options) => {
|
|
@@ -403,14 +403,17 @@ function formatTransitions(stateNode) {
|
|
|
403
403
|
function formatInitialTransition(stateNode, _target) {
|
|
404
404
|
const targetString = typeof _target === 'object' && _target !== null ? _target.target : _target;
|
|
405
405
|
const input = typeof _target === 'object' && _target !== null ? _target.input : undefined;
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
406
|
+
const to = typeof _target === 'object' && _target !== null ? _target.to : undefined;
|
|
407
|
+
const targetStrings = Array.isArray(targetString) ? targetString : targetString ? [targetString] : [];
|
|
408
|
+
const resolvedTargets = targetStrings.map(target => target.startsWith('#') ? stateNode.machine.getStateNodeById(target.slice(1)) : stateNode.states[target]);
|
|
409
|
+
if (resolvedTargets.some(target => !target)) {
|
|
410
|
+
throw new Error(`Initial state node "${targetStrings.find((_, index) => !resolvedTargets[index])}" not found on parent state node #${stateNode.id}` );
|
|
409
411
|
}
|
|
410
412
|
const transition = {
|
|
411
413
|
source: stateNode,
|
|
412
|
-
target:
|
|
413
|
-
input
|
|
414
|
+
target: resolvedTargets.length ? resolvedTargets : undefined,
|
|
415
|
+
input,
|
|
416
|
+
to
|
|
414
417
|
};
|
|
415
418
|
return transition;
|
|
416
419
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
4
|
-
var
|
|
3
|
+
var createActor = require('./createActor-9b41ade9.cjs.js');
|
|
4
|
+
var validation = require('./validation-4561b43c.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
7
7
|
return (src, options) => {
|
|
@@ -387,14 +387,17 @@ function formatTransitions(stateNode) {
|
|
|
387
387
|
function formatInitialTransition(stateNode, _target) {
|
|
388
388
|
const targetString = typeof _target === 'object' && _target !== null ? _target.target : _target;
|
|
389
389
|
const input = typeof _target === 'object' && _target !== null ? _target.input : undefined;
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
390
|
+
const to = typeof _target === 'object' && _target !== null ? _target.to : undefined;
|
|
391
|
+
const targetStrings = Array.isArray(targetString) ? targetString : targetString ? [targetString] : [];
|
|
392
|
+
const resolvedTargets = targetStrings.map(target => target.startsWith('#') ? stateNode.machine.getStateNodeById(target.slice(1)) : stateNode.states[target]);
|
|
393
|
+
if (resolvedTargets.some(target => !target)) {
|
|
394
|
+
throw new Error(`Initial state not found on "#${stateNode.id}"`);
|
|
393
395
|
}
|
|
394
396
|
const transition = {
|
|
395
397
|
source: stateNode,
|
|
396
|
-
target:
|
|
397
|
-
input
|
|
398
|
+
target: resolvedTargets.length ? resolvedTargets : undefined,
|
|
399
|
+
input,
|
|
400
|
+
to
|
|
398
401
|
};
|
|
399
402
|
return transition;
|
|
400
403
|
}
|
|
@@ -712,7 +715,7 @@ class StateMachine {
|
|
|
712
715
|
const usesInertScope = !actorScope;
|
|
713
716
|
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this, snapshot);
|
|
714
717
|
if (this.validator) {
|
|
715
|
-
|
|
718
|
+
validation.assertValid(this.validator, {
|
|
716
719
|
kind: 'event',
|
|
717
720
|
logic: this,
|
|
718
721
|
event,
|
|
@@ -730,7 +733,7 @@ class StateMachine {
|
|
|
730
733
|
}
|
|
731
734
|
const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? createActor.attachSnapshotActorRef(resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
|
|
732
735
|
if (this.validator) {
|
|
733
|
-
|
|
736
|
+
validation.assertValid(this.validator, {
|
|
734
737
|
kind: 'result',
|
|
735
738
|
logic: this,
|
|
736
739
|
snapshot: returnedSnapshot,
|
|
@@ -749,7 +752,7 @@ class StateMachine {
|
|
|
749
752
|
const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : createActor.attachSnapshotActorRef(resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
|
|
750
753
|
const effects = this._collectEffects(microsteps);
|
|
751
754
|
if (this.validator) {
|
|
752
|
-
|
|
755
|
+
validation.assertValid(this.validator, {
|
|
753
756
|
kind: 'result',
|
|
754
757
|
logic: this,
|
|
755
758
|
snapshot: returnedSnapshot,
|
|
@@ -941,7 +944,7 @@ class StateMachine {
|
|
|
941
944
|
}
|
|
942
945
|
initialTransition(input, actorScope) {
|
|
943
946
|
if (this.validator) {
|
|
944
|
-
|
|
947
|
+
validation.assertValid(this.validator, {
|
|
945
948
|
kind: 'input',
|
|
946
949
|
logic: this,
|
|
947
950
|
input
|
|
@@ -961,7 +964,7 @@ class StateMachine {
|
|
|
961
964
|
const returnedSnapshot = usesInertScope ? createActor.attachSnapshotActorRef(resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope, true);
|
|
962
965
|
const effects = this._collectEffects(microsteps);
|
|
963
966
|
if (this.validator) {
|
|
964
|
-
|
|
967
|
+
validation.assertValid(this.validator, {
|
|
965
968
|
kind: 'result',
|
|
966
969
|
logic: this,
|
|
967
970
|
snapshot: returnedSnapshot,
|
package/dist/{StateMachine-70c06bdd.development.cjs.js → StateMachine-b3a890bf.development.cjs.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
4
|
-
var
|
|
3
|
+
var createActor = require('./createActor-cc3d6dde.development.cjs.js');
|
|
4
|
+
var validation = require('./validation-f2714a35.development.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
7
7
|
return (src, options) => {
|
|
@@ -405,14 +405,17 @@ function formatTransitions(stateNode) {
|
|
|
405
405
|
function formatInitialTransition(stateNode, _target) {
|
|
406
406
|
const targetString = typeof _target === 'object' && _target !== null ? _target.target : _target;
|
|
407
407
|
const input = typeof _target === 'object' && _target !== null ? _target.input : undefined;
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
408
|
+
const to = typeof _target === 'object' && _target !== null ? _target.to : undefined;
|
|
409
|
+
const targetStrings = Array.isArray(targetString) ? targetString : targetString ? [targetString] : [];
|
|
410
|
+
const resolvedTargets = targetStrings.map(target => target.startsWith('#') ? stateNode.machine.getStateNodeById(target.slice(1)) : stateNode.states[target]);
|
|
411
|
+
if (resolvedTargets.some(target => !target)) {
|
|
412
|
+
throw new Error(`Initial state node "${targetStrings.find((_, index) => !resolvedTargets[index])}" not found on parent state node #${stateNode.id}` );
|
|
411
413
|
}
|
|
412
414
|
const transition = {
|
|
413
415
|
source: stateNode,
|
|
414
|
-
target:
|
|
415
|
-
input
|
|
416
|
+
target: resolvedTargets.length ? resolvedTargets : undefined,
|
|
417
|
+
input,
|
|
418
|
+
to
|
|
416
419
|
};
|
|
417
420
|
return transition;
|
|
418
421
|
}
|
|
@@ -741,7 +744,7 @@ class StateMachine {
|
|
|
741
744
|
const usesInertScope = !actorScope;
|
|
742
745
|
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(this, snapshot);
|
|
743
746
|
if (this.validator) {
|
|
744
|
-
|
|
747
|
+
validation.assertValid(this.validator, {
|
|
745
748
|
kind: 'event',
|
|
746
749
|
logic: this,
|
|
747
750
|
event,
|
|
@@ -759,7 +762,7 @@ class StateMachine {
|
|
|
759
762
|
}
|
|
760
763
|
const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? createActor.attachSnapshotActorRef(resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
|
|
761
764
|
if (this.validator) {
|
|
762
|
-
|
|
765
|
+
validation.assertValid(this.validator, {
|
|
763
766
|
kind: 'result',
|
|
764
767
|
logic: this,
|
|
765
768
|
snapshot: returnedSnapshot,
|
|
@@ -778,7 +781,7 @@ class StateMachine {
|
|
|
778
781
|
const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : createActor.attachSnapshotActorRef(resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
|
|
779
782
|
const effects = this._collectEffects(microsteps);
|
|
780
783
|
if (this.validator) {
|
|
781
|
-
|
|
784
|
+
validation.assertValid(this.validator, {
|
|
782
785
|
kind: 'result',
|
|
783
786
|
logic: this,
|
|
784
787
|
snapshot: returnedSnapshot,
|
|
@@ -970,7 +973,7 @@ class StateMachine {
|
|
|
970
973
|
}
|
|
971
974
|
initialTransition(input, actorScope) {
|
|
972
975
|
if (this.validator) {
|
|
973
|
-
|
|
976
|
+
validation.assertValid(this.validator, {
|
|
974
977
|
kind: 'input',
|
|
975
978
|
logic: this,
|
|
976
979
|
input
|
|
@@ -990,7 +993,7 @@ class StateMachine {
|
|
|
990
993
|
const returnedSnapshot = usesInertScope ? createActor.attachSnapshotActorRef(resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope, true);
|
|
991
994
|
const effects = this._collectEffects(microsteps);
|
|
992
995
|
if (this.validator) {
|
|
993
|
-
|
|
996
|
+
validation.assertValid(this.validator, {
|
|
994
997
|
kind: 'result',
|
|
995
998
|
logic: this,
|
|
996
999
|
snapshot: returnedSnapshot,
|
|
@@ -2280,7 +2280,8 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
2280
2280
|
target,
|
|
2281
2281
|
source: stateNode,
|
|
2282
2282
|
reenter: false,
|
|
2283
|
-
eventType: ''
|
|
2283
|
+
eventType: '',
|
|
2284
|
+
to: stateNode.config._historyDefaultTransition
|
|
2284
2285
|
};
|
|
2285
2286
|
}
|
|
2286
2287
|
function isHistoryNode(stateNode) {
|
|
@@ -2294,7 +2295,9 @@ function getInitialStateNodes(stateNode) {
|
|
|
2294
2295
|
}
|
|
2295
2296
|
set.add(descStateNode);
|
|
2296
2297
|
if (descStateNode.type === 'compound') {
|
|
2297
|
-
|
|
2298
|
+
for (const target of descStateNode.initial.target ?? []) {
|
|
2299
|
+
iter(target);
|
|
2300
|
+
}
|
|
2298
2301
|
} else if (descStateNode.type === 'parallel') {
|
|
2299
2302
|
for (const child of getChildren(descStateNode)) {
|
|
2300
2303
|
iter(child);
|
|
@@ -2547,6 +2550,18 @@ function getTransitionDomain(transition, snapshot, resolveTransition) {
|
|
|
2547
2550
|
targets,
|
|
2548
2551
|
reenter
|
|
2549
2552
|
} = resolveTransition(transition);
|
|
2553
|
+
if (transition._transitionDomain) {
|
|
2554
|
+
if (transition._transitionDomain === 'internal' && transition.source.type === 'compound' && targetStates.every(target => isDescendant(target, transition.source))) {
|
|
2555
|
+
return transition.source;
|
|
2556
|
+
}
|
|
2557
|
+
const [head, ...tail] = targetStates.concat(transition.source);
|
|
2558
|
+
for (const ancestor of getProperAncestors(head, undefined)) {
|
|
2559
|
+
if (ancestor.type === 'compound' && tail.every(stateNode => isDescendant(stateNode, ancestor))) {
|
|
2560
|
+
return ancestor;
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
return;
|
|
2564
|
+
}
|
|
2550
2565
|
|
|
2551
2566
|
// A history target that restores the source itself must exit and reenter
|
|
2552
2567
|
// the source (SCXML domain = the source's ancestor), unlike a plain
|
|
@@ -2599,12 +2614,28 @@ function computeExitSet(transitions, stateNodeSet, snapshot, resolveTransition)
|
|
|
2599
2614
|
return [...statesToExit];
|
|
2600
2615
|
}
|
|
2601
2616
|
function initialMicrostep(root, preInitialState, actorScope, initEvent, internalQueue) {
|
|
2617
|
+
const initialStateNodes = [...getInitialStateNodes(root)];
|
|
2618
|
+
const statesForDefaultEntry = new Set();
|
|
2619
|
+
const collectDefaultEntryStates = stateNode => {
|
|
2620
|
+
if (stateNode.type === 'compound') {
|
|
2621
|
+
statesForDefaultEntry.add(stateNode);
|
|
2622
|
+
for (const target of stateNode.initial.target ?? []) {
|
|
2623
|
+
collectDefaultEntryStates(target);
|
|
2624
|
+
}
|
|
2625
|
+
} else if (stateNode.type === 'parallel') {
|
|
2626
|
+
for (const child of getChildren(stateNode)) {
|
|
2627
|
+
collectDefaultEntryStates(child);
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
};
|
|
2631
|
+
collectDefaultEntryStates(root);
|
|
2602
2632
|
return microstep([{
|
|
2603
|
-
target:
|
|
2633
|
+
target: initialStateNodes.filter(stateNode => !initialStateNodes.some(other => other !== stateNode && isDescendant(other, stateNode))),
|
|
2604
2634
|
source: root,
|
|
2605
2635
|
reenter: true,
|
|
2606
2636
|
eventType: null,
|
|
2607
|
-
toJSON: null
|
|
2637
|
+
toJSON: null,
|
|
2638
|
+
_statesForDefaultEntry: [...statesForDefaultEntry]
|
|
2608
2639
|
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
2609
2640
|
}
|
|
2610
2641
|
|
|
@@ -2783,6 +2814,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2783
2814
|
// in other words, those are states for which initial actions should be executed
|
|
2784
2815
|
// when we target `#deep_child` initial actions of its ancestors shouldn't be executed
|
|
2785
2816
|
const statesForDefaultEntry = new Set();
|
|
2817
|
+
const historyDefaultsByParent = new Map();
|
|
2786
2818
|
const addAncestorStatesToEnter = (ancestors, reentrancyDomain) => {
|
|
2787
2819
|
for (const anc of ancestors) {
|
|
2788
2820
|
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
@@ -2811,6 +2843,11 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2811
2843
|
}
|
|
2812
2844
|
} else {
|
|
2813
2845
|
const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
|
|
2846
|
+
const historyParent = stateNode.parent;
|
|
2847
|
+
statesForDefaultEntry.add(historyParent);
|
|
2848
|
+
const defaults = historyDefaultsByParent.get(historyParent) ?? [];
|
|
2849
|
+
defaults.push(historyDefaultTransition);
|
|
2850
|
+
historyDefaultsByParent.set(historyParent, defaults);
|
|
2814
2851
|
const {
|
|
2815
2852
|
targets
|
|
2816
2853
|
} = getCurrentTransitionResult(historyDefaultTransition);
|
|
@@ -2828,13 +2865,19 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2828
2865
|
return;
|
|
2829
2866
|
}
|
|
2830
2867
|
if (stateNode.type === 'compound') {
|
|
2831
|
-
const
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2868
|
+
const initialStates = getCurrentTransitionResult(stateNode.initial).targets ?? [];
|
|
2869
|
+
for (const initialState of initialStates) {
|
|
2870
|
+
if (!isHistoryNode(initialState)) {
|
|
2871
|
+
statesToEnter.add(initialState);
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
statesForDefaultEntry.add(stateNode);
|
|
2875
|
+
for (const initialState of initialStates) {
|
|
2876
|
+
addDescendantStatesToEnter(initialState);
|
|
2877
|
+
}
|
|
2878
|
+
for (const initialState of initialStates) {
|
|
2879
|
+
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2835
2880
|
}
|
|
2836
|
-
addDescendantStatesToEnter(initialState);
|
|
2837
|
-
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2838
2881
|
return;
|
|
2839
2882
|
}
|
|
2840
2883
|
if (stateNode.type === 'parallel') {
|
|
@@ -2876,7 +2919,9 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2876
2919
|
}
|
|
2877
2920
|
}
|
|
2878
2921
|
if (isInitial) {
|
|
2879
|
-
|
|
2922
|
+
for (const stateNode of filteredTransitions[0]._statesForDefaultEntry ?? [currentSnapshot.machine.root]) {
|
|
2923
|
+
statesForDefaultEntry.add(stateNode);
|
|
2924
|
+
}
|
|
2880
2925
|
}
|
|
2881
2926
|
const stateInputMap = {
|
|
2882
2927
|
...currentSnapshot._stateInputs
|
|
@@ -2961,17 +3006,28 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2961
3006
|
nextState.context = context;
|
|
2962
3007
|
}
|
|
2963
3008
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
2964
|
-
const
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
3009
|
+
const defaultTransitions = [stateNodeToEnter.initial, ...(historyDefaultsByParent.get(stateNodeToEnter) ?? [])].filter(Boolean);
|
|
3010
|
+
for (const defaultTransition of defaultTransitions) {
|
|
3011
|
+
const {
|
|
3012
|
+
actions: initialActions,
|
|
3013
|
+
context: initialContext,
|
|
3014
|
+
input: initialInput,
|
|
3015
|
+
internalEvents: initialInternalEvents
|
|
3016
|
+
} = getTransitionResult(defaultTransition, nextState, event, actorScope);
|
|
3017
|
+
if (initialActions) {
|
|
3018
|
+
actions.push(...initialActions);
|
|
3019
|
+
}
|
|
3020
|
+
if (initialInternalEvents?.length) {
|
|
3021
|
+
internalQueue.push(...initialInternalEvents);
|
|
3022
|
+
}
|
|
3023
|
+
if (initialContext !== undefined) {
|
|
3024
|
+
nextState.context = mergeContextPatch(nextState.context, initialContext);
|
|
3025
|
+
}
|
|
3026
|
+
if (initialInput && defaultTransition.target) {
|
|
3027
|
+
for (const targetNode of defaultTransition.target) {
|
|
3028
|
+
stateInputMap[targetNode.id] = initialInput;
|
|
3029
|
+
stateInputsChanged = true;
|
|
3030
|
+
}
|
|
2975
3031
|
}
|
|
2976
3032
|
}
|
|
2977
3033
|
}
|
package/dist/{createActor-ff132afa.development.esm.js → createActor-309d77eb.development.esm.js}
RENAMED
|
@@ -2298,7 +2298,8 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
2298
2298
|
target,
|
|
2299
2299
|
source: stateNode,
|
|
2300
2300
|
reenter: false,
|
|
2301
|
-
eventType: ''
|
|
2301
|
+
eventType: '',
|
|
2302
|
+
to: stateNode.config._historyDefaultTransition
|
|
2302
2303
|
};
|
|
2303
2304
|
}
|
|
2304
2305
|
function isHistoryNode(stateNode) {
|
|
@@ -2312,7 +2313,9 @@ function getInitialStateNodes(stateNode) {
|
|
|
2312
2313
|
}
|
|
2313
2314
|
set.add(descStateNode);
|
|
2314
2315
|
if (descStateNode.type === 'compound') {
|
|
2315
|
-
|
|
2316
|
+
for (const target of descStateNode.initial.target ?? []) {
|
|
2317
|
+
iter(target);
|
|
2318
|
+
}
|
|
2316
2319
|
} else if (descStateNode.type === 'parallel') {
|
|
2317
2320
|
for (const child of getChildren(descStateNode)) {
|
|
2318
2321
|
iter(child);
|
|
@@ -2565,6 +2568,18 @@ function getTransitionDomain(transition, snapshot, resolveTransition) {
|
|
|
2565
2568
|
targets,
|
|
2566
2569
|
reenter
|
|
2567
2570
|
} = resolveTransition(transition);
|
|
2571
|
+
if (transition._transitionDomain) {
|
|
2572
|
+
if (transition._transitionDomain === 'internal' && transition.source.type === 'compound' && targetStates.every(target => isDescendant(target, transition.source))) {
|
|
2573
|
+
return transition.source;
|
|
2574
|
+
}
|
|
2575
|
+
const [head, ...tail] = targetStates.concat(transition.source);
|
|
2576
|
+
for (const ancestor of getProperAncestors(head, undefined)) {
|
|
2577
|
+
if (ancestor.type === 'compound' && tail.every(stateNode => isDescendant(stateNode, ancestor))) {
|
|
2578
|
+
return ancestor;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
return;
|
|
2582
|
+
}
|
|
2568
2583
|
|
|
2569
2584
|
// A history target that restores the source itself must exit and reenter
|
|
2570
2585
|
// the source (SCXML domain = the source's ancestor), unlike a plain
|
|
@@ -2617,12 +2632,28 @@ function computeExitSet(transitions, stateNodeSet, snapshot, resolveTransition)
|
|
|
2617
2632
|
return [...statesToExit];
|
|
2618
2633
|
}
|
|
2619
2634
|
function initialMicrostep(root, preInitialState, actorScope, initEvent, internalQueue) {
|
|
2635
|
+
const initialStateNodes = [...getInitialStateNodes(root)];
|
|
2636
|
+
const statesForDefaultEntry = new Set();
|
|
2637
|
+
const collectDefaultEntryStates = stateNode => {
|
|
2638
|
+
if (stateNode.type === 'compound') {
|
|
2639
|
+
statesForDefaultEntry.add(stateNode);
|
|
2640
|
+
for (const target of stateNode.initial.target ?? []) {
|
|
2641
|
+
collectDefaultEntryStates(target);
|
|
2642
|
+
}
|
|
2643
|
+
} else if (stateNode.type === 'parallel') {
|
|
2644
|
+
for (const child of getChildren(stateNode)) {
|
|
2645
|
+
collectDefaultEntryStates(child);
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
};
|
|
2649
|
+
collectDefaultEntryStates(root);
|
|
2620
2650
|
return microstep([{
|
|
2621
|
-
target:
|
|
2651
|
+
target: initialStateNodes.filter(stateNode => !initialStateNodes.some(other => other !== stateNode && isDescendant(other, stateNode))),
|
|
2622
2652
|
source: root,
|
|
2623
2653
|
reenter: true,
|
|
2624
2654
|
eventType: null,
|
|
2625
|
-
toJSON: null
|
|
2655
|
+
toJSON: null,
|
|
2656
|
+
_statesForDefaultEntry: [...statesForDefaultEntry]
|
|
2626
2657
|
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
2627
2658
|
}
|
|
2628
2659
|
|
|
@@ -2801,6 +2832,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2801
2832
|
// in other words, those are states for which initial actions should be executed
|
|
2802
2833
|
// when we target `#deep_child` initial actions of its ancestors shouldn't be executed
|
|
2803
2834
|
const statesForDefaultEntry = new Set();
|
|
2835
|
+
const historyDefaultsByParent = new Map();
|
|
2804
2836
|
const addAncestorStatesToEnter = (ancestors, reentrancyDomain) => {
|
|
2805
2837
|
for (const anc of ancestors) {
|
|
2806
2838
|
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
@@ -2829,6 +2861,11 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2829
2861
|
}
|
|
2830
2862
|
} else {
|
|
2831
2863
|
const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
|
|
2864
|
+
const historyParent = stateNode.parent;
|
|
2865
|
+
statesForDefaultEntry.add(historyParent);
|
|
2866
|
+
const defaults = historyDefaultsByParent.get(historyParent) ?? [];
|
|
2867
|
+
defaults.push(historyDefaultTransition);
|
|
2868
|
+
historyDefaultsByParent.set(historyParent, defaults);
|
|
2832
2869
|
const {
|
|
2833
2870
|
targets
|
|
2834
2871
|
} = getCurrentTransitionResult(historyDefaultTransition);
|
|
@@ -2846,13 +2883,19 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2846
2883
|
return;
|
|
2847
2884
|
}
|
|
2848
2885
|
if (stateNode.type === 'compound') {
|
|
2849
|
-
const
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2886
|
+
const initialStates = getCurrentTransitionResult(stateNode.initial).targets ?? [];
|
|
2887
|
+
for (const initialState of initialStates) {
|
|
2888
|
+
if (!isHistoryNode(initialState)) {
|
|
2889
|
+
statesToEnter.add(initialState);
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
statesForDefaultEntry.add(stateNode);
|
|
2893
|
+
for (const initialState of initialStates) {
|
|
2894
|
+
addDescendantStatesToEnter(initialState);
|
|
2895
|
+
}
|
|
2896
|
+
for (const initialState of initialStates) {
|
|
2897
|
+
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2853
2898
|
}
|
|
2854
|
-
addDescendantStatesToEnter(initialState);
|
|
2855
|
-
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2856
2899
|
return;
|
|
2857
2900
|
}
|
|
2858
2901
|
if (stateNode.type === 'parallel') {
|
|
@@ -2894,7 +2937,9 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2894
2937
|
}
|
|
2895
2938
|
}
|
|
2896
2939
|
if (isInitial) {
|
|
2897
|
-
|
|
2940
|
+
for (const stateNode of filteredTransitions[0]._statesForDefaultEntry ?? [currentSnapshot.machine.root]) {
|
|
2941
|
+
statesForDefaultEntry.add(stateNode);
|
|
2942
|
+
}
|
|
2898
2943
|
}
|
|
2899
2944
|
const stateInputMap = {
|
|
2900
2945
|
...currentSnapshot._stateInputs
|
|
@@ -2979,17 +3024,28 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2979
3024
|
nextState.context = context;
|
|
2980
3025
|
}
|
|
2981
3026
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
2982
|
-
const
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
3027
|
+
const defaultTransitions = [stateNodeToEnter.initial, ...(historyDefaultsByParent.get(stateNodeToEnter) ?? [])].filter(Boolean);
|
|
3028
|
+
for (const defaultTransition of defaultTransitions) {
|
|
3029
|
+
const {
|
|
3030
|
+
actions: initialActions,
|
|
3031
|
+
context: initialContext,
|
|
3032
|
+
input: initialInput,
|
|
3033
|
+
internalEvents: initialInternalEvents
|
|
3034
|
+
} = getTransitionResult(defaultTransition, nextState, event, actorScope);
|
|
3035
|
+
if (initialActions) {
|
|
3036
|
+
actions.push(...initialActions);
|
|
3037
|
+
}
|
|
3038
|
+
if (initialInternalEvents?.length) {
|
|
3039
|
+
internalQueue.push(...initialInternalEvents);
|
|
3040
|
+
}
|
|
3041
|
+
if (initialContext !== undefined) {
|
|
3042
|
+
nextState.context = mergeContextPatch(nextState.context, initialContext);
|
|
3043
|
+
}
|
|
3044
|
+
if (initialInput && defaultTransition.target) {
|
|
3045
|
+
for (const targetNode of defaultTransition.target) {
|
|
3046
|
+
stateInputMap[targetNode.id] = initialInput;
|
|
3047
|
+
stateInputsChanged = true;
|
|
3048
|
+
}
|
|
2993
3049
|
}
|
|
2994
3050
|
}
|
|
2995
3051
|
}
|