xstate 5.0.0-beta.38 → 5.0.0-beta.39
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/types.d.ts +7 -7
- package/dist/{interpreter-ed3f81f7.development.cjs.js → interpreter-03a5c3f5.development.cjs.js} +90 -11
- package/dist/{interpreter-c80ce92e.esm.js → interpreter-1e8c1c0c.esm.js} +90 -11
- package/dist/{interpreter-b6f22ee2.cjs.js → interpreter-5dfcd203.cjs.js} +90 -11
- package/dist/{interpreter-4005eb36.development.esm.js → interpreter-70cd9217.development.esm.js} +90 -11
- package/dist/{raise-b69a3d16.development.cjs.js → raise-17cb3d9d.development.cjs.js} +84 -81
- package/dist/{raise-7faa9b3b.cjs.js → raise-291d2181.cjs.js} +83 -80
- package/dist/{raise-c989c7fb.esm.js → raise-62de3670.esm.js} +83 -80
- package/dist/{raise-42073973.development.esm.js → raise-e044f460.development.esm.js} +84 -81
- package/dist/{send-4b616da9.esm.js → send-1249d4ac.esm.js} +22 -22
- package/dist/{send-58725522.development.cjs.js → send-33433787.development.cjs.js} +22 -22
- package/dist/{send-34160163.cjs.js → send-af152aca.cjs.js} +22 -22
- package/dist/{send-bff8c910.development.esm.js → send-f1a2a827.development.esm.js} +22 -22
- package/dist/xstate.cjs.js +17 -17
- package/dist/xstate.development.cjs.js +17 -17
- package/dist/xstate.development.esm.js +20 -20
- package/dist/xstate.esm.js +20 -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, W as WILDCARD, X as XSTATE_STOP, u as XSTATE_INIT, 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, W as WILDCARD, X as XSTATE_STOP, u as XSTATE_INIT, v as createAfterEvent, w as flatten, e as matchesState, $ as $$ACTOR_TYPE } from './interpreter-70cd9217.development.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
|
|
@@ -43,7 +43,7 @@ function cancel(sendId) {
|
|
|
43
43
|
return cancel;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function resolveSpawn(
|
|
46
|
+
function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
47
47
|
id,
|
|
48
48
|
systemId,
|
|
49
49
|
src,
|
|
@@ -62,19 +62,19 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
|
|
|
62
62
|
actorRef = createActor(referenced.src, {
|
|
63
63
|
id: resolvedId,
|
|
64
64
|
src: typeof src === 'string' ? src : undefined,
|
|
65
|
-
parent:
|
|
65
|
+
parent: actorScope?.self,
|
|
66
66
|
systemId,
|
|
67
67
|
input: typeof configuredInput === 'function' ? configuredInput({
|
|
68
68
|
context: state.context,
|
|
69
69
|
event: actionArgs.event,
|
|
70
|
-
self:
|
|
70
|
+
self: actorScope?.self
|
|
71
71
|
}) : configuredInput
|
|
72
72
|
});
|
|
73
73
|
if (syncSnapshot) {
|
|
74
74
|
actorRef.subscribe({
|
|
75
75
|
next: snapshot => {
|
|
76
76
|
if (snapshot.status === 'active') {
|
|
77
|
-
|
|
77
|
+
actorScope.self.send({
|
|
78
78
|
type: `xstate.snapshot.${id}`,
|
|
79
79
|
snapshot
|
|
80
80
|
});
|
|
@@ -85,7 +85,7 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
if (!actorRef) {
|
|
88
|
-
console.warn(`Actor type '${src}' not found in machine '${
|
|
88
|
+
console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
|
|
89
89
|
}
|
|
90
90
|
return [cloneState(state, {
|
|
91
91
|
children: {
|
|
@@ -97,21 +97,21 @@ function resolveSpawn(actorContext, state, actionArgs, _actionParams, {
|
|
|
97
97
|
actorRef
|
|
98
98
|
}];
|
|
99
99
|
}
|
|
100
|
-
function executeSpawn(
|
|
100
|
+
function executeSpawn(actorScope, {
|
|
101
101
|
id,
|
|
102
102
|
actorRef
|
|
103
103
|
}) {
|
|
104
104
|
if (!actorRef) {
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
|
-
|
|
107
|
+
actorScope.defer(() => {
|
|
108
108
|
if (actorRef.status === ActorStatus.Stopped) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
try {
|
|
112
112
|
actorRef.start?.();
|
|
113
113
|
} catch (err) {
|
|
114
|
-
|
|
114
|
+
actorScope.self.send(createErrorActorEvent(id, err));
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
});
|
|
@@ -154,7 +154,7 @@ function resolveStop(_, state, args, actionParams, {
|
|
|
154
154
|
children
|
|
155
155
|
}), resolvedActorRef];
|
|
156
156
|
}
|
|
157
|
-
function executeStop(
|
|
157
|
+
function executeStop(actorScope, actorRef) {
|
|
158
158
|
if (!actorRef) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
@@ -162,20 +162,20 @@ function executeStop(actorContext, actorRef) {
|
|
|
162
162
|
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
163
163
|
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
164
164
|
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
165
|
-
|
|
165
|
+
actorScope.system._unregister(actorRef);
|
|
166
166
|
|
|
167
167
|
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
168
168
|
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
169
169
|
if (actorRef.status !== ActorStatus.Running) {
|
|
170
|
-
|
|
170
|
+
actorScope.stopChild(actorRef);
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
173
|
// stopping a child enqueues a stop event in the child actor's mailbox
|
|
174
174
|
// we need for all of the already enqueued events to be processed before we stop the child
|
|
175
175
|
// the parent itself might want to send some events to a child (for example from exit actions on the invoking state)
|
|
176
176
|
// and we don't want to ignore those events
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
actorScope.defer(() => {
|
|
178
|
+
actorScope.stopChild(actorRef);
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
/**
|
|
@@ -760,15 +760,6 @@ function isDescendant(childStateNode, parentStateNode) {
|
|
|
760
760
|
}
|
|
761
761
|
return marker.parent === parentStateNode;
|
|
762
762
|
}
|
|
763
|
-
function getPathFromRootToNode(stateNode) {
|
|
764
|
-
const path = [];
|
|
765
|
-
let marker = stateNode.parent;
|
|
766
|
-
while (marker) {
|
|
767
|
-
path.unshift(marker);
|
|
768
|
-
marker = marker.parent;
|
|
769
|
-
}
|
|
770
|
-
return path;
|
|
771
|
-
}
|
|
772
763
|
function hasIntersection(s1, s2) {
|
|
773
764
|
const set1 = new Set(s1);
|
|
774
765
|
const set2 = new Set(s2);
|
|
@@ -808,17 +799,13 @@ function removeConflictingTransitions(enabledTransitions, configuration, history
|
|
|
808
799
|
}
|
|
809
800
|
return Array.from(filteredTransitions);
|
|
810
801
|
}
|
|
811
|
-
function
|
|
812
|
-
const [head] = stateNodes;
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
candidates = current.filter(sn => path.includes(sn));
|
|
818
|
-
current = candidates;
|
|
819
|
-
candidates = [];
|
|
802
|
+
function findLeastCommonAncestor(stateNodes) {
|
|
803
|
+
const [head, ...tail] = stateNodes;
|
|
804
|
+
for (const ancestor of getProperAncestors(head, undefined)) {
|
|
805
|
+
if (tail.every(sn => isDescendant(sn, ancestor))) {
|
|
806
|
+
return ancestor;
|
|
807
|
+
}
|
|
820
808
|
}
|
|
821
|
-
return current[current.length - 1];
|
|
822
809
|
}
|
|
823
810
|
function getEffectiveTargetStates(transition, historyValue) {
|
|
824
811
|
if (!transition.target) {
|
|
@@ -850,8 +837,16 @@ function getTransitionDomain(transition, historyValue) {
|
|
|
850
837
|
if (!transition.reenter && targetStates.every(target => target === transition.source || isDescendant(target, transition.source))) {
|
|
851
838
|
return transition.source;
|
|
852
839
|
}
|
|
853
|
-
const
|
|
854
|
-
|
|
840
|
+
const lca = findLeastCommonAncestor(targetStates.concat(transition.source));
|
|
841
|
+
if (lca) {
|
|
842
|
+
return lca;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// at this point we know that it's a root transition since LCA couldn't be found
|
|
846
|
+
if (transition.reenter) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
return transition.source.machine.root;
|
|
855
850
|
}
|
|
856
851
|
function computeExitSet(transitions, configuration, historyValue) {
|
|
857
852
|
const statesToExit = new Set();
|
|
@@ -885,7 +880,7 @@ function areConfigurationsEqual(previousConfiguration, nextConfigurationSet) {
|
|
|
885
880
|
/**
|
|
886
881
|
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
887
882
|
*/
|
|
888
|
-
function microstep(transitions, currentState,
|
|
883
|
+
function microstep(transitions, currentState, actorScope, event, isInitial, internalQueue) {
|
|
889
884
|
if (!transitions.length) {
|
|
890
885
|
return currentState;
|
|
891
886
|
}
|
|
@@ -896,17 +891,17 @@ function microstep(transitions, currentState, actorCtx, event, isInitial, intern
|
|
|
896
891
|
|
|
897
892
|
// Exit states
|
|
898
893
|
if (!isInitial) {
|
|
899
|
-
[nextState, historyValue] = exitStates(nextState, event,
|
|
894
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, historyValue, internalQueue);
|
|
900
895
|
}
|
|
901
896
|
|
|
902
897
|
// Execute transition content
|
|
903
|
-
nextState = resolveActionsAndContext(nextState, event,
|
|
898
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
904
899
|
|
|
905
900
|
// Enter states
|
|
906
|
-
nextState = enterStates(nextState, event,
|
|
901
|
+
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
|
|
907
902
|
const nextConfiguration = [...mutConfiguration];
|
|
908
903
|
if (nextState.status === 'done') {
|
|
909
|
-
nextState = resolveActionsAndContext(nextState, event,
|
|
904
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
|
|
910
905
|
}
|
|
911
906
|
try {
|
|
912
907
|
if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
|
|
@@ -922,14 +917,14 @@ function microstep(transitions, currentState, actorCtx, event, isInitial, intern
|
|
|
922
917
|
throw e;
|
|
923
918
|
}
|
|
924
919
|
}
|
|
925
|
-
function getMachineOutput(state, event,
|
|
920
|
+
function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode) {
|
|
926
921
|
if (!rootNode.output) {
|
|
927
922
|
return;
|
|
928
923
|
}
|
|
929
|
-
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event,
|
|
930
|
-
return resolveOutput(rootNode.output, state.context, doneStateEvent,
|
|
924
|
+
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
|
|
925
|
+
return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
|
|
931
926
|
}
|
|
932
|
-
function enterStates(currentState, event,
|
|
927
|
+
function enterStates(currentState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
|
|
933
928
|
let nextState = currentState;
|
|
934
929
|
const statesToEnter = new Set();
|
|
935
930
|
// those are states that were directly targeted or indirectly targeted by the explicit target
|
|
@@ -959,13 +954,13 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
|
|
|
959
954
|
const initialActions = stateNodeToEnter.initial.actions;
|
|
960
955
|
actions.push(...initialActions);
|
|
961
956
|
}
|
|
962
|
-
nextState = resolveActionsAndContext(nextState, event,
|
|
957
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, actions, internalQueue, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
|
|
963
958
|
if (stateNodeToEnter.type === 'final') {
|
|
964
959
|
const parent = stateNodeToEnter.parent;
|
|
965
960
|
let ancestorMarker = parent?.type === 'parallel' ? parent : parent?.parent;
|
|
966
961
|
let rootCompletionNode = ancestorMarker || stateNodeToEnter;
|
|
967
962
|
if (parent?.type === 'compound') {
|
|
968
|
-
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event,
|
|
963
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
|
|
969
964
|
}
|
|
970
965
|
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutConfiguration, ancestorMarker)) {
|
|
971
966
|
completedNodes.add(ancestorMarker);
|
|
@@ -978,7 +973,7 @@ function enterStates(currentState, event, actorCtx, filteredTransitions, mutConf
|
|
|
978
973
|
}
|
|
979
974
|
nextState = cloneState(nextState, {
|
|
980
975
|
status: 'done',
|
|
981
|
-
output: getMachineOutput(nextState, event,
|
|
976
|
+
output: getMachineOutput(nextState, event, actorScope, currentState.configuration[0].machine.root, rootCompletionNode)
|
|
982
977
|
});
|
|
983
978
|
}
|
|
984
979
|
}
|
|
@@ -1003,7 +998,11 @@ function computeEntrySet(transitions, historyValue, statesForDefaultEntry, state
|
|
|
1003
998
|
}
|
|
1004
999
|
const targetStates = getEffectiveTargetStates(t, historyValue);
|
|
1005
1000
|
for (const s of targetStates) {
|
|
1006
|
-
|
|
1001
|
+
const ancestors = getProperAncestors(s, domain);
|
|
1002
|
+
if (domain?.type === 'parallel') {
|
|
1003
|
+
ancestors.push(domain);
|
|
1004
|
+
}
|
|
1005
|
+
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, !t.source.parent && t.reenter ? undefined : domain);
|
|
1007
1006
|
}
|
|
1008
1007
|
}
|
|
1009
1008
|
}
|
|
@@ -1016,7 +1015,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
1016
1015
|
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
1017
1016
|
}
|
|
1018
1017
|
for (const s of historyStateNodes) {
|
|
1019
|
-
|
|
1018
|
+
addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
|
|
1020
1019
|
}
|
|
1021
1020
|
} else {
|
|
1022
1021
|
const historyDefaultTransition = resolveHistoryDefaultTransition(stateNode);
|
|
@@ -1028,7 +1027,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
1028
1027
|
addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
|
|
1029
1028
|
}
|
|
1030
1029
|
for (const s of historyDefaultTransition.target) {
|
|
1031
|
-
|
|
1030
|
+
addProperAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
1032
1031
|
}
|
|
1033
1032
|
}
|
|
1034
1033
|
} else {
|
|
@@ -1039,7 +1038,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
1039
1038
|
statesForDefaultEntry.add(initialState);
|
|
1040
1039
|
}
|
|
1041
1040
|
addDescendantStatesToEnter(initialState, historyValue, statesForDefaultEntry, statesToEnter);
|
|
1042
|
-
|
|
1041
|
+
addProperAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
1043
1042
|
} else {
|
|
1044
1043
|
if (stateNode.type === 'parallel') {
|
|
1045
1044
|
for (const child of getChildren(stateNode).filter(sn => !isHistoryNode(sn))) {
|
|
@@ -1055,10 +1054,11 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
1055
1054
|
}
|
|
1056
1055
|
}
|
|
1057
1056
|
}
|
|
1058
|
-
function addAncestorStatesToEnter(
|
|
1059
|
-
const
|
|
1060
|
-
|
|
1061
|
-
|
|
1057
|
+
function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, ancestors, reentrancyDomain) {
|
|
1058
|
+
for (const anc of ancestors) {
|
|
1059
|
+
if (!reentrancyDomain || isDescendant(anc, reentrancyDomain)) {
|
|
1060
|
+
statesToEnter.add(anc);
|
|
1061
|
+
}
|
|
1062
1062
|
if (anc.type === 'parallel') {
|
|
1063
1063
|
for (const child of getChildren(anc).filter(sn => !isHistoryNode(sn))) {
|
|
1064
1064
|
if (![...statesToEnter].some(s => isDescendant(s, child))) {
|
|
@@ -1069,7 +1069,10 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
|
|
|
1069
1069
|
}
|
|
1070
1070
|
}
|
|
1071
1071
|
}
|
|
1072
|
-
function
|
|
1072
|
+
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
1073
|
+
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
1074
|
+
}
|
|
1075
|
+
function exitStates(currentState, event, actorScope, transitions, mutConfiguration, historyValue, internalQueue) {
|
|
1073
1076
|
let nextState = currentState;
|
|
1074
1077
|
const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
|
|
1075
1078
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
@@ -1093,12 +1096,12 @@ function exitStates(currentState, event, actorCtx, transitions, mutConfiguration
|
|
|
1093
1096
|
}
|
|
1094
1097
|
}
|
|
1095
1098
|
for (const s of statesToExit) {
|
|
1096
|
-
nextState = resolveActionsAndContext(nextState, event,
|
|
1099
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
|
|
1097
1100
|
mutConfiguration.delete(s);
|
|
1098
1101
|
}
|
|
1099
1102
|
return [nextState, changedHistory || historyValue];
|
|
1100
1103
|
}
|
|
1101
|
-
function resolveActionsAndContextWorker(currentState, event,
|
|
1104
|
+
function resolveActionsAndContextWorker(currentState, event, actorScope, actions, extra, retries) {
|
|
1102
1105
|
const {
|
|
1103
1106
|
machine
|
|
1104
1107
|
} = currentState;
|
|
@@ -1116,25 +1119,25 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
|
|
|
1116
1119
|
const actionArgs = {
|
|
1117
1120
|
context: intermediateState.context,
|
|
1118
1121
|
event,
|
|
1119
|
-
self:
|
|
1120
|
-
system:
|
|
1122
|
+
self: actorScope?.self,
|
|
1123
|
+
system: actorScope?.system
|
|
1121
1124
|
};
|
|
1122
1125
|
const actionParams = isInline || typeof action === 'string' ? undefined : 'params' in action ? typeof action.params === 'function' ? action.params({
|
|
1123
1126
|
context: intermediateState.context,
|
|
1124
1127
|
event
|
|
1125
1128
|
}) : action.params : undefined;
|
|
1126
1129
|
if (!('resolve' in resolvedAction)) {
|
|
1127
|
-
if (
|
|
1130
|
+
if (actorScope?.self.status === ActorStatus.Running) {
|
|
1128
1131
|
resolvedAction(actionArgs, actionParams);
|
|
1129
1132
|
} else {
|
|
1130
|
-
|
|
1133
|
+
actorScope?.defer(() => {
|
|
1131
1134
|
resolvedAction(actionArgs, actionParams);
|
|
1132
1135
|
});
|
|
1133
1136
|
}
|
|
1134
1137
|
continue;
|
|
1135
1138
|
}
|
|
1136
1139
|
const builtinAction = resolvedAction;
|
|
1137
|
-
const [nextState, params, actions] = builtinAction.resolve(
|
|
1140
|
+
const [nextState, params, actions] = builtinAction.resolve(actorScope, intermediateState, actionArgs, actionParams, resolvedAction,
|
|
1138
1141
|
// this holds all params
|
|
1139
1142
|
extra);
|
|
1140
1143
|
intermediateState = nextState;
|
|
@@ -1142,30 +1145,30 @@ function resolveActionsAndContextWorker(currentState, event, actorCtx, actions,
|
|
|
1142
1145
|
retries?.push([builtinAction, params]);
|
|
1143
1146
|
}
|
|
1144
1147
|
if ('execute' in builtinAction) {
|
|
1145
|
-
if (
|
|
1146
|
-
builtinAction.execute(
|
|
1148
|
+
if (actorScope?.self.status === ActorStatus.Running) {
|
|
1149
|
+
builtinAction.execute(actorScope, params);
|
|
1147
1150
|
} else {
|
|
1148
|
-
|
|
1151
|
+
actorScope?.defer(builtinAction.execute.bind(null, actorScope, params));
|
|
1149
1152
|
}
|
|
1150
1153
|
}
|
|
1151
1154
|
if (actions) {
|
|
1152
|
-
intermediateState = resolveActionsAndContextWorker(intermediateState, event,
|
|
1155
|
+
intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorScope, actions, extra, retries);
|
|
1153
1156
|
}
|
|
1154
1157
|
}
|
|
1155
1158
|
return intermediateState;
|
|
1156
1159
|
}
|
|
1157
|
-
function resolveActionsAndContext(currentState, event,
|
|
1160
|
+
function resolveActionsAndContext(currentState, event, actorScope, actions, internalQueue, deferredActorIds) {
|
|
1158
1161
|
const retries = deferredActorIds ? [] : undefined;
|
|
1159
|
-
const nextState = resolveActionsAndContextWorker(currentState, event,
|
|
1162
|
+
const nextState = resolveActionsAndContextWorker(currentState, event, actorScope, actions, {
|
|
1160
1163
|
internalQueue,
|
|
1161
1164
|
deferredActorIds
|
|
1162
1165
|
}, retries);
|
|
1163
1166
|
retries?.forEach(([builtinAction, params]) => {
|
|
1164
|
-
builtinAction.retryResolve(
|
|
1167
|
+
builtinAction.retryResolve(actorScope, nextState, params);
|
|
1165
1168
|
});
|
|
1166
1169
|
return nextState;
|
|
1167
1170
|
}
|
|
1168
|
-
function macrostep(state, event,
|
|
1171
|
+
function macrostep(state, event, actorScope, internalQueue = []) {
|
|
1169
1172
|
if (event.type === WILDCARD) {
|
|
1170
1173
|
throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
|
|
1171
1174
|
}
|
|
@@ -1174,7 +1177,7 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
|
|
|
1174
1177
|
|
|
1175
1178
|
// Handle stop event
|
|
1176
1179
|
if (event.type === XSTATE_STOP) {
|
|
1177
|
-
nextState = cloneState(stopChildren(nextState, event,
|
|
1180
|
+
nextState = cloneState(stopChildren(nextState, event, actorScope), {
|
|
1178
1181
|
status: 'stopped'
|
|
1179
1182
|
});
|
|
1180
1183
|
states.push(nextState);
|
|
@@ -1189,7 +1192,7 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
|
|
|
1189
1192
|
// Determine the next state based on the next microstep
|
|
1190
1193
|
if (nextEvent.type !== XSTATE_INIT) {
|
|
1191
1194
|
const transitions = selectTransitions(nextEvent, nextState);
|
|
1192
|
-
nextState = microstep(transitions, state,
|
|
1195
|
+
nextState = microstep(transitions, state, actorScope, nextEvent, false, internalQueue);
|
|
1193
1196
|
states.push(nextState);
|
|
1194
1197
|
}
|
|
1195
1198
|
let shouldSelectEventlessTransitions = true;
|
|
@@ -1206,20 +1209,20 @@ function macrostep(state, event, actorCtx, internalQueue = []) {
|
|
|
1206
1209
|
nextEvent = internalQueue.shift();
|
|
1207
1210
|
enabledTransitions = selectTransitions(nextEvent, nextState);
|
|
1208
1211
|
}
|
|
1209
|
-
nextState = microstep(enabledTransitions, nextState,
|
|
1212
|
+
nextState = microstep(enabledTransitions, nextState, actorScope, nextEvent, false, internalQueue);
|
|
1210
1213
|
shouldSelectEventlessTransitions = nextState !== previousState;
|
|
1211
1214
|
states.push(nextState);
|
|
1212
1215
|
}
|
|
1213
1216
|
if (nextState.status !== 'active') {
|
|
1214
|
-
stopChildren(nextState, nextEvent,
|
|
1217
|
+
stopChildren(nextState, nextEvent, actorScope);
|
|
1215
1218
|
}
|
|
1216
1219
|
return {
|
|
1217
1220
|
state: nextState,
|
|
1218
1221
|
microstates: states
|
|
1219
1222
|
};
|
|
1220
1223
|
}
|
|
1221
|
-
function stopChildren(nextState, event,
|
|
1222
|
-
return resolveActionsAndContext(nextState, event,
|
|
1224
|
+
function stopChildren(nextState, event, actorScope) {
|
|
1225
|
+
return resolveActionsAndContext(nextState, event, actorScope, Object.values(nextState.children).map(child => stop(child)), []);
|
|
1223
1226
|
}
|
|
1224
1227
|
function selectTransitions(event, nextState) {
|
|
1225
1228
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -1506,9 +1509,9 @@ function resolveRaise(_, state, args, actionParams, {
|
|
|
1506
1509
|
delay: resolvedDelay
|
|
1507
1510
|
}];
|
|
1508
1511
|
}
|
|
1509
|
-
function executeRaise(
|
|
1512
|
+
function executeRaise(actorScope, params) {
|
|
1510
1513
|
if (typeof params.delay === 'number') {
|
|
1511
|
-
|
|
1514
|
+
actorScope.self.delaySend(params);
|
|
1512
1515
|
return;
|
|
1513
1516
|
}
|
|
1514
1517
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { j as cloneState, e as evaluateGuard } from './raise-
|
|
2
|
-
import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, x as XSTATE_ERROR } from './interpreter-
|
|
1
|
+
import { j as cloneState, e as evaluateGuard } from './raise-62de3670.esm.js';
|
|
2
|
+
import { f as ActorStatus, j as createErrorActorEvent, r as resolveReferencedActor, d as createActor, t as toArray, x as XSTATE_ERROR } from './interpreter-1e8c1c0c.esm.js';
|
|
3
3
|
|
|
4
|
-
function createSpawner(
|
|
4
|
+
function createSpawner(actorScope, {
|
|
5
5
|
machine,
|
|
6
6
|
context
|
|
7
7
|
}, event, spawnedChildren) {
|
|
@@ -19,11 +19,11 @@ function createSpawner(actorContext, {
|
|
|
19
19
|
// TODO: this should also receive `src`
|
|
20
20
|
const actorRef = createActor(referenced.src, {
|
|
21
21
|
id: options.id,
|
|
22
|
-
parent:
|
|
22
|
+
parent: actorScope.self,
|
|
23
23
|
input: typeof input === 'function' ? input({
|
|
24
24
|
context,
|
|
25
25
|
event,
|
|
26
|
-
self:
|
|
26
|
+
self: actorScope.self
|
|
27
27
|
}) : input,
|
|
28
28
|
src,
|
|
29
29
|
systemId
|
|
@@ -33,7 +33,7 @@ function createSpawner(actorContext, {
|
|
|
33
33
|
actorRef.subscribe({
|
|
34
34
|
next: snapshot => {
|
|
35
35
|
if (snapshot.status === 'active') {
|
|
36
|
-
|
|
36
|
+
actorScope.self.send({
|
|
37
37
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
38
38
|
snapshot
|
|
39
39
|
});
|
|
@@ -47,7 +47,7 @@ function createSpawner(actorContext, {
|
|
|
47
47
|
// TODO: this should also receive `src`
|
|
48
48
|
const actorRef = createActor(src, {
|
|
49
49
|
id: options.id,
|
|
50
|
-
parent:
|
|
50
|
+
parent: actorScope.self,
|
|
51
51
|
input: options.input,
|
|
52
52
|
src: undefined,
|
|
53
53
|
systemId
|
|
@@ -56,7 +56,7 @@ function createSpawner(actorContext, {
|
|
|
56
56
|
actorRef.subscribe({
|
|
57
57
|
next: snapshot => {
|
|
58
58
|
if (snapshot.status === 'active') {
|
|
59
|
-
|
|
59
|
+
actorScope.self.send({
|
|
60
60
|
type: `xstate.snapshot.${actorRef.id}`,
|
|
61
61
|
snapshot,
|
|
62
62
|
id: actorRef.id
|
|
@@ -72,14 +72,14 @@ function createSpawner(actorContext, {
|
|
|
72
72
|
return (src, options) => {
|
|
73
73
|
const actorRef = spawn(src, options); // TODO: fix types
|
|
74
74
|
spawnedChildren[actorRef.id] = actorRef;
|
|
75
|
-
|
|
75
|
+
actorScope.defer(() => {
|
|
76
76
|
if (actorRef.status === ActorStatus.Stopped) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
try {
|
|
80
80
|
actorRef.start?.();
|
|
81
81
|
} catch (err) {
|
|
82
|
-
|
|
82
|
+
actorScope.self.send(createErrorActorEvent(actorRef.id, err));
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
});
|
|
@@ -87,7 +87,7 @@ function createSpawner(actorContext, {
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
function resolveAssign(
|
|
90
|
+
function resolveAssign(actorScope, state, actionArgs, actionParams, {
|
|
91
91
|
assignment
|
|
92
92
|
}) {
|
|
93
93
|
if (!state.context) {
|
|
@@ -97,9 +97,9 @@ function resolveAssign(actorContext, state, actionArgs, actionParams, {
|
|
|
97
97
|
const assignArgs = {
|
|
98
98
|
context: state.context,
|
|
99
99
|
event: actionArgs.event,
|
|
100
|
-
spawn: createSpawner(
|
|
101
|
-
self:
|
|
102
|
-
system:
|
|
100
|
+
spawn: createSpawner(actorScope, state, actionArgs.event, spawnedChildren),
|
|
101
|
+
self: actorScope?.self,
|
|
102
|
+
system: actorScope?.system
|
|
103
103
|
};
|
|
104
104
|
let partialUpdate = {};
|
|
105
105
|
if (typeof assignment === 'function') {
|
|
@@ -254,7 +254,7 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
|
|
|
254
254
|
return SpecialTargets;
|
|
255
255
|
}({});
|
|
256
256
|
|
|
257
|
-
function resolveSendTo(
|
|
257
|
+
function resolveSendTo(actorScope, state, args, actionParams, {
|
|
258
258
|
to,
|
|
259
259
|
event: eventOrExpr,
|
|
260
260
|
id,
|
|
@@ -276,9 +276,9 @@ function resolveSendTo(actorContext, state, args, actionParams, {
|
|
|
276
276
|
let targetActorRef;
|
|
277
277
|
if (typeof resolvedTarget === 'string') {
|
|
278
278
|
if (resolvedTarget === SpecialTargets.Parent) {
|
|
279
|
-
targetActorRef =
|
|
279
|
+
targetActorRef = actorScope?.self._parent;
|
|
280
280
|
} else if (resolvedTarget === SpecialTargets.Internal) {
|
|
281
|
-
targetActorRef =
|
|
281
|
+
targetActorRef = actorScope?.self;
|
|
282
282
|
} else if (resolvedTarget.startsWith('#_')) {
|
|
283
283
|
// SCXML compatibility: https://www.w3.org/TR/scxml/#SCXMLEventProcessor
|
|
284
284
|
// #_invokeid. If the target is the special term '#_invokeid', where invokeid is the invokeid of an SCXML session that the sending session has created by <invoke>, the Processor must add the event to the external queue of that session.
|
|
@@ -290,7 +290,7 @@ function resolveSendTo(actorContext, state, args, actionParams, {
|
|
|
290
290
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
|
|
291
291
|
}
|
|
292
292
|
} else {
|
|
293
|
-
targetActorRef = resolvedTarget ||
|
|
293
|
+
targetActorRef = resolvedTarget || actorScope?.self;
|
|
294
294
|
}
|
|
295
295
|
return [state, {
|
|
296
296
|
to: targetActorRef,
|
|
@@ -304,20 +304,20 @@ function retryResolveSendTo(_, state, params) {
|
|
|
304
304
|
params.to = state.children[params.to];
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
function executeSendTo(
|
|
307
|
+
function executeSendTo(actorScope, params) {
|
|
308
308
|
if (typeof params.delay === 'number') {
|
|
309
|
-
|
|
309
|
+
actorScope.self.delaySend(params);
|
|
310
310
|
return;
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
// this forms an outgoing events queue
|
|
314
314
|
// thanks to that the recipient actors are able to read the *updated* snapshot value of the sender
|
|
315
|
-
|
|
315
|
+
actorScope.defer(() => {
|
|
316
316
|
const {
|
|
317
317
|
to,
|
|
318
318
|
event
|
|
319
319
|
} = params;
|
|
320
|
-
|
|
320
|
+
actorScope?.system._relay(actorScope.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorScope.self.id, event.data) : event);
|
|
321
321
|
});
|
|
322
322
|
}
|
|
323
323
|
/**
|