xstate 5.0.0-beta.38 → 5.0.0-beta.40
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/actions/dist/xstate-actions.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +60 -3
- package/actors/dist/xstate-actors.development.cjs.js +60 -3
- package/actors/dist/xstate-actors.development.esm.js +60 -3
- package/actors/dist/xstate-actors.esm.js +60 -3
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/StateMachine.d.ts +5 -5
- package/dist/declarations/src/actors/callback.d.ts +74 -0
- package/dist/declarations/src/actors/transition.d.ts +2 -2
- package/dist/declarations/src/interpreter.d.ts +70 -9
- package/dist/declarations/src/spawn.d.ts +2 -2
- package/dist/declarations/src/stateUtils.d.ts +4 -4
- package/dist/declarations/src/system.d.ts +7 -3
- package/dist/declarations/src/types.d.ts +7 -7
- package/dist/{interpreter-4005eb36.development.esm.js → interpreter-410d7ca9.development.esm.js} +92 -13
- package/dist/{interpreter-b6f22ee2.cjs.js → interpreter-586abde4.cjs.js} +92 -13
- package/dist/{interpreter-ed3f81f7.development.cjs.js → interpreter-bae5c279.development.cjs.js} +92 -13
- package/dist/{interpreter-c80ce92e.esm.js → interpreter-ed0fac7e.esm.js} +92 -13
- package/dist/{raise-7faa9b3b.cjs.js → raise-27909189.cjs.js} +83 -80
- package/dist/{raise-c989c7fb.esm.js → raise-2b2fdec3.esm.js} +83 -80
- package/dist/{raise-42073973.development.esm.js → raise-37f9f3b8.development.esm.js} +84 -81
- package/dist/{raise-b69a3d16.development.cjs.js → raise-8325e2df.development.cjs.js} +84 -81
- package/dist/{send-34160163.cjs.js → send-4fdf275e.cjs.js} +22 -22
- package/dist/{send-4b616da9.esm.js → send-59f66c58.esm.js} +22 -22
- package/dist/{send-58725522.development.cjs.js → send-c45d0d2c.development.cjs.js} +22 -22
- package/dist/{send-bff8c910.development.esm.js → send-f6b49072.development.esm.js} +22 -22
- package/dist/xstate.cjs.js +18 -17
- package/dist/xstate.development.cjs.js +18 -17
- package/dist/xstate.development.esm.js +21 -20
- package/dist/xstate.esm.js +21 -20
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.cjs.js +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -2
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, j as createErrorActorEvent, k as toStateValue, l as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, o as toStatePath, q as createDoneStateEvent, s as resolveOutput, X as XSTATE_STOP, u as XSTATE_INIT, W as WILDCARD, v as createAfterEvent, w as flatten, e as matchesState, $ as $$ACTOR_TYPE } from './interpreter-
|
|
1
|
+
import { r as resolveReferencedActor, d as createActor, f as ActorStatus, j as createErrorActorEvent, k as toStateValue, l as STATE_IDENTIFIER, n as normalizeTarget, t as toArray, N as NULL_EVENT, a as toTransitionConfigArray, S as STATE_DELIMITER, o as toStatePath, q as createDoneStateEvent, s as resolveOutput, X as XSTATE_STOP, u as XSTATE_INIT, W as WILDCARD, v as createAfterEvent, w as flatten, e as matchesState, $ as $$ACTOR_TYPE } from './interpreter-ed0fac7e.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -20,8 +20,8 @@ function resolveCancel(_, state, actionArgs, actionParams, {
|
|
|
20
20
|
const resolvedSendId = typeof sendId === 'function' ? sendId(actionArgs, actionParams) : sendId;
|
|
21
21
|
return [state, resolvedSendId];
|
|
22
22
|
}
|
|
23
|
-
function executeCancel(
|
|
24
|
-
|
|
23
|
+
function executeCancel(actorScope, resolvedSendId) {
|
|
24
|
+
actorScope.self.cancel(resolvedSendId);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Cancels an in-flight `send(...)` action. A canceled sent action will not
|
|
@@ -40,7 +40,7 @@ function cancel(sendId) {
|
|
|
40
40
|
return cancel;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function resolveSpawn(
|
|
43
|
+
function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
44
44
|
id,
|
|
45
45
|
systemId,
|
|
46
46
|
src,
|
|
@@ -59,19 +59,19 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
|
|
|
59
59
|
actorRef = createActor(referenced.src, {
|
|
60
60
|
id: resolvedId,
|
|
61
61
|
src: typeof src === 'string' ? src : undefined,
|
|
62
|
-
parent:
|
|
62
|
+
parent: actorScope?.self,
|
|
63
63
|
systemId,
|
|
64
64
|
input: typeof configuredInput === 'function' ? configuredInput({
|
|
65
65
|
context: state.context,
|
|
66
66
|
event: actionArgs.event,
|
|
67
|
-
self:
|
|
67
|
+
self: actorScope?.self
|
|
68
68
|
}) : configuredInput
|
|
69
69
|
});
|
|
70
70
|
if (syncSnapshot) {
|
|
71
71
|
actorRef.subscribe({
|
|
72
72
|
next: snapshot => {
|
|
73
73
|
if (snapshot.status === 'active') {
|
|
74
|
-
|
|
74
|
+
actorScope.self.send({
|
|
75
75
|
type: `xstate.snapshot.${id}`,
|
|
76
76
|
snapshot
|
|
77
77
|
});
|
|
@@ -91,21 +91,21 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
|
|
|
91
91
|
actorRef
|
|
92
92
|
}];
|
|
93
93
|
}
|
|
94
|
-
function executeSpawn(
|
|
94
|
+
function executeSpawn(actorScope, {
|
|
95
95
|
id,
|
|
96
96
|
actorRef
|
|
97
97
|
}) {
|
|
98
98
|
if (!actorRef) {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
actorScope.defer(() => {
|
|
102
102
|
if (actorRef.status === ActorStatus.Stopped) {
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
try {
|
|
106
106
|
actorRef.start?.();
|
|
107
107
|
} catch (err) {
|
|
108
|
-
|
|
108
|
+
actorScope.self.send(createErrorActorEvent(id, err));
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
});
|
|
@@ -145,7 +145,7 @@ function resolveStop(_, state, args, actionParams, {
|
|
|
145
145
|
children
|
|
146
146
|
}), resolvedActorRef];
|
|
147
147
|
}
|
|
148
|
-
function executeStop(
|
|
148
|
+
function executeStop(actorScope, actorRef) {
|
|
149
149
|
if (!actorRef) {
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
@@ -153,20 +153,20 @@ function executeStop(actorContext, actorRef) {
|
|
|
153
153
|
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
154
154
|
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
155
155
|
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
156
|
-
|
|
156
|
+
actorScope.system._unregister(actorRef);
|
|
157
157
|
|
|
158
158
|
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
159
159
|
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
160
160
|
if (actorRef.status !== ActorStatus.Running) {
|
|
161
|
-
|
|
161
|
+
actorScope.stopChild(actorRef);
|
|
162
162
|
return;
|
|
163
163
|
}
|
|
164
164
|
// stopping a child enqueues a stop event in the child actor's mailbox
|
|
165
165
|
// we need for all of the already enqueued events to be processed before we stop the child
|
|
166
166
|
// the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
|
|
167
167
|
// and we don't want to ignore those events
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
actorScope.defer(() => {
|
|
169
|
+
actorScope.stopChild(actorRef);
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
@@ -729,15 +729,6 @@ function isDescendant(childStateNode, parentStateNode) {
|
|
|
729
729
|
}
|
|
730
730
|
return marker.parent === parentStateNode;
|
|
731
731
|
}
|
|
732
|
-
function getPathFromRootToNode(stateNode) {
|
|
733
|
-
const path = [];
|
|
734
|
-
let marker = stateNode.parent;
|
|
735
|
-
while (marker) {
|
|
736
|
-
path.unshift(marker);
|
|
737
|
-
marker = marker.parent;
|
|
738
|
-
}
|
|
739
|
-
return path;
|
|
740
|
-
}
|
|
741
732
|
function hasIntersection(s1, s2) {
|
|
742
733
|
const set1 = new Set(s1);
|
|
743
734
|
const set2 = new Set(s2);
|
|
@@ -777,17 +768,13 @@ function removeConflictingTransitions(enabledTransitions, configuration, history
|
|
|
777
768
|
}
|
|
778
769
|
return Array.from(filteredTransitions);
|
|
779
770
|
}
|
|
780
|
-
function
|
|
781
|
-
const [head] = stateNodes;
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
candidates = current.filter(sn => path.includes(sn));
|
|
787
|
-
current = candidates;
|
|
788
|
-
candidates = [];
|
|
771
|
+
function findLeastCommonAncestor(stateNodes) {
|
|
772
|
+
const [head, ...tail] = stateNodes;
|
|
773
|
+
for (const ancestor of getProperAncestors(head, undefined)) {
|
|
774
|
+
if (tail.every(sn => isDescendant(sn, ancestor))) {
|
|
775
|
+
return ancestor;
|
|
776
|
+
}
|
|
789
777
|
}
|
|
790
|
-
return current[current.length - 1];
|
|
791
778
|
}
|
|
792
779
|
function getEffectiveTargetStates(transition, historyValue) {
|
|
793
780
|
if (!transition.target) {
|
|
@@ -819,8 +806,16 @@ function getTransitionDomain(transition, historyValue) {
|
|
|
819
806
|
if (!transition.reenter && targetStates.every(target => target === transition.source || isDescendant(target, transition.source))) {
|
|
820
807
|
return transition.source;
|
|
821
808
|
}
|
|
822
|
-
const
|
|
823
|
-
|
|
809
|
+
const lca = findLeastCommonAncestor(targetStates.concat(transition.source));
|
|
810
|
+
if (lca) {
|
|
811
|
+
return lca;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// at this point we know that it's a root transition since LCA couldn't be found
|
|
815
|
+
if (transition.reenter) {
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
return transition.source.machine.root;
|
|
824
819
|
}
|
|
825
820
|
function computeExitSet(transitions, configuration, historyValue) {
|
|
826
821
|
const statesToExit = new Set();
|
|
@@ -854,7 +849,7 @@ function areConfigurationsEqual(previousConfiguration, nextConfigurationSet) {
|
|
|
854
849
|
/**
|
|
855
850
|
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
856
851
|
*/
|
|
857
|
-
function microstep(transitions, currentState,
|
|
852
|
+
function microstep(transitions, currentState, actorScope, event, isInitial, internalQueue) {
|
|
858
853
|
if (!transitions.length) {
|
|
859
854
|
return currentState;
|
|
860
855
|
}
|
|
@@ -865,17 +860,17 @@ function microstep(transitions, currentState, actorCtx, event, isInitial, intern
|
|
|
865
860
|
|
|
866
861
|
// Exit states
|
|
867
862
|
if (!isInitial) {
|
|
868
|
-
[nextState, historyValue] = exitStates(nextState, event,
|
|
863
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, historyValue, internalQueue);
|
|
869
864
|
}
|
|
870
865
|
|
|
871
866
|
// Execute transition content
|
|
872
|
-
nextState = resolveActionsAndContext(nextState, event,
|
|
867
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
873
868
|
|
|
874
869
|
// Enter states
|
|
875
|
-
nextState = enterStates(nextState, event,
|
|
870
|
+
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
|
|
876
871
|
const nextConfiguration = [...mutConfiguration];
|
|
877
872
|
if (nextState.status === 'done') {
|
|
878
|
-
nextState = resolveActionsAndContext(nextState, event,
|
|
873
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
|
|
879
874
|
}
|
|
880
875
|
try {
|
|
881
876
|
if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
|
|
@@ -891,14 +886,14 @@ function microstep(transitions, currentState, actorCtx, event, isInitial, intern
|
|
|
891
886
|
throw e;
|
|
892
887
|
}
|
|
893
888
|
}
|
|
894
|
-
function getMachineOutput(state, event,
|
|
889
|
+
function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode) {
|
|
895
890
|
if (!rootNode.output) {
|
|
896
891
|
return;
|
|
897
892
|
}
|
|
898
|
-
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event,
|
|
899
|
-
return resolveOutput(rootNode.output, state.context, doneStateEvent,
|
|
893
|
+
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
|
|
894
|
+
return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
|
|
900
895
|
}
|
|
901
|
-
function enterStates(currentState, event,
|
|
896
|
+
function enterStates(currentState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
|
|
902
897
|
let nextState = currentState;
|
|
903
898
|
const statesToEnter = new Set();
|
|
904
899
|
// those are states that were directly targeted or indirectly targeted by the explicit target
|
|
@@ -928,13 +923,13 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
|
|
|
928
923
|
const initialActions = stateNodeToEnter.initial.actions;
|
|
929
924
|
actions.push(...initialActions);
|
|
930
925
|
}
|
|
931
|
-
nextState = resolveActionsAndContext(nextState, event,
|
|
926
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
|
|
932
927
|
if (stateNodeToEnter.type === 'final') {
|
|
933
928
|
const parent = stateNodeToEnter.parent;
|
|
934
929
|
let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
|
|
935
930
|
let rootCompletionNode = ancestorMarker || stateNodeToEnter;
|
|
936
931
|
if (parent?.type === 'compound') {
|
|
937
|
-
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event,
|
|
932
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
|
|
938
933
|
}
|
|
939
934
|
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutConfiguration, ancestorMarker)) {
|
|
940
935
|
completedNodes.add(ancestorMarker);
|
|
@@ -947,7 +942,7 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
|
|
|
947
942
|
}
|
|
948
943
|
nextState = cloneState(nextState, {
|
|
949
944
|
status: 'done',
|
|
950
|
-
output: getMachineOutput(nextState, event,
|
|
945
|
+
output: getMachineOutput(nextState, event, actorScope, currentState.configuration[0].machine.root, rootCompletionNode)
|
|
951
946
|
});
|
|
952
947
|
}
|
|
953
948
|
}
|
|
@@ -972,7 +967,11 @@ function computeEntrySet(transitions, historyValue, statesForDefaultEntry, state
|
|
|
972
967
|
}
|
|
973
968
|
const targetStates = getEffectiveTargetStates(t, historyValue);
|
|
974
969
|
for (const s of targetStates) {
|
|
975
|
-
|
|
970
|
+
const ancestors = getProperAncestors(s, domain);
|
|
971
|
+
if (domain?.type === 'parallel') {
|
|
972
|
+
ancestors.push(domain);
|
|
973
|
+
}
|
|
974
|
+
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, !t.source.parent && t.reenter ? undefined : domain);
|
|
976
975
|
}
|
|
977
976
|
}
|
|
978
977
|
}
|
|
@@ -985,7 +984,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
985
984
|
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
986
985
|
}
|
|
987
986
|
for (const s of historyStateNodes) {
|
|
988
|
-
|
|
987
|
+
addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
|
|
989
988
|
}
|
|
990
989
|
} else {
|
|
991
990
|
const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
|
|
@@ -997,7 +996,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
997
996
|
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
998
997
|
}
|
|
999
998
|
for (const s of historyDefaultTransition.target) {
|
|
1000
|
-
|
|
999
|
+
addProperAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
1001
1000
|
}
|
|
1002
1001
|
}
|
|
1003
1002
|
} else {
|
|
@@ -1008,7 +1007,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
1008
1007
|
statesForDefaultEntry.add(initialState);
|
|
1009
1008
|
}
|
|
1010
1009
|
addDescendantStatesToEnter(initialState, historyValue, statesForDefaultEntry, statesToEnter);
|
|
1011
|
-
|
|
1010
|
+
addProperAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
1012
1011
|
} else {
|
|
1013
1012
|
if (stateNode.type === 'parallel') {
|
|
1014
1013
|
for (const child of getChildren(stateNode).filter(sn => !isHistoryNode(sn))) {
|
|
@@ -1024,10 +1023,11 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
1024
1023
|
}
|
|
1025
1024
|
}
|
|
1026
1025
|
}
|
|
1027
|
-
function addAncestorStatesToEnter(
|
|
1028
|
-
const
|
|
1029
|
-
|
|
1030
|
-
|
|
1026
|
+
function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, reentrancyDomain) {
|
|
1027
|
+
for (const anc of ancestors) {
|
|
1028
|
+
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
1029
|
+
statesToEnter.add(anc);
|
|
1030
|
+
}
|
|
1031
1031
|
if (anc.type === 'parallel') {
|
|
1032
1032
|
for (const child of getChildren(anc).filter(sn => !isHistoryNode(sn))) {
|
|
1033
1033
|
if (![...statesToEnter].some(s => isDescendant(s, child))) {
|
|
@@ -1038,7 +1038,10 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
|
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
|
1041
|
-
function
|
|
1041
|
+
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
1042
|
+
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
1043
|
+
}
|
|
1044
|
+
function exitStates(currentState, event, actorScope, transitions, mutConfiguration, historyValue, internalQueue) {
|
|
1042
1045
|
let nextState = currentState;
|
|
1043
1046
|
const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
|
|
1044
1047
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
@@ -1062,12 +1065,12 @@ function exitStates(currentState, event, actorCtx, transitions, mutConfiguration
|
|
|
1062
1065
|
}
|
|
1063
1066
|
}
|
|
1064
1067
|
for (const s of statesToExit) {
|
|
1065
|
-
nextState = resolveActionsAndContext(nextState, event,
|
|
1068
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
|
|
1066
1069
|
mutConfiguration.delete(s);
|
|
1067
1070
|
}
|
|
1068
1071
|
return [nextState, changedHistory || historyValue];
|
|
1069
1072
|
}
|
|
1070
|
-
function resolveActionsAndContextWorker(currentState, event,
|
|
1073
|
+
function resolveActionsAndContextWorker(currentState, event, actorScope, actions, extra, retries) {
|
|
1071
1074
|
const {
|
|
1072
1075
|
machine
|
|
1073
1076
|
} = currentState;
|
|
@@ -1085,25 +1088,25 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
|
|
|
1085
1088
|
const actionArgs = {
|
|
1086
1089
|
context: intermediateState.context,
|
|
1087
1090
|
event,
|
|
1088
|
-
self:
|
|
1089
|
-
system:
|
|
1091
|
+
self: actorScope?.self,
|
|
1092
|
+
system: actorScope?.system
|
|
1090
1093
|
};
|
|
1091
1094
|
const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
|
|
1092
1095
|
context: intermediateState.context,
|
|
1093
1096
|
event
|
|
1094
1097
|
}) : action.params : undefined;
|
|
1095
1098
|
if (!('resolve' in resolvedAction)) {
|
|
1096
|
-
if (
|
|
1099
|
+
if (actorScope?.self.status === ActorStatus.Running) {
|
|
1097
1100
|
resolvedAction(actionArgs, actionParams);
|
|
1098
1101
|
} else {
|
|
1099
|
-
|
|
1102
|
+
actorScope?.defer(() => {
|
|
1100
1103
|
resolvedAction(actionArgs, actionParams);
|
|
1101
1104
|
});
|
|
1102
1105
|
}
|
|
1103
1106
|
continue;
|
|
1104
1107
|
}
|
|
1105
1108
|
const builtinAction = resolvedAction;
|
|
1106
|
-
const [nextState, params, actions] = builtinAction.resolve(
|
|
1109
|
+
const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateState, actionArgs, actionParams, resolvedAction,
|
|
1107
1110
|
// this holds all params
|
|
1108
1111
|
extra);
|
|
1109
1112
|
intermediateState = nextState;
|
|
@@ -1111,36 +1114,36 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
|
|
|
1111
1114
|
retries?.push([builtinAction, params]);
|
|
1112
1115
|
}
|
|
1113
1116
|
if ('execute' in builtinAction) {
|
|
1114
|
-
if (
|
|
1115
|
-
builtinAction.execute(
|
|
1117
|
+
if (actorScope?.self.status === ActorStatus.Running) {
|
|
1118
|
+
builtinAction.execute(actorScope, params);
|
|
1116
1119
|
} else {
|
|
1117
|
-
|
|
1120
|
+
actorScope?.defer(builtinAction.execute.bind(null, actorScope, params));
|
|
1118
1121
|
}
|
|
1119
1122
|
}
|
|
1120
1123
|
if (actions) {
|
|
1121
|
-
intermediateState = resolveActionsAndContextWorker(intermediateState, event,
|
|
1124
|
+
intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorScope, actions, extra, retries);
|
|
1122
1125
|
}
|
|
1123
1126
|
}
|
|
1124
1127
|
return intermediateState;
|
|
1125
1128
|
}
|
|
1126
|
-
function resolveActionsAndContext(currentState, event,
|
|
1129
|
+
function resolveActionsAndContext(currentState, event, actorScope, actions, internalQueue, deferredActorIds) {
|
|
1127
1130
|
const retries = deferredActorIds ? [] : undefined;
|
|
1128
|
-
const nextState = resolveActionsAndContextWorker(currentState, event,
|
|
1131
|
+
const nextState = resolveActionsAndContextWorker(currentState, event, actorScope, actions, {
|
|
1129
1132
|
internalQueue,
|
|
1130
1133
|
deferredActorIds
|
|
1131
1134
|
}, retries);
|
|
1132
1135
|
retries?.forEach(([builtinAction, params]) => {
|
|
1133
|
-
builtinAction.retryResolve(
|
|
1136
|
+
builtinAction.retryResolve(actorScope, nextState, params);
|
|
1134
1137
|
});
|
|
1135
1138
|
return nextState;
|
|
1136
1139
|
}
|
|
1137
|
-
function macrostep(state, event,
|
|
1140
|
+
function macrostep(state, event, actorScope, internalQueue = []) {
|
|
1138
1141
|
let nextState = state;
|
|
1139
1142
|
const states = [];
|
|
1140
1143
|
|
|
1141
1144
|
// Handle stop event
|
|
1142
1145
|
if (event.type === XSTATE_STOP) {
|
|
1143
|
-
nextState = cloneState(stopChildren(nextState, event,
|
|
1146
|
+
nextState = cloneState(stopChildren(nextState, event, actorScope), {
|
|
1144
1147
|
status: 'stopped'
|
|
1145
1148
|
});
|
|
1146
1149
|
states.push(nextState);
|
|
@@ -1155,7 +1158,7 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
|
|
|
1155
1158
|
// Determine the next state based on the next microstep
|
|
1156
1159
|
if (nextEvent.type !== XSTATE_INIT) {
|
|
1157
1160
|
const transitions = selectTransitions(nextEvent, nextState);
|
|
1158
|
-
nextState = microstep(transitions, state,
|
|
1161
|
+
nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
|
|
1159
1162
|
states.push(nextState);
|
|
1160
1163
|
}
|
|
1161
1164
|
let shouldSelectEventlessTransitions = true;
|
|
@@ -1172,20 +1175,20 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
|
|
|
1172
1175
|
nextEvent = internalQueue.shift();
|
|
1173
1176
|
enabledTransitions = selectTransitions(nextEvent, nextState);
|
|
1174
1177
|
}
|
|
1175
|
-
nextState = microstep(enabledTransitions, nextState,
|
|
1178
|
+
nextState = microstep(enabledTransitions, nextState, actorScope, nextEvent, false, internalQueue);
|
|
1176
1179
|
shouldSelectEventlessTransitions = nextState !== previousState;
|
|
1177
1180
|
states.push(nextState);
|
|
1178
1181
|
}
|
|
1179
1182
|
if (nextState.status !== 'active') {
|
|
1180
|
-
stopChildren(nextState, nextEvent,
|
|
1183
|
+
stopChildren(nextState, nextEvent, actorScope);
|
|
1181
1184
|
}
|
|
1182
1185
|
return {
|
|
1183
1186
|
state: nextState,
|
|
1184
1187
|
microstates: states
|
|
1185
1188
|
};
|
|
1186
1189
|
}
|
|
1187
|
-
function stopChildren(nextState, event,
|
|
1188
|
-
return resolveActionsAndContext(nextState, event,
|
|
1190
|
+
function stopChildren(nextState, event, actorScope) {
|
|
1191
|
+
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stop(child)), []);
|
|
1189
1192
|
}
|
|
1190
1193
|
function selectTransitions(event, nextState) {
|
|
1191
1194
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -1466,9 +1469,9 @@ function resolveRaise(_, state, args, actionParams, {
|
|
|
1466
1469
|
delay: resolvedDelay
|
|
1467
1470
|
}];
|
|
1468
1471
|
}
|
|
1469
|
-
function executeRaise(
|
|
1472
|
+
function executeRaise(actorScope, params) {
|
|
1470
1473
|
if (typeof params.delay === 'number') {
|
|
1471
|
-
|
|
1474
|
+
actorScope.self.delaySend(params);
|
|
1472
1475
|
return;
|
|
1473
1476
|
}
|
|
1474
1477
|
}
|