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