xstate 6.0.0-alpha.46 → 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-9509c0bd.esm.js → StateMachine-8329769a.esm.js} +15 -8
- package/dist/{StateMachine-a5ede014.development.esm.js → StateMachine-88b3c26a.development.esm.js} +15 -8
- package/dist/{StateMachine-756e1335.cjs.js → StateMachine-b09d2b00.cjs.js} +20 -13
- package/dist/{StateMachine-fa133051.development.cjs.js → StateMachine-b3a890bf.development.cjs.js} +20 -13
- package/dist/{createActor-9523f716.esm.js → createActor-27287c65.esm.js} +84 -25
- package/dist/{createActor-f5277b31.development.esm.js → createActor-309d77eb.development.esm.js} +84 -25
- package/dist/{createActor-0816a84b.cjs.js → createActor-9b41ade9.cjs.js} +84 -25
- package/dist/{createActor-f6e6146f.development.cjs.js → createActor-cc3d6dde.development.cjs.js} +84 -25
- package/dist/declarations/src/StateMachine.d.ts +7 -3
- package/dist/declarations/src/createMachineFromConfig.d.ts +5 -77
- package/dist/declarations/src/durable/index.d.ts +9 -2
- 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/setup.d.ts +36 -7
- package/dist/declarations/src/types.d.ts +5 -4
- package/dist/declarations/src/types.v6.d.ts +27 -5
- package/dist/{effectDescriptor-9a14147f.development.esm.js → effectDescriptor-7707794b.development.esm.js} +4 -1
- package/dist/{effectDescriptor-8a5d62e0.development.cjs.js → effectDescriptor-a1678d06.development.cjs.js} +4 -1
- package/dist/{effectDescriptor-87826c41.esm.js → effectDescriptor-b1f5deb6.esm.js} +4 -1
- package/dist/{effectDescriptor-3a016bbe.cjs.js → effectDescriptor-bd36a33e.cjs.js} +4 -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-actors.umd.min.js.map +1 -1
- package/dist/xstate-durable.cjs.js +9 -6
- package/dist/xstate-durable.development.cjs.js +9 -6
- package/dist/xstate-durable.development.esm.js +9 -6
- package/dist/xstate-durable.esm.js +9 -6
- package/dist/xstate-durable.umd.min.js +1 -1
- package/dist/xstate-durable.umd.min.js.map +1 -1
- 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 +160 -1036
- package/dist/xstate.development.cjs.js +160 -1036
- package/dist/xstate.development.esm.js +160 -1035
- package/dist/xstate.esm.js +160 -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-1e1e1cba.development.cjs.js +0 -946
- package/dist/index-3907b7aa.development.esm.js +0 -937
- package/dist/index-7b9c4f77.cjs.js +0 -946
- package/dist/index-c7431a16.esm.js +0 -937
package/dist/{createActor-f5277b31.development.esm.js → createActor-309d77eb.development.esm.js}
RENAMED
|
@@ -906,12 +906,15 @@ function createTransitionEnqueue(actorScope, actions, internalEvents, actorSubsc
|
|
|
906
906
|
},
|
|
907
907
|
stop: actor => {
|
|
908
908
|
if (actor) {
|
|
909
|
-
|
|
909
|
+
// enq.stop accepts the consumer ActorRef contract; refs handed to
|
|
910
|
+
// machine code are always full actor instances at runtime.
|
|
911
|
+
const actorInstance = actor;
|
|
912
|
+
const action = pushBuiltInAction(actions, builtInActions['@xstate.stop'], actorScope, actorInstance);
|
|
910
913
|
action.childUpdate = {
|
|
911
914
|
type: 'remove',
|
|
912
|
-
actor
|
|
915
|
+
actor: actorInstance
|
|
913
916
|
};
|
|
914
|
-
recordStoppedChild(actorScope,
|
|
917
|
+
recordStoppedChild(actorScope, actorInstance);
|
|
915
918
|
}
|
|
916
919
|
}
|
|
917
920
|
};
|
|
@@ -2295,7 +2298,8 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
2295
2298
|
target,
|
|
2296
2299
|
source: stateNode,
|
|
2297
2300
|
reenter: false,
|
|
2298
|
-
eventType: ''
|
|
2301
|
+
eventType: '',
|
|
2302
|
+
to: stateNode.config._historyDefaultTransition
|
|
2299
2303
|
};
|
|
2300
2304
|
}
|
|
2301
2305
|
function isHistoryNode(stateNode) {
|
|
@@ -2309,7 +2313,9 @@ function getInitialStateNodes(stateNode) {
|
|
|
2309
2313
|
}
|
|
2310
2314
|
set.add(descStateNode);
|
|
2311
2315
|
if (descStateNode.type === 'compound') {
|
|
2312
|
-
|
|
2316
|
+
for (const target of descStateNode.initial.target ?? []) {
|
|
2317
|
+
iter(target);
|
|
2318
|
+
}
|
|
2313
2319
|
} else if (descStateNode.type === 'parallel') {
|
|
2314
2320
|
for (const child of getChildren(descStateNode)) {
|
|
2315
2321
|
iter(child);
|
|
@@ -2562,6 +2568,18 @@ function getTransitionDomain(transition, snapshot, resolveTransition) {
|
|
|
2562
2568
|
targets,
|
|
2563
2569
|
reenter
|
|
2564
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
|
+
}
|
|
2565
2583
|
|
|
2566
2584
|
// A history target that restores the source itself must exit and reenter
|
|
2567
2585
|
// the source (SCXML domain = the source's ancestor), unlike a plain
|
|
@@ -2614,12 +2632,28 @@ function computeExitSet(transitions, stateNodeSet, snapshot, resolveTransition)
|
|
|
2614
2632
|
return [...statesToExit];
|
|
2615
2633
|
}
|
|
2616
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);
|
|
2617
2650
|
return microstep([{
|
|
2618
|
-
target:
|
|
2651
|
+
target: initialStateNodes.filter(stateNode => !initialStateNodes.some(other => other !== stateNode && isDescendant(other, stateNode))),
|
|
2619
2652
|
source: root,
|
|
2620
2653
|
reenter: true,
|
|
2621
2654
|
eventType: null,
|
|
2622
|
-
toJSON: null
|
|
2655
|
+
toJSON: null,
|
|
2656
|
+
_statesForDefaultEntry: [...statesForDefaultEntry]
|
|
2623
2657
|
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
2624
2658
|
}
|
|
2625
2659
|
|
|
@@ -2798,6 +2832,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2798
2832
|
// in other words, those are states for which initial actions should be executed
|
|
2799
2833
|
// when we target `#deep_child` initial actions of its ancestors shouldn't be executed
|
|
2800
2834
|
const statesForDefaultEntry = new Set();
|
|
2835
|
+
const historyDefaultsByParent = new Map();
|
|
2801
2836
|
const addAncestorStatesToEnter = (ancestors, reentrancyDomain) => {
|
|
2802
2837
|
for (const anc of ancestors) {
|
|
2803
2838
|
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
@@ -2826,6 +2861,11 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2826
2861
|
}
|
|
2827
2862
|
} else {
|
|
2828
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);
|
|
2829
2869
|
const {
|
|
2830
2870
|
targets
|
|
2831
2871
|
} = getCurrentTransitionResult(historyDefaultTransition);
|
|
@@ -2843,13 +2883,19 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2843
2883
|
return;
|
|
2844
2884
|
}
|
|
2845
2885
|
if (stateNode.type === 'compound') {
|
|
2846
|
-
const
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
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);
|
|
2850
2898
|
}
|
|
2851
|
-
addDescendantStatesToEnter(initialState);
|
|
2852
|
-
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2853
2899
|
return;
|
|
2854
2900
|
}
|
|
2855
2901
|
if (stateNode.type === 'parallel') {
|
|
@@ -2891,7 +2937,9 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2891
2937
|
}
|
|
2892
2938
|
}
|
|
2893
2939
|
if (isInitial) {
|
|
2894
|
-
|
|
2940
|
+
for (const stateNode of filteredTransitions[0]._statesForDefaultEntry ?? [currentSnapshot.machine.root]) {
|
|
2941
|
+
statesForDefaultEntry.add(stateNode);
|
|
2942
|
+
}
|
|
2895
2943
|
}
|
|
2896
2944
|
const stateInputMap = {
|
|
2897
2945
|
...currentSnapshot._stateInputs
|
|
@@ -2976,17 +3024,28 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2976
3024
|
nextState.context = context;
|
|
2977
3025
|
}
|
|
2978
3026
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
2979
|
-
const
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
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
|
+
}
|
|
2990
3049
|
}
|
|
2991
3050
|
}
|
|
2992
3051
|
}
|
|
@@ -900,12 +900,15 @@ function createTransitionEnqueue(actorScope, actions, internalEvents, actorSubsc
|
|
|
900
900
|
},
|
|
901
901
|
stop: actor => {
|
|
902
902
|
if (actor) {
|
|
903
|
-
|
|
903
|
+
// enq.stop accepts the consumer ActorRef contract; refs handed to
|
|
904
|
+
// machine code are always full actor instances at runtime.
|
|
905
|
+
const actorInstance = actor;
|
|
906
|
+
const action = pushBuiltInAction(actions, builtInActions['@xstate.stop'], actorScope, actorInstance);
|
|
904
907
|
action.childUpdate = {
|
|
905
908
|
type: 'remove',
|
|
906
|
-
actor
|
|
909
|
+
actor: actorInstance
|
|
907
910
|
};
|
|
908
|
-
recordStoppedChild(actorScope,
|
|
911
|
+
recordStoppedChild(actorScope, actorInstance);
|
|
909
912
|
}
|
|
910
913
|
}
|
|
911
914
|
};
|
|
@@ -2279,7 +2282,8 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
2279
2282
|
target,
|
|
2280
2283
|
source: stateNode,
|
|
2281
2284
|
reenter: false,
|
|
2282
|
-
eventType: ''
|
|
2285
|
+
eventType: '',
|
|
2286
|
+
to: stateNode.config._historyDefaultTransition
|
|
2283
2287
|
};
|
|
2284
2288
|
}
|
|
2285
2289
|
function isHistoryNode(stateNode) {
|
|
@@ -2293,7 +2297,9 @@ function getInitialStateNodes(stateNode) {
|
|
|
2293
2297
|
}
|
|
2294
2298
|
set.add(descStateNode);
|
|
2295
2299
|
if (descStateNode.type === 'compound') {
|
|
2296
|
-
|
|
2300
|
+
for (const target of descStateNode.initial.target ?? []) {
|
|
2301
|
+
iter(target);
|
|
2302
|
+
}
|
|
2297
2303
|
} else if (descStateNode.type === 'parallel') {
|
|
2298
2304
|
for (const child of getChildren(descStateNode)) {
|
|
2299
2305
|
iter(child);
|
|
@@ -2546,6 +2552,18 @@ function getTransitionDomain(transition, snapshot, resolveTransition) {
|
|
|
2546
2552
|
targets,
|
|
2547
2553
|
reenter
|
|
2548
2554
|
} = resolveTransition(transition);
|
|
2555
|
+
if (transition._transitionDomain) {
|
|
2556
|
+
if (transition._transitionDomain === 'internal' && transition.source.type === 'compound' && targetStates.every(target => isDescendant(target, transition.source))) {
|
|
2557
|
+
return transition.source;
|
|
2558
|
+
}
|
|
2559
|
+
const [head, ...tail] = targetStates.concat(transition.source);
|
|
2560
|
+
for (const ancestor of getProperAncestors(head, undefined)) {
|
|
2561
|
+
if (ancestor.type === 'compound' && tail.every(stateNode => isDescendant(stateNode, ancestor))) {
|
|
2562
|
+
return ancestor;
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
return;
|
|
2566
|
+
}
|
|
2549
2567
|
|
|
2550
2568
|
// A history target that restores the source itself must exit and reenter
|
|
2551
2569
|
// the source (SCXML domain = the source's ancestor), unlike a plain
|
|
@@ -2598,12 +2616,28 @@ function computeExitSet(transitions, stateNodeSet, snapshot, resolveTransition)
|
|
|
2598
2616
|
return [...statesToExit];
|
|
2599
2617
|
}
|
|
2600
2618
|
function initialMicrostep(root, preInitialState, actorScope, initEvent, internalQueue) {
|
|
2619
|
+
const initialStateNodes = [...getInitialStateNodes(root)];
|
|
2620
|
+
const statesForDefaultEntry = new Set();
|
|
2621
|
+
const collectDefaultEntryStates = stateNode => {
|
|
2622
|
+
if (stateNode.type === 'compound') {
|
|
2623
|
+
statesForDefaultEntry.add(stateNode);
|
|
2624
|
+
for (const target of stateNode.initial.target ?? []) {
|
|
2625
|
+
collectDefaultEntryStates(target);
|
|
2626
|
+
}
|
|
2627
|
+
} else if (stateNode.type === 'parallel') {
|
|
2628
|
+
for (const child of getChildren(stateNode)) {
|
|
2629
|
+
collectDefaultEntryStates(child);
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
};
|
|
2633
|
+
collectDefaultEntryStates(root);
|
|
2601
2634
|
return microstep([{
|
|
2602
|
-
target:
|
|
2635
|
+
target: initialStateNodes.filter(stateNode => !initialStateNodes.some(other => other !== stateNode && isDescendant(other, stateNode))),
|
|
2603
2636
|
source: root,
|
|
2604
2637
|
reenter: true,
|
|
2605
2638
|
eventType: null,
|
|
2606
|
-
toJSON: null
|
|
2639
|
+
toJSON: null,
|
|
2640
|
+
_statesForDefaultEntry: [...statesForDefaultEntry]
|
|
2607
2641
|
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
2608
2642
|
}
|
|
2609
2643
|
|
|
@@ -2782,6 +2816,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2782
2816
|
// in other words, those are states for which initial actions should be executed
|
|
2783
2817
|
// when we target `#deep_child` initial actions of its ancestors shouldn't be executed
|
|
2784
2818
|
const statesForDefaultEntry = new Set();
|
|
2819
|
+
const historyDefaultsByParent = new Map();
|
|
2785
2820
|
const addAncestorStatesToEnter = (ancestors, reentrancyDomain) => {
|
|
2786
2821
|
for (const anc of ancestors) {
|
|
2787
2822
|
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
@@ -2810,6 +2845,11 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2810
2845
|
}
|
|
2811
2846
|
} else {
|
|
2812
2847
|
const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
|
|
2848
|
+
const historyParent = stateNode.parent;
|
|
2849
|
+
statesForDefaultEntry.add(historyParent);
|
|
2850
|
+
const defaults = historyDefaultsByParent.get(historyParent) ?? [];
|
|
2851
|
+
defaults.push(historyDefaultTransition);
|
|
2852
|
+
historyDefaultsByParent.set(historyParent, defaults);
|
|
2813
2853
|
const {
|
|
2814
2854
|
targets
|
|
2815
2855
|
} = getCurrentTransitionResult(historyDefaultTransition);
|
|
@@ -2827,13 +2867,19 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2827
2867
|
return;
|
|
2828
2868
|
}
|
|
2829
2869
|
if (stateNode.type === 'compound') {
|
|
2830
|
-
const
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2870
|
+
const initialStates = getCurrentTransitionResult(stateNode.initial).targets ?? [];
|
|
2871
|
+
for (const initialState of initialStates) {
|
|
2872
|
+
if (!isHistoryNode(initialState)) {
|
|
2873
|
+
statesToEnter.add(initialState);
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
statesForDefaultEntry.add(stateNode);
|
|
2877
|
+
for (const initialState of initialStates) {
|
|
2878
|
+
addDescendantStatesToEnter(initialState);
|
|
2879
|
+
}
|
|
2880
|
+
for (const initialState of initialStates) {
|
|
2881
|
+
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2834
2882
|
}
|
|
2835
|
-
addDescendantStatesToEnter(initialState);
|
|
2836
|
-
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2837
2883
|
return;
|
|
2838
2884
|
}
|
|
2839
2885
|
if (stateNode.type === 'parallel') {
|
|
@@ -2875,7 +2921,9 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2875
2921
|
}
|
|
2876
2922
|
}
|
|
2877
2923
|
if (isInitial) {
|
|
2878
|
-
|
|
2924
|
+
for (const stateNode of filteredTransitions[0]._statesForDefaultEntry ?? [currentSnapshot.machine.root]) {
|
|
2925
|
+
statesForDefaultEntry.add(stateNode);
|
|
2926
|
+
}
|
|
2879
2927
|
}
|
|
2880
2928
|
const stateInputMap = {
|
|
2881
2929
|
...currentSnapshot._stateInputs
|
|
@@ -2960,17 +3008,28 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2960
3008
|
nextState.context = context;
|
|
2961
3009
|
}
|
|
2962
3010
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
2963
|
-
const
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
3011
|
+
const defaultTransitions = [stateNodeToEnter.initial, ...(historyDefaultsByParent.get(stateNodeToEnter) ?? [])].filter(Boolean);
|
|
3012
|
+
for (const defaultTransition of defaultTransitions) {
|
|
3013
|
+
const {
|
|
3014
|
+
actions: initialActions,
|
|
3015
|
+
context: initialContext,
|
|
3016
|
+
input: initialInput,
|
|
3017
|
+
internalEvents: initialInternalEvents
|
|
3018
|
+
} = getTransitionResult(defaultTransition, nextState, event, actorScope);
|
|
3019
|
+
if (initialActions) {
|
|
3020
|
+
actions.push(...initialActions);
|
|
3021
|
+
}
|
|
3022
|
+
if (initialInternalEvents?.length) {
|
|
3023
|
+
internalQueue.push(...initialInternalEvents);
|
|
3024
|
+
}
|
|
3025
|
+
if (initialContext !== undefined) {
|
|
3026
|
+
nextState.context = mergeContextPatch(nextState.context, initialContext);
|
|
3027
|
+
}
|
|
3028
|
+
if (initialInput && defaultTransition.target) {
|
|
3029
|
+
for (const targetNode of defaultTransition.target) {
|
|
3030
|
+
stateInputMap[targetNode.id] = initialInput;
|
|
3031
|
+
stateInputsChanged = true;
|
|
3032
|
+
}
|
|
2974
3033
|
}
|
|
2975
3034
|
}
|
|
2976
3035
|
}
|
package/dist/{createActor-f6e6146f.development.cjs.js → createActor-cc3d6dde.development.cjs.js}
RENAMED
|
@@ -908,12 +908,15 @@ function createTransitionEnqueue(actorScope, actions, internalEvents, actorSubsc
|
|
|
908
908
|
},
|
|
909
909
|
stop: actor => {
|
|
910
910
|
if (actor) {
|
|
911
|
-
|
|
911
|
+
// enq.stop accepts the consumer ActorRef contract; refs handed to
|
|
912
|
+
// machine code are always full actor instances at runtime.
|
|
913
|
+
const actorInstance = actor;
|
|
914
|
+
const action = pushBuiltInAction(actions, builtInActions['@xstate.stop'], actorScope, actorInstance);
|
|
912
915
|
action.childUpdate = {
|
|
913
916
|
type: 'remove',
|
|
914
|
-
actor
|
|
917
|
+
actor: actorInstance
|
|
915
918
|
};
|
|
916
|
-
recordStoppedChild(actorScope,
|
|
919
|
+
recordStoppedChild(actorScope, actorInstance);
|
|
917
920
|
}
|
|
918
921
|
}
|
|
919
922
|
};
|
|
@@ -2297,7 +2300,8 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
2297
2300
|
target,
|
|
2298
2301
|
source: stateNode,
|
|
2299
2302
|
reenter: false,
|
|
2300
|
-
eventType: ''
|
|
2303
|
+
eventType: '',
|
|
2304
|
+
to: stateNode.config._historyDefaultTransition
|
|
2301
2305
|
};
|
|
2302
2306
|
}
|
|
2303
2307
|
function isHistoryNode(stateNode) {
|
|
@@ -2311,7 +2315,9 @@ function getInitialStateNodes(stateNode) {
|
|
|
2311
2315
|
}
|
|
2312
2316
|
set.add(descStateNode);
|
|
2313
2317
|
if (descStateNode.type === 'compound') {
|
|
2314
|
-
|
|
2318
|
+
for (const target of descStateNode.initial.target ?? []) {
|
|
2319
|
+
iter(target);
|
|
2320
|
+
}
|
|
2315
2321
|
} else if (descStateNode.type === 'parallel') {
|
|
2316
2322
|
for (const child of getChildren(descStateNode)) {
|
|
2317
2323
|
iter(child);
|
|
@@ -2564,6 +2570,18 @@ function getTransitionDomain(transition, snapshot, resolveTransition) {
|
|
|
2564
2570
|
targets,
|
|
2565
2571
|
reenter
|
|
2566
2572
|
} = resolveTransition(transition);
|
|
2573
|
+
if (transition._transitionDomain) {
|
|
2574
|
+
if (transition._transitionDomain === 'internal' && transition.source.type === 'compound' && targetStates.every(target => isDescendant(target, transition.source))) {
|
|
2575
|
+
return transition.source;
|
|
2576
|
+
}
|
|
2577
|
+
const [head, ...tail] = targetStates.concat(transition.source);
|
|
2578
|
+
for (const ancestor of getProperAncestors(head, undefined)) {
|
|
2579
|
+
if (ancestor.type === 'compound' && tail.every(stateNode => isDescendant(stateNode, ancestor))) {
|
|
2580
|
+
return ancestor;
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2567
2585
|
|
|
2568
2586
|
// A history target that restores the source itself must exit and reenter
|
|
2569
2587
|
// the source (SCXML domain = the source's ancestor), unlike a plain
|
|
@@ -2616,12 +2634,28 @@ function computeExitSet(transitions, stateNodeSet, snapshot, resolveTransition)
|
|
|
2616
2634
|
return [...statesToExit];
|
|
2617
2635
|
}
|
|
2618
2636
|
function initialMicrostep(root, preInitialState, actorScope, initEvent, internalQueue) {
|
|
2637
|
+
const initialStateNodes = [...getInitialStateNodes(root)];
|
|
2638
|
+
const statesForDefaultEntry = new Set();
|
|
2639
|
+
const collectDefaultEntryStates = stateNode => {
|
|
2640
|
+
if (stateNode.type === 'compound') {
|
|
2641
|
+
statesForDefaultEntry.add(stateNode);
|
|
2642
|
+
for (const target of stateNode.initial.target ?? []) {
|
|
2643
|
+
collectDefaultEntryStates(target);
|
|
2644
|
+
}
|
|
2645
|
+
} else if (stateNode.type === 'parallel') {
|
|
2646
|
+
for (const child of getChildren(stateNode)) {
|
|
2647
|
+
collectDefaultEntryStates(child);
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
2651
|
+
collectDefaultEntryStates(root);
|
|
2619
2652
|
return microstep([{
|
|
2620
|
-
target:
|
|
2653
|
+
target: initialStateNodes.filter(stateNode => !initialStateNodes.some(other => other !== stateNode && isDescendant(other, stateNode))),
|
|
2621
2654
|
source: root,
|
|
2622
2655
|
reenter: true,
|
|
2623
2656
|
eventType: null,
|
|
2624
|
-
toJSON: null
|
|
2657
|
+
toJSON: null,
|
|
2658
|
+
_statesForDefaultEntry: [...statesForDefaultEntry]
|
|
2625
2659
|
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
2626
2660
|
}
|
|
2627
2661
|
|
|
@@ -2800,6 +2834,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2800
2834
|
// in other words, those are states for which initial actions should be executed
|
|
2801
2835
|
// when we target `#deep_child` initial actions of its ancestors shouldn't be executed
|
|
2802
2836
|
const statesForDefaultEntry = new Set();
|
|
2837
|
+
const historyDefaultsByParent = new Map();
|
|
2803
2838
|
const addAncestorStatesToEnter = (ancestors, reentrancyDomain) => {
|
|
2804
2839
|
for (const anc of ancestors) {
|
|
2805
2840
|
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
@@ -2828,6 +2863,11 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2828
2863
|
}
|
|
2829
2864
|
} else {
|
|
2830
2865
|
const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
|
|
2866
|
+
const historyParent = stateNode.parent;
|
|
2867
|
+
statesForDefaultEntry.add(historyParent);
|
|
2868
|
+
const defaults = historyDefaultsByParent.get(historyParent) ?? [];
|
|
2869
|
+
defaults.push(historyDefaultTransition);
|
|
2870
|
+
historyDefaultsByParent.set(historyParent, defaults);
|
|
2831
2871
|
const {
|
|
2832
2872
|
targets
|
|
2833
2873
|
} = getCurrentTransitionResult(historyDefaultTransition);
|
|
@@ -2845,13 +2885,19 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2845
2885
|
return;
|
|
2846
2886
|
}
|
|
2847
2887
|
if (stateNode.type === 'compound') {
|
|
2848
|
-
const
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2888
|
+
const initialStates = getCurrentTransitionResult(stateNode.initial).targets ?? [];
|
|
2889
|
+
for (const initialState of initialStates) {
|
|
2890
|
+
if (!isHistoryNode(initialState)) {
|
|
2891
|
+
statesToEnter.add(initialState);
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
statesForDefaultEntry.add(stateNode);
|
|
2895
|
+
for (const initialState of initialStates) {
|
|
2896
|
+
addDescendantStatesToEnter(initialState);
|
|
2897
|
+
}
|
|
2898
|
+
for (const initialState of initialStates) {
|
|
2899
|
+
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2852
2900
|
}
|
|
2853
|
-
addDescendantStatesToEnter(initialState);
|
|
2854
|
-
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2855
2901
|
return;
|
|
2856
2902
|
}
|
|
2857
2903
|
if (stateNode.type === 'parallel') {
|
|
@@ -2893,7 +2939,9 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2893
2939
|
}
|
|
2894
2940
|
}
|
|
2895
2941
|
if (isInitial) {
|
|
2896
|
-
|
|
2942
|
+
for (const stateNode of filteredTransitions[0]._statesForDefaultEntry ?? [currentSnapshot.machine.root]) {
|
|
2943
|
+
statesForDefaultEntry.add(stateNode);
|
|
2944
|
+
}
|
|
2897
2945
|
}
|
|
2898
2946
|
const stateInputMap = {
|
|
2899
2947
|
...currentSnapshot._stateInputs
|
|
@@ -2978,17 +3026,28 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2978
3026
|
nextState.context = context;
|
|
2979
3027
|
}
|
|
2980
3028
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
2981
|
-
const
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
3029
|
+
const defaultTransitions = [stateNodeToEnter.initial, ...(historyDefaultsByParent.get(stateNodeToEnter) ?? [])].filter(Boolean);
|
|
3030
|
+
for (const defaultTransition of defaultTransitions) {
|
|
3031
|
+
const {
|
|
3032
|
+
actions: initialActions,
|
|
3033
|
+
context: initialContext,
|
|
3034
|
+
input: initialInput,
|
|
3035
|
+
internalEvents: initialInternalEvents
|
|
3036
|
+
} = getTransitionResult(defaultTransition, nextState, event, actorScope);
|
|
3037
|
+
if (initialActions) {
|
|
3038
|
+
actions.push(...initialActions);
|
|
3039
|
+
}
|
|
3040
|
+
if (initialInternalEvents?.length) {
|
|
3041
|
+
internalQueue.push(...initialInternalEvents);
|
|
3042
|
+
}
|
|
3043
|
+
if (initialContext !== undefined) {
|
|
3044
|
+
nextState.context = mergeContextPatch(nextState.context, initialContext);
|
|
3045
|
+
}
|
|
3046
|
+
if (initialInput && defaultTransition.target) {
|
|
3047
|
+
for (const targetNode of defaultTransition.target) {
|
|
3048
|
+
stateInputMap[targetNode.id] = initialInput;
|
|
3049
|
+
stateInputsChanged = true;
|
|
3050
|
+
}
|
|
2992
3051
|
}
|
|
2993
3052
|
}
|
|
2994
3053
|
}
|
|
@@ -3,7 +3,7 @@ import { StateNode } from "./StateNode.js";
|
|
|
3
3
|
import { type TransitionSelectionResults } from "./stateUtils.js";
|
|
4
4
|
import { AnyActorSystem } from "./system.js";
|
|
5
5
|
import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActorLogic, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EmittedFrom, EventObject, EventFromLogic, ExecutableActionObjectFromLogic, HistoryValue, InputFrom, IsAny, MachineContext, MetaObject, OutputFrom, Snapshot, SnapshotFrom, StateValue, StateSchema, SnapshotStatus } from "./types.js";
|
|
6
|
-
import { AnyMachineSchemas, Sources, Next_MachineConfig, MachineOptions } from "./types.v6.js";
|
|
6
|
+
import { AnyMachineSchemas, DelaySourceMap, GuardSourceMap, Sources, Next_MachineConfig, MachineOptions } from "./types.v6.js";
|
|
7
7
|
import type { ActorLogicValidator } from "./validation.types.js";
|
|
8
8
|
import type { StandardSchemaV1 } from "./schema.types.js";
|
|
9
9
|
import type { PersistedMachineSnapshot } from "./machineVersion.types.js";
|
|
@@ -53,8 +53,12 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
53
53
|
provide<const TProvidedActorMap extends Partial<Record<keyof TActorMap & string, AnyActorLogic>> = {}>(sources: {
|
|
54
54
|
actions?: Partial<TActionMap>;
|
|
55
55
|
actors?: TProvidedActorMap & ProvidedActors<TActorMap, TProvidedActorMap>;
|
|
56
|
-
guards?: Partial<TGuardMap
|
|
57
|
-
|
|
56
|
+
guards?: Partial<TGuardMap> & {
|
|
57
|
+
[K in keyof TGuardMap]?: GuardSourceMap<TContext, TEvent>[string];
|
|
58
|
+
};
|
|
59
|
+
delays?: {
|
|
60
|
+
[K in keyof TDelayMap]?: DelaySourceMap<TContext, TEvent>[string];
|
|
61
|
+
};
|
|
58
62
|
}): this;
|
|
59
63
|
resolveState(config: {
|
|
60
64
|
value: StateValue;
|