xstate 6.0.0-alpha.47 → 6.0.0-alpha.49
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 +30 -1
- package/dist/{StateMachine-7046f677.cjs.js → StateMachine-0adb3a70.cjs.js} +15 -12
- package/dist/{StateMachine-70c06bdd.development.cjs.js → StateMachine-29450e6d.development.cjs.js} +15 -12
- package/dist/{StateMachine-74929087.esm.js → StateMachine-2af31c11.esm.js} +10 -7
- package/dist/{StateMachine-ee10f67e.development.esm.js → StateMachine-faf50c5c.development.esm.js} +10 -7
- package/dist/{createActor-915ea40c.esm.js → createActor-268165d4.esm.js} +79 -23
- package/dist/{createActor-ff132afa.development.esm.js → createActor-88709f74.development.esm.js} +79 -23
- package/dist/{createActor-6736cbbe.development.cjs.js → createActor-a1e0dffb.development.cjs.js} +78 -25
- package/dist/{createActor-bfe8b6bd.cjs.js → createActor-b4dd05ae.cjs.js} +78 -25
- package/dist/declarations/src/createMachineFromConfig.d.ts +5 -77
- package/dist/declarations/src/fsm/createFSMActor.d.ts +67 -0
- package/dist/declarations/src/fsm/index.d.ts +2 -0
- package/dist/declarations/src/fsm.d.ts +5 -4
- 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-8be60443.esm.js → effectDescriptor-30c9a744.esm.js} +1 -1
- package/dist/{effectDescriptor-fbe67d5a.development.esm.js → effectDescriptor-39d22100.development.esm.js} +1 -1
- package/dist/{effectDescriptor-3c699328.development.cjs.js → effectDescriptor-7ff6802f.development.cjs.js} +1 -1
- package/dist/{effectDescriptor-a7e2d4d1.cjs.js → effectDescriptor-be348e50.cjs.js} +1 -1
- package/dist/fsm-7a2e9697.cjs.js +777 -0
- package/dist/fsm-b804b3e9.esm.js +775 -0
- package/dist/fsm-c1316948.development.cjs.js +777 -0
- package/dist/fsm-e18a7cb4.development.esm.js +775 -0
- package/dist/types-3c3455f7.esm.js +185 -0
- package/dist/types-adda3842.development.esm.js +185 -0
- package/dist/types-b3fea5bd.development.cjs.js +189 -0
- package/dist/types-fbabaeee.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-fsm.cjs.d.mts +2 -0
- package/dist/xstate-fsm.cjs.d.ts +2 -0
- package/dist/xstate-fsm.cjs.js +409 -0
- package/dist/xstate-fsm.cjs.mjs +5 -0
- package/dist/xstate-fsm.development.cjs.js +409 -0
- package/dist/xstate-fsm.development.cjs.mjs +5 -0
- package/dist/xstate-fsm.development.esm.js +403 -0
- package/dist/xstate-fsm.esm.js +403 -0
- package/dist/xstate-fsm.umd.min.js +2 -0
- package/dist/xstate-fsm.umd.min.js.map +1 -0
- 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 +143 -1412
- package/dist/xstate.development.cjs.js +143 -1412
- package/dist/xstate.development.esm.js +143 -1411
- package/dist/xstate.esm.js +143 -1411
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/fsm/package.json +8 -0
- package/package.json +37 -3
- 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/dist/{createActor-ff132afa.development.esm.js → createActor-88709f74.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
|
}
|
|
@@ -5738,4 +5794,4 @@ function createActor(logic, options) {
|
|
|
5738
5794
|
return new Actor(logic, options);
|
|
5739
5795
|
}
|
|
5740
5796
|
|
|
5741
|
-
export {
|
|
5797
|
+
export { matchesActorSession as $, Actor as A, XSTATE_LOGIC_EFFECT_START as B, XSTATE_LOGIC_EFFECT_RESOLVE as C, XSTATE_LOGIC_EFFECT_REJECT as D, finalizeTransitionResult as E, createEmitEffect as F, createSendToEffect as G, XSTATE_INIT as H, withActorScope as I, XSTATE_TIMER as J, isLazyActorScope as K, resolveRegisteredActorSource as L, allocateChildId as M, assertChildIdFree as N, reserveChildId as O, mapValues as P, createInvokeId as Q, getDelayedTransitions as R, STATE_DELIMITER as S, getEventDescriptorKey as T, getCandidates as U, evaluateCandidate as V, formatTransition as W, XSTATE_STOP as X, NULL_EVENT as Y, toTransitionConfigArray as Z, createInvokeTimeoutEventId as _, createListenerLogic as a, formatRouteTransitions as a0, resolveStateValue as a1, getAllStateNodes as a2, createMachineSnapshot as a3, isInFinalState as a4, createInertActorScope as a5, setInertActorScopeSnapshot as a6, beginSpawnAllocation as a7, attachSnapshotActorRef as a8, macrostep as a9, getAllOwnEvents as aA, matchesEvent as aB, encodeAddressSegment as aC, getRootActorId as aD, RUNTIME_OPERATIONS as aE, withSystemInspector as aF, getSnapshotActorRef as aG, withExecutionIdentity as aH, isInertActorScope as aa, setSnapshotActorRef as ab, cloneMachineSnapshot as ac, transitionNode as ad, getTransitionResult as ae, hasEffect as af, createErrorPlatformEvent as ag, withActorSelf as ah, resolveActionsWithContext as ai, takeSpawnAllocationCounters as aj, mergeActorIdCounters as ak, createSpawnEffect as al, initialMicrostep as am, toStatePath as an, isStateId as ao, getStateNodeByPath as ap, getPersistedSnapshot as aq, createRemoteActorRef as ar, resolveReferencedActor as as, createInvokeTimeoutEvent as at, parseGeneratedActorId as au, ACTOR_REF_TYPE as av, hasAmbientInspector as aw, getProperAncestors as ax, isRemoteActorRef as ay, getActorIdPrefix as az, createSubscriptionLogic as b, createActor as c, getNextSnapshot as d, isMachineSnapshot as e, getStateNodes as f, getInitialSnapshot as g, getAllOwnEventDescriptors as h, isAtomicStateNode as i, matchesState as j, checkStateIn as k, listenerLogic as l, matchesEventDescriptor as m, pathToStateValue as n, toObserver as o, parseDelayToMilliseconds as p, executeEffects as q, isBuiltInExecutableAction as r, subscriptionLogic as s, toArray as t, deliverEvent as u, runStep as v, stopActor as w, terminateActor as x, createInitEvent as y, createCustomEffect as z };
|
package/dist/{createActor-6736cbbe.development.cjs.js → createActor-a1e0dffb.development.cjs.js}
RENAMED
|
@@ -2300,7 +2300,8 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
2300
2300
|
target,
|
|
2301
2301
|
source: stateNode,
|
|
2302
2302
|
reenter: false,
|
|
2303
|
-
eventType: ''
|
|
2303
|
+
eventType: '',
|
|
2304
|
+
to: stateNode.config._historyDefaultTransition
|
|
2304
2305
|
};
|
|
2305
2306
|
}
|
|
2306
2307
|
function isHistoryNode(stateNode) {
|
|
@@ -2314,7 +2315,9 @@ function getInitialStateNodes(stateNode) {
|
|
|
2314
2315
|
}
|
|
2315
2316
|
set.add(descStateNode);
|
|
2316
2317
|
if (descStateNode.type === 'compound') {
|
|
2317
|
-
|
|
2318
|
+
for (const target of descStateNode.initial.target ?? []) {
|
|
2319
|
+
iter(target);
|
|
2320
|
+
}
|
|
2318
2321
|
} else if (descStateNode.type === 'parallel') {
|
|
2319
2322
|
for (const child of getChildren(descStateNode)) {
|
|
2320
2323
|
iter(child);
|
|
@@ -2567,6 +2570,18 @@ function getTransitionDomain(transition, snapshot, resolveTransition) {
|
|
|
2567
2570
|
targets,
|
|
2568
2571
|
reenter
|
|
2569
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
|
+
}
|
|
2570
2585
|
|
|
2571
2586
|
// A history target that restores the source itself must exit and reenter
|
|
2572
2587
|
// the source (SCXML domain = the source's ancestor), unlike a plain
|
|
@@ -2619,12 +2634,28 @@ function computeExitSet(transitions, stateNodeSet, snapshot, resolveTransition)
|
|
|
2619
2634
|
return [...statesToExit];
|
|
2620
2635
|
}
|
|
2621
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);
|
|
2622
2652
|
return microstep([{
|
|
2623
|
-
target:
|
|
2653
|
+
target: initialStateNodes.filter(stateNode => !initialStateNodes.some(other => other !== stateNode && isDescendant(other, stateNode))),
|
|
2624
2654
|
source: root,
|
|
2625
2655
|
reenter: true,
|
|
2626
2656
|
eventType: null,
|
|
2627
|
-
toJSON: null
|
|
2657
|
+
toJSON: null,
|
|
2658
|
+
_statesForDefaultEntry: [...statesForDefaultEntry]
|
|
2628
2659
|
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
2629
2660
|
}
|
|
2630
2661
|
|
|
@@ -2803,6 +2834,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2803
2834
|
// in other words, those are states for which initial actions should be executed
|
|
2804
2835
|
// when we target `#deep_child` initial actions of its ancestors shouldn't be executed
|
|
2805
2836
|
const statesForDefaultEntry = new Set();
|
|
2837
|
+
const historyDefaultsByParent = new Map();
|
|
2806
2838
|
const addAncestorStatesToEnter = (ancestors, reentrancyDomain) => {
|
|
2807
2839
|
for (const anc of ancestors) {
|
|
2808
2840
|
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
@@ -2831,6 +2863,11 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2831
2863
|
}
|
|
2832
2864
|
} else {
|
|
2833
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);
|
|
2834
2871
|
const {
|
|
2835
2872
|
targets
|
|
2836
2873
|
} = getCurrentTransitionResult(historyDefaultTransition);
|
|
@@ -2848,13 +2885,19 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2848
2885
|
return;
|
|
2849
2886
|
}
|
|
2850
2887
|
if (stateNode.type === 'compound') {
|
|
2851
|
-
const
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
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);
|
|
2855
2900
|
}
|
|
2856
|
-
addDescendantStatesToEnter(initialState);
|
|
2857
|
-
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2858
2901
|
return;
|
|
2859
2902
|
}
|
|
2860
2903
|
if (stateNode.type === 'parallel') {
|
|
@@ -2896,7 +2939,9 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2896
2939
|
}
|
|
2897
2940
|
}
|
|
2898
2941
|
if (isInitial) {
|
|
2899
|
-
|
|
2942
|
+
for (const stateNode of filteredTransitions[0]._statesForDefaultEntry ?? [currentSnapshot.machine.root]) {
|
|
2943
|
+
statesForDefaultEntry.add(stateNode);
|
|
2944
|
+
}
|
|
2900
2945
|
}
|
|
2901
2946
|
const stateInputMap = {
|
|
2902
2947
|
...currentSnapshot._stateInputs
|
|
@@ -2981,17 +3026,28 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2981
3026
|
nextState.context = context;
|
|
2982
3027
|
}
|
|
2983
3028
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
2984
|
-
const
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
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
|
+
}
|
|
2995
3051
|
}
|
|
2996
3052
|
}
|
|
2997
3053
|
}
|
|
@@ -5755,7 +5811,6 @@ exports.allocateChildId = allocateChildId;
|
|
|
5755
5811
|
exports.assertChildIdFree = assertChildIdFree;
|
|
5756
5812
|
exports.attachSnapshotActorRef = attachSnapshotActorRef;
|
|
5757
5813
|
exports.beginSpawnAllocation = beginSpawnAllocation;
|
|
5758
|
-
exports.builtInActions = builtInActions;
|
|
5759
5814
|
exports.checkStateIn = checkStateIn;
|
|
5760
5815
|
exports.cloneMachineSnapshot = cloneMachineSnapshot;
|
|
5761
5816
|
exports.createActor = createActor;
|
|
@@ -5773,9 +5828,7 @@ exports.createRemoteActorRef = createRemoteActorRef;
|
|
|
5773
5828
|
exports.createSendToEffect = createSendToEffect;
|
|
5774
5829
|
exports.createSpawnEffect = createSpawnEffect;
|
|
5775
5830
|
exports.createSubscriptionLogic = createSubscriptionLogic;
|
|
5776
|
-
exports.createTransitionEnqueue = createTransitionEnqueue;
|
|
5777
5831
|
exports.deliverEvent = deliverEvent;
|
|
5778
|
-
exports.deriveDeferredStarts = deriveDeferredStarts;
|
|
5779
5832
|
exports.encodeAddressSegment = encodeAddressSegment;
|
|
5780
5833
|
exports.evaluateCandidate = evaluateCandidate;
|
|
5781
5834
|
exports.executeEffects = executeEffects;
|
|
@@ -2282,7 +2282,8 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
2282
2282
|
target,
|
|
2283
2283
|
source: stateNode,
|
|
2284
2284
|
reenter: false,
|
|
2285
|
-
eventType: ''
|
|
2285
|
+
eventType: '',
|
|
2286
|
+
to: stateNode.config._historyDefaultTransition
|
|
2286
2287
|
};
|
|
2287
2288
|
}
|
|
2288
2289
|
function isHistoryNode(stateNode) {
|
|
@@ -2296,7 +2297,9 @@ function getInitialStateNodes(stateNode) {
|
|
|
2296
2297
|
}
|
|
2297
2298
|
set.add(descStateNode);
|
|
2298
2299
|
if (descStateNode.type === 'compound') {
|
|
2299
|
-
|
|
2300
|
+
for (const target of descStateNode.initial.target ?? []) {
|
|
2301
|
+
iter(target);
|
|
2302
|
+
}
|
|
2300
2303
|
} else if (descStateNode.type === 'parallel') {
|
|
2301
2304
|
for (const child of getChildren(descStateNode)) {
|
|
2302
2305
|
iter(child);
|
|
@@ -2549,6 +2552,18 @@ function getTransitionDomain(transition, snapshot, resolveTransition) {
|
|
|
2549
2552
|
targets,
|
|
2550
2553
|
reenter
|
|
2551
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
|
+
}
|
|
2552
2567
|
|
|
2553
2568
|
// A history target that restores the source itself must exit and reenter
|
|
2554
2569
|
// the source (SCXML domain = the source's ancestor), unlike a plain
|
|
@@ -2601,12 +2616,28 @@ function computeExitSet(transitions, stateNodeSet, snapshot, resolveTransition)
|
|
|
2601
2616
|
return [...statesToExit];
|
|
2602
2617
|
}
|
|
2603
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);
|
|
2604
2634
|
return microstep([{
|
|
2605
|
-
target:
|
|
2635
|
+
target: initialStateNodes.filter(stateNode => !initialStateNodes.some(other => other !== stateNode && isDescendant(other, stateNode))),
|
|
2606
2636
|
source: root,
|
|
2607
2637
|
reenter: true,
|
|
2608
2638
|
eventType: null,
|
|
2609
|
-
toJSON: null
|
|
2639
|
+
toJSON: null,
|
|
2640
|
+
_statesForDefaultEntry: [...statesForDefaultEntry]
|
|
2610
2641
|
}], preInitialState, actorScope, initEvent, true, internalQueue);
|
|
2611
2642
|
}
|
|
2612
2643
|
|
|
@@ -2785,6 +2816,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2785
2816
|
// in other words, those are states for which initial actions should be executed
|
|
2786
2817
|
// when we target `#deep_child` initial actions of its ancestors shouldn't be executed
|
|
2787
2818
|
const statesForDefaultEntry = new Set();
|
|
2819
|
+
const historyDefaultsByParent = new Map();
|
|
2788
2820
|
const addAncestorStatesToEnter = (ancestors, reentrancyDomain) => {
|
|
2789
2821
|
for (const anc of ancestors) {
|
|
2790
2822
|
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
@@ -2813,6 +2845,11 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2813
2845
|
}
|
|
2814
2846
|
} else {
|
|
2815
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);
|
|
2816
2853
|
const {
|
|
2817
2854
|
targets
|
|
2818
2855
|
} = getCurrentTransitionResult(historyDefaultTransition);
|
|
@@ -2830,13 +2867,19 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2830
2867
|
return;
|
|
2831
2868
|
}
|
|
2832
2869
|
if (stateNode.type === 'compound') {
|
|
2833
|
-
const
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
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);
|
|
2837
2882
|
}
|
|
2838
|
-
addDescendantStatesToEnter(initialState);
|
|
2839
|
-
addAncestorStatesToEnter(getProperAncestors(initialState, stateNode), undefined);
|
|
2840
2883
|
return;
|
|
2841
2884
|
}
|
|
2842
2885
|
if (stateNode.type === 'parallel') {
|
|
@@ -2878,7 +2921,9 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2878
2921
|
}
|
|
2879
2922
|
}
|
|
2880
2923
|
if (isInitial) {
|
|
2881
|
-
|
|
2924
|
+
for (const stateNode of filteredTransitions[0]._statesForDefaultEntry ?? [currentSnapshot.machine.root]) {
|
|
2925
|
+
statesForDefaultEntry.add(stateNode);
|
|
2926
|
+
}
|
|
2882
2927
|
}
|
|
2883
2928
|
const stateInputMap = {
|
|
2884
2929
|
...currentSnapshot._stateInputs
|
|
@@ -2963,17 +3008,28 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
|
|
|
2963
3008
|
nextState.context = context;
|
|
2964
3009
|
}
|
|
2965
3010
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
2966
|
-
const
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
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
|
+
}
|
|
2977
3033
|
}
|
|
2978
3034
|
}
|
|
2979
3035
|
}
|
|
@@ -5716,7 +5772,6 @@ exports.allocateChildId = allocateChildId;
|
|
|
5716
5772
|
exports.assertChildIdFree = assertChildIdFree;
|
|
5717
5773
|
exports.attachSnapshotActorRef = attachSnapshotActorRef;
|
|
5718
5774
|
exports.beginSpawnAllocation = beginSpawnAllocation;
|
|
5719
|
-
exports.builtInActions = builtInActions;
|
|
5720
5775
|
exports.checkStateIn = checkStateIn;
|
|
5721
5776
|
exports.cloneMachineSnapshot = cloneMachineSnapshot;
|
|
5722
5777
|
exports.createActor = createActor;
|
|
@@ -5734,9 +5789,7 @@ exports.createRemoteActorRef = createRemoteActorRef;
|
|
|
5734
5789
|
exports.createSendToEffect = createSendToEffect;
|
|
5735
5790
|
exports.createSpawnEffect = createSpawnEffect;
|
|
5736
5791
|
exports.createSubscriptionLogic = createSubscriptionLogic;
|
|
5737
|
-
exports.createTransitionEnqueue = createTransitionEnqueue;
|
|
5738
5792
|
exports.deliverEvent = deliverEvent;
|
|
5739
|
-
exports.deriveDeferredStarts = deriveDeferredStarts;
|
|
5740
5793
|
exports.encodeAddressSegment = encodeAddressSegment;
|
|
5741
5794
|
exports.evaluateCandidate = evaluateCandidate;
|
|
5742
5795
|
exports.executeEffects = executeEffects;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { AnyActorLogic, AnyEventObject, AnyStateMachine, EventObject, MachineContext, MetaObject } from "./types.js";
|
|
2
|
-
|
|
2
|
+
interface RaiseJSON {
|
|
3
3
|
type: '@xstate.raise';
|
|
4
4
|
event: EventObject;
|
|
5
5
|
id?: string;
|
|
6
6
|
delay?: number;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
interface CancelJSON {
|
|
9
9
|
type: '@xstate.cancel';
|
|
10
10
|
id: string;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
interface LogJSON {
|
|
13
13
|
type: '@xstate.log';
|
|
14
14
|
args: any[];
|
|
15
15
|
}
|
|
@@ -21,78 +21,12 @@ interface AssignJSON {
|
|
|
21
21
|
type: '@xstate.assign';
|
|
22
22
|
context: MachineContext;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
type: 'scxml.assign';
|
|
26
|
-
/** SCXML location attribute - the context property to assign to */
|
|
27
|
-
location: string;
|
|
28
|
-
/** SCXML expr attribute - expression to evaluate */
|
|
29
|
-
expr: string;
|
|
30
|
-
}
|
|
31
|
-
export interface ScxmlRaiseJSON {
|
|
32
|
-
type: 'scxml.raise';
|
|
33
|
-
/** Event type, or undefined if using eventexpr */
|
|
34
|
-
event?: string;
|
|
35
|
-
/** Expression to evaluate for event type */
|
|
36
|
-
eventexpr?: string;
|
|
37
|
-
/** Params with expressions to evaluate */
|
|
38
|
-
params?: Array<{
|
|
39
|
-
name: string;
|
|
40
|
-
expr: string;
|
|
41
|
-
}>;
|
|
42
|
-
id?: string;
|
|
43
|
-
delay?: number;
|
|
44
|
-
/** Expression for delay */
|
|
45
|
-
delayexpr?: string;
|
|
46
|
-
/** Static target (e.g. '#_parent') */
|
|
47
|
-
target?: string;
|
|
48
|
-
/** Expression for target */
|
|
49
|
-
targetexpr?: string;
|
|
50
|
-
}
|
|
51
|
-
interface ScxmlScriptJSON {
|
|
52
|
-
type: 'scxml.script';
|
|
53
|
-
/** The script code to execute */
|
|
54
|
-
code: string;
|
|
55
|
-
}
|
|
56
|
-
export interface ScxmlForeachJSON {
|
|
57
|
-
type: 'scxml.foreach';
|
|
58
|
-
array: string;
|
|
59
|
-
item: string;
|
|
60
|
-
index?: string;
|
|
61
|
-
actions: ActionJSON[];
|
|
62
|
-
}
|
|
63
|
-
export interface ScxmlCancelJSON {
|
|
64
|
-
type: 'scxml.cancel';
|
|
65
|
-
sendidexpr: string;
|
|
66
|
-
}
|
|
67
|
-
export interface ScxmlDonedataJSON {
|
|
68
|
-
params?: Array<{
|
|
69
|
-
name: string;
|
|
70
|
-
expr: string;
|
|
71
|
-
}>;
|
|
72
|
-
contentExpr?: string;
|
|
73
|
-
contentText?: string;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Isolated executable-content block. Errors in nested actions stop this block
|
|
77
|
-
* but do not propagate to the surrounding action list. Used to model SCXML's
|
|
78
|
-
* separate <onentry>/<onexit> blocks: each is its own block per spec.
|
|
79
|
-
*/
|
|
80
|
-
interface ScxmlBlockJSON {
|
|
81
|
-
type: 'scxml.block';
|
|
82
|
-
actions: ActionJSON[];
|
|
83
|
-
}
|
|
84
|
-
interface ScxmlIfJSON {
|
|
85
|
-
type: 'scxml.if';
|
|
86
|
-
branches: Array<{
|
|
87
|
-
cond?: string;
|
|
88
|
-
actions: ActionJSON[];
|
|
89
|
-
}>;
|
|
90
|
-
}
|
|
24
|
+
type BuiltInActionJSON = RaiseJSON | CancelJSON | LogJSON | EmitJSON | AssignJSON;
|
|
91
25
|
interface CustomActionJSON {
|
|
92
26
|
type: string;
|
|
93
27
|
params?: unknown;
|
|
94
28
|
}
|
|
95
|
-
export type ActionJSON = CustomActionJSON |
|
|
29
|
+
export type ActionJSON = CustomActionJSON | BuiltInActionJSON | ExpressionJSON | CodeJSON;
|
|
96
30
|
export interface GuardJSON {
|
|
97
31
|
type: string;
|
|
98
32
|
params?: unknown;
|
|
@@ -150,11 +84,6 @@ export interface StateNodeJSON {
|
|
|
150
84
|
after?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
|
|
151
85
|
always?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
152
86
|
choice?: ChoiceBranchJSON[] | ResolvableJSON;
|
|
153
|
-
/**
|
|
154
|
-
* JSON route config. Unlike the authoring API (a function), the JSON layer
|
|
155
|
-
* allows an object form whose `guard` may be a named guard reference (string)
|
|
156
|
-
* resolved against the machine's `guards` sources.
|
|
157
|
-
*/
|
|
158
87
|
route?: {
|
|
159
88
|
description?: string;
|
|
160
89
|
reenter?: boolean;
|
|
@@ -175,7 +104,6 @@ export interface StateNodeJSON {
|
|
|
175
104
|
target?: string | [string, ...string[]];
|
|
176
105
|
output?: unknown;
|
|
177
106
|
context?: Record<string, unknown>;
|
|
178
|
-
_scxmlDonedata?: ScxmlDonedataJSON;
|
|
179
107
|
}
|
|
180
108
|
export interface MachineJSON extends StateNodeJSON {
|
|
181
109
|
'@exprLang'?: string;
|