xstate 5.0.0-beta.33 → 5.0.0-beta.34
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 +3 -3
- package/actors/dist/xstate-actors.development.cjs.js +3 -3
- package/actors/dist/xstate-actors.development.esm.js +3 -3
- package/actors/dist/xstate-actors.esm.js +3 -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/index.d.ts +1 -0
- package/dist/declarations/src/interpreter.d.ts +1 -1
- package/dist/declarations/src/stateUtils.d.ts +2 -2
- package/dist/{interpreter-054e9fb7.cjs.js → interpreter-1301970f.cjs.js} +8 -8
- package/dist/{interpreter-0c630f66.development.cjs.js → interpreter-70ed62f2.development.cjs.js} +8 -8
- package/dist/{interpreter-03737810.esm.js → interpreter-83f7f2d4.esm.js} +9 -9
- package/dist/{interpreter-825f3d6e.development.esm.js → interpreter-dee56dc8.development.esm.js} +9 -9
- package/dist/{raise-46f122aa.development.esm.js → raise-05f8b2a6.development.esm.js} +44 -27
- package/dist/{raise-987c242e.cjs.js → raise-1dd65455.cjs.js} +44 -27
- package/dist/{raise-4c6a5a96.development.cjs.js → raise-38b707c0.development.cjs.js} +44 -27
- package/dist/{raise-2d92eae8.esm.js → raise-b5cfe1bb.esm.js} +44 -27
- package/dist/{send-0edee2b4.esm.js → send-0b5eda0c.esm.js} +14 -8
- package/dist/{send-0e8675c8.development.cjs.js → send-3764c866.development.cjs.js} +14 -8
- package/dist/{send-4d5b92dc.development.esm.js → send-9526366e.development.esm.js} +14 -8
- package/dist/{send-bd1bd0e3.cjs.js → send-fe94de2b.cjs.js} +14 -8
- package/dist/xstate.cjs.js +5 -5
- package/dist/xstate.development.cjs.js +5 -5
- package/dist/xstate.development.esm.js +8 -8
- package/dist/xstate.esm.js +8 -8
- 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
|
@@ -557,7 +557,7 @@ class Actor {
|
|
|
557
557
|
const status = this._state.status;
|
|
558
558
|
switch (status) {
|
|
559
559
|
case 'done':
|
|
560
|
-
// a state machine can be "done" upon
|
|
560
|
+
// a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
|
|
561
561
|
// we still need to complete observers, flush deferreds etc
|
|
562
562
|
this.update(this._state, initEvent);
|
|
563
563
|
// fallthrough
|
|
@@ -712,14 +712,14 @@ class Actor {
|
|
|
712
712
|
}
|
|
713
713
|
|
|
714
714
|
// TODO: make private (and figure out a way to do this within the machine)
|
|
715
|
-
delaySend({
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
715
|
+
delaySend(params) {
|
|
716
|
+
const {
|
|
717
|
+
event,
|
|
718
|
+
id,
|
|
719
|
+
delay
|
|
720
|
+
} = params;
|
|
721
721
|
const timerId = this.clock.setTimeout(() => {
|
|
722
|
-
this.system._relay(this, to ?? this, event);
|
|
722
|
+
this.system._relay(this, params.to ?? this, event);
|
|
723
723
|
}, delay);
|
|
724
724
|
|
|
725
725
|
// TODO: consider the rehydration story here
|
|
@@ -781,4 +781,4 @@ const interpret = createActor;
|
|
|
781
781
|
* @deprecated Use `Actor` instead.
|
|
782
782
|
*/
|
|
783
783
|
|
|
784
|
-
export { Actor as A, InterpreterStatus as I, NULL_EVENT as N, STATE_DELIMITER as S, WILDCARD as W,
|
|
784
|
+
export { Actor as A, InterpreterStatus as I, NULL_EVENT as N, STATE_DELIMITER as S, WILDCARD as W, XSTATE_STOP as X, toTransitionConfigArray as a, createInitEvent as b, createInvokeId as c, createActor as d, matchesState as e, ActorStatus as f, interpret as g, toObserver as h, isErrorActorEvent as i, createErrorActorEvent as j, toStateValue as k, STATE_IDENTIFIER as l, mapValues as m, normalizeTarget as n, toStatePath as o, pathToStateValue as p, createDoneStateEvent as q, resolveReferencedActor as r, resolveOutput as s, toArray as t, XSTATE_INIT as u, isArray as v, createAfterEvent as w, flatten as x, XSTATE_ERROR as y };
|
package/dist/{interpreter-825f3d6e.development.esm.js → interpreter-dee56dc8.development.esm.js}
RENAMED
|
@@ -560,7 +560,7 @@ class Actor {
|
|
|
560
560
|
const status = this._state.status;
|
|
561
561
|
switch (status) {
|
|
562
562
|
case 'done':
|
|
563
|
-
// a state machine can be "done" upon
|
|
563
|
+
// a state machine can be "done" upon initialization (it could reach a final state using initial microsteps)
|
|
564
564
|
// we still need to complete observers, flush deferreds etc
|
|
565
565
|
this.update(this._state, initEvent);
|
|
566
566
|
// fallthrough
|
|
@@ -723,14 +723,14 @@ class Actor {
|
|
|
723
723
|
}
|
|
724
724
|
|
|
725
725
|
// TODO: make private (and figure out a way to do this within the machine)
|
|
726
|
-
delaySend({
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
726
|
+
delaySend(params) {
|
|
727
|
+
const {
|
|
728
|
+
event,
|
|
729
|
+
id,
|
|
730
|
+
delay
|
|
731
|
+
} = params;
|
|
732
732
|
const timerId = this.clock.setTimeout(() => {
|
|
733
|
-
this.system._relay(this, to ?? this, event);
|
|
733
|
+
this.system._relay(this, params.to ?? this, event);
|
|
734
734
|
}, delay);
|
|
735
735
|
|
|
736
736
|
// TODO: consider the rehydration story here
|
|
@@ -792,4 +792,4 @@ const interpret = createActor;
|
|
|
792
792
|
* @deprecated Use `Actor` instead.
|
|
793
793
|
*/
|
|
794
794
|
|
|
795
|
-
export { Actor as A, InterpreterStatus as I, NULL_EVENT as N, STATE_DELIMITER as S, WILDCARD as W,
|
|
795
|
+
export { Actor as A, InterpreterStatus as I, NULL_EVENT as N, STATE_DELIMITER as S, WILDCARD as W, XSTATE_STOP as X, toTransitionConfigArray as a, createInitEvent as b, createInvokeId as c, createActor as d, matchesState as e, ActorStatus as f, interpret as g, toObserver as h, isErrorActorEvent as i, createErrorActorEvent as j, toStateValue as k, STATE_IDENTIFIER as l, mapValues as m, normalizeTarget as n, toStatePath as o, pathToStateValue as p, createDoneStateEvent as q, resolveReferencedActor as r, resolveOutput as s, toArray as t, XSTATE_INIT as u, isArray as v, createAfterEvent as w, flatten as x, XSTATE_ERROR as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as resolveReferencedActor, d as createActor, f as ActorStatus,
|
|
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 isArray, w as createAfterEvent, x as flatten, e as matchesState } from './interpreter-dee56dc8.development.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -916,31 +916,33 @@ function microstep(transitions, currentState, actorCtx, event, isInitial) {
|
|
|
916
916
|
}
|
|
917
917
|
|
|
918
918
|
function microstepProcedure(transitions, currentState, mutConfiguration, event, actorCtx, isInitial) {
|
|
919
|
-
const actions = [];
|
|
920
919
|
const historyValue = {
|
|
921
920
|
...currentState.historyValue
|
|
922
921
|
};
|
|
923
922
|
const filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
|
|
924
923
|
const internalQueue = [...currentState._internalQueue];
|
|
924
|
+
// TODO: this `cloneState` is really just a hack to prevent infinite loops
|
|
925
|
+
// we need to take another look at how internal queue is managed
|
|
926
|
+
let nextState = cloneState(currentState, {
|
|
927
|
+
_internalQueue: []
|
|
928
|
+
});
|
|
925
929
|
|
|
926
930
|
// Exit states
|
|
927
931
|
if (!isInitial) {
|
|
928
|
-
exitStates(filteredTransitions, mutConfiguration, historyValue
|
|
932
|
+
nextState = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue);
|
|
929
933
|
}
|
|
930
934
|
|
|
931
935
|
// Execute transition content
|
|
932
|
-
|
|
936
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions));
|
|
933
937
|
|
|
934
938
|
// Enter states
|
|
935
|
-
enterStates(event, filteredTransitions, mutConfiguration,
|
|
939
|
+
nextState = enterStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
|
|
936
940
|
const nextConfiguration = [...mutConfiguration];
|
|
937
941
|
const done = isInFinalState(nextConfiguration);
|
|
938
942
|
if (done) {
|
|
939
|
-
|
|
940
|
-
actions.push(...finalActions);
|
|
943
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit));
|
|
941
944
|
}
|
|
942
945
|
try {
|
|
943
|
-
const nextState = resolveActionsAndContext(actions, event, currentState, actorCtx);
|
|
944
946
|
const output = done ? getOutput(nextConfiguration, nextState.context, event, actorCtx.self) : undefined;
|
|
945
947
|
internalQueue.push(...nextState._internalQueue);
|
|
946
948
|
return cloneState(currentState, {
|
|
@@ -958,7 +960,8 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
958
960
|
throw e;
|
|
959
961
|
}
|
|
960
962
|
}
|
|
961
|
-
function enterStates(event, filteredTransitions, mutConfiguration,
|
|
963
|
+
function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
|
|
964
|
+
let nextState = currentState;
|
|
962
965
|
const statesToEnter = new Set();
|
|
963
966
|
const statesForDefaultEntry = new Set();
|
|
964
967
|
computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
|
|
@@ -969,24 +972,26 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
969
972
|
}
|
|
970
973
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
971
974
|
mutConfiguration.add(stateNodeToEnter);
|
|
972
|
-
|
|
973
|
-
actions.push(invoke(invokeDef));
|
|
974
|
-
}
|
|
975
|
+
const actions = [];
|
|
975
976
|
|
|
976
977
|
// Add entry actions
|
|
977
978
|
actions.push(...stateNodeToEnter.entry);
|
|
979
|
+
for (const invokeDef of stateNodeToEnter.invoke) {
|
|
980
|
+
actions.push(invoke(invokeDef));
|
|
981
|
+
}
|
|
978
982
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
979
983
|
for (const stateNode of statesForDefaultEntry) {
|
|
980
984
|
const initialActions = stateNode.initial.actions;
|
|
981
985
|
actions.push(...initialActions);
|
|
982
986
|
}
|
|
983
987
|
}
|
|
988
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
|
|
984
989
|
if (stateNodeToEnter.type === 'final') {
|
|
985
990
|
const parent = stateNodeToEnter.parent;
|
|
986
991
|
if (!parent.parent) {
|
|
987
992
|
continue;
|
|
988
993
|
}
|
|
989
|
-
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output,
|
|
994
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
|
|
990
995
|
if (parent.parent) {
|
|
991
996
|
const grandparent = parent.parent;
|
|
992
997
|
if (grandparent.type === 'parallel') {
|
|
@@ -997,6 +1002,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
997
1002
|
}
|
|
998
1003
|
}
|
|
999
1004
|
}
|
|
1005
|
+
return nextState;
|
|
1000
1006
|
}
|
|
1001
1007
|
function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
|
|
1002
1008
|
for (const t of transitions) {
|
|
@@ -1070,7 +1076,8 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
|
|
|
1070
1076
|
}
|
|
1071
1077
|
}
|
|
1072
1078
|
}
|
|
1073
|
-
function exitStates(transitions, mutConfiguration, historyValue
|
|
1079
|
+
function exitStates(currentState, event, actorCtx, transitions, mutConfiguration, historyValue) {
|
|
1080
|
+
let nextState = currentState;
|
|
1074
1081
|
const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
|
|
1075
1082
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
1076
1083
|
|
|
@@ -1089,19 +1096,16 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
|
|
|
1089
1096
|
}
|
|
1090
1097
|
}
|
|
1091
1098
|
for (const s of statesToExit) {
|
|
1092
|
-
|
|
1099
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, [...s.exit, ...s.invoke.map(def => stop(def.id))]);
|
|
1093
1100
|
mutConfiguration.delete(s);
|
|
1094
1101
|
}
|
|
1102
|
+
return nextState;
|
|
1095
1103
|
}
|
|
1096
|
-
function
|
|
1104
|
+
function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
|
|
1097
1105
|
const {
|
|
1098
1106
|
machine
|
|
1099
1107
|
} = currentState;
|
|
1100
|
-
|
|
1101
|
-
// we need to take another look at how internal queue is managed
|
|
1102
|
-
let intermediateState = cloneState(currentState, {
|
|
1103
|
-
_internalQueue: []
|
|
1104
|
-
});
|
|
1108
|
+
let intermediateState = currentState;
|
|
1105
1109
|
for (const action of actions) {
|
|
1106
1110
|
const isInline = typeof action === 'function';
|
|
1107
1111
|
const resolvedAction = isInline ? action :
|
|
@@ -1140,11 +1144,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1140
1144
|
continue;
|
|
1141
1145
|
}
|
|
1142
1146
|
const builtinAction = resolvedAction;
|
|
1143
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction
|
|
1144
|
-
|
|
1145
|
-
|
|
1147
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction,
|
|
1148
|
+
// this holds all params
|
|
1149
|
+
extra);
|
|
1146
1150
|
intermediateState = nextState;
|
|
1147
|
-
if ('
|
|
1151
|
+
if ('retryResolve' in builtinAction) {
|
|
1152
|
+
retries?.push([builtinAction, params]);
|
|
1153
|
+
}
|
|
1154
|
+
if ('execute' in builtinAction) {
|
|
1148
1155
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
1149
1156
|
builtinAction.execute(actorCtx, params);
|
|
1150
1157
|
} else {
|
|
@@ -1152,11 +1159,21 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1152
1159
|
}
|
|
1153
1160
|
}
|
|
1154
1161
|
if (actions) {
|
|
1155
|
-
intermediateState =
|
|
1162
|
+
intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
|
|
1156
1163
|
}
|
|
1157
1164
|
}
|
|
1158
1165
|
return intermediateState;
|
|
1159
1166
|
}
|
|
1167
|
+
function resolveActionsAndContext(currentState, event, actorCtx, actions, deferredActorIds) {
|
|
1168
|
+
const retries = deferredActorIds ? [] : undefined;
|
|
1169
|
+
const nextState = resolveActionsAndContextWorker(currentState, event, actorCtx, actions, deferredActorIds && {
|
|
1170
|
+
deferredActorIds
|
|
1171
|
+
}, retries);
|
|
1172
|
+
retries?.forEach(([builtinAction, params]) => {
|
|
1173
|
+
builtinAction.retryResolve(actorCtx, nextState, params);
|
|
1174
|
+
});
|
|
1175
|
+
return nextState;
|
|
1176
|
+
}
|
|
1160
1177
|
function macrostep(state, event, actorCtx) {
|
|
1161
1178
|
if (event.type === WILDCARD) {
|
|
1162
1179
|
throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
|
|
@@ -1216,7 +1233,7 @@ function stopStep(event, nextState, actorCtx) {
|
|
|
1216
1233
|
for (const child of Object.values(nextState.children)) {
|
|
1217
1234
|
actions.push(stop(child));
|
|
1218
1235
|
}
|
|
1219
|
-
return resolveActionsAndContext(
|
|
1236
|
+
return resolveActionsAndContext(nextState, event, actorCtx, actions);
|
|
1220
1237
|
}
|
|
1221
1238
|
function selectTransitions(event, nextState) {
|
|
1222
1239
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var interpreter = require('./interpreter-1301970f.cjs.js');
|
|
4
4
|
|
|
5
5
|
const cache = new WeakMap();
|
|
6
6
|
function memo(object, key, fn) {
|
|
@@ -887,31 +887,33 @@ function microstep(transitions, currentState, actorCtx, event, isInitial) {
|
|
|
887
887
|
}
|
|
888
888
|
|
|
889
889
|
function microstepProcedure(transitions, currentState, mutConfiguration, event, actorCtx, isInitial) {
|
|
890
|
-
const actions = [];
|
|
891
890
|
const historyValue = {
|
|
892
891
|
...currentState.historyValue
|
|
893
892
|
};
|
|
894
893
|
const filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
|
|
895
894
|
const internalQueue = [...currentState._internalQueue];
|
|
895
|
+
// TODO: this `cloneState` is really just a hack to prevent infinite loops
|
|
896
|
+
// we need to take another look at how internal queue is managed
|
|
897
|
+
let nextState = cloneState(currentState, {
|
|
898
|
+
_internalQueue: []
|
|
899
|
+
});
|
|
896
900
|
|
|
897
901
|
// Exit states
|
|
898
902
|
if (!isInitial) {
|
|
899
|
-
exitStates(filteredTransitions, mutConfiguration, historyValue
|
|
903
|
+
nextState = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue);
|
|
900
904
|
}
|
|
901
905
|
|
|
902
906
|
// Execute transition content
|
|
903
|
-
|
|
907
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions));
|
|
904
908
|
|
|
905
909
|
// Enter states
|
|
906
|
-
enterStates(event, filteredTransitions, mutConfiguration,
|
|
910
|
+
nextState = enterStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
|
|
907
911
|
const nextConfiguration = [...mutConfiguration];
|
|
908
912
|
const done = isInFinalState(nextConfiguration);
|
|
909
913
|
if (done) {
|
|
910
|
-
|
|
911
|
-
actions.push(...finalActions);
|
|
914
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit));
|
|
912
915
|
}
|
|
913
916
|
try {
|
|
914
|
-
const nextState = resolveActionsAndContext(actions, event, currentState, actorCtx);
|
|
915
917
|
const output = done ? getOutput(nextConfiguration, nextState.context, event, actorCtx.self) : undefined;
|
|
916
918
|
internalQueue.push(...nextState._internalQueue);
|
|
917
919
|
return cloneState(currentState, {
|
|
@@ -929,7 +931,8 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
929
931
|
throw e;
|
|
930
932
|
}
|
|
931
933
|
}
|
|
932
|
-
function enterStates(event, filteredTransitions, mutConfiguration,
|
|
934
|
+
function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
|
|
935
|
+
let nextState = currentState;
|
|
933
936
|
const statesToEnter = new Set();
|
|
934
937
|
const statesForDefaultEntry = new Set();
|
|
935
938
|
computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
|
|
@@ -940,24 +943,26 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
940
943
|
}
|
|
941
944
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
942
945
|
mutConfiguration.add(stateNodeToEnter);
|
|
943
|
-
|
|
944
|
-
actions.push(invoke(invokeDef));
|
|
945
|
-
}
|
|
946
|
+
const actions = [];
|
|
946
947
|
|
|
947
948
|
// Add entry actions
|
|
948
949
|
actions.push(...stateNodeToEnter.entry);
|
|
950
|
+
for (const invokeDef of stateNodeToEnter.invoke) {
|
|
951
|
+
actions.push(invoke(invokeDef));
|
|
952
|
+
}
|
|
949
953
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
950
954
|
for (const stateNode of statesForDefaultEntry) {
|
|
951
955
|
const initialActions = stateNode.initial.actions;
|
|
952
956
|
actions.push(...initialActions);
|
|
953
957
|
}
|
|
954
958
|
}
|
|
959
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
|
|
955
960
|
if (stateNodeToEnter.type === 'final') {
|
|
956
961
|
const parent = stateNodeToEnter.parent;
|
|
957
962
|
if (!parent.parent) {
|
|
958
963
|
continue;
|
|
959
964
|
}
|
|
960
|
-
internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output,
|
|
965
|
+
internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
|
|
961
966
|
if (parent.parent) {
|
|
962
967
|
const grandparent = parent.parent;
|
|
963
968
|
if (grandparent.type === 'parallel') {
|
|
@@ -968,6 +973,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
968
973
|
}
|
|
969
974
|
}
|
|
970
975
|
}
|
|
976
|
+
return nextState;
|
|
971
977
|
}
|
|
972
978
|
function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
|
|
973
979
|
for (const t of transitions) {
|
|
@@ -1041,7 +1047,8 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
|
|
|
1041
1047
|
}
|
|
1042
1048
|
}
|
|
1043
1049
|
}
|
|
1044
|
-
function exitStates(transitions, mutConfiguration, historyValue
|
|
1050
|
+
function exitStates(currentState, event, actorCtx, transitions, mutConfiguration, historyValue) {
|
|
1051
|
+
let nextState = currentState;
|
|
1045
1052
|
const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
|
|
1046
1053
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
1047
1054
|
|
|
@@ -1060,19 +1067,16 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
|
|
|
1060
1067
|
}
|
|
1061
1068
|
}
|
|
1062
1069
|
for (const s of statesToExit) {
|
|
1063
|
-
|
|
1070
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, [...s.exit, ...s.invoke.map(def => stop(def.id))]);
|
|
1064
1071
|
mutConfiguration.delete(s);
|
|
1065
1072
|
}
|
|
1073
|
+
return nextState;
|
|
1066
1074
|
}
|
|
1067
|
-
function
|
|
1075
|
+
function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
|
|
1068
1076
|
const {
|
|
1069
1077
|
machine
|
|
1070
1078
|
} = currentState;
|
|
1071
|
-
|
|
1072
|
-
// we need to take another look at how internal queue is managed
|
|
1073
|
-
let intermediateState = cloneState(currentState, {
|
|
1074
|
-
_internalQueue: []
|
|
1075
|
-
});
|
|
1079
|
+
let intermediateState = currentState;
|
|
1076
1080
|
for (const action of actions) {
|
|
1077
1081
|
const isInline = typeof action === 'function';
|
|
1078
1082
|
const resolvedAction = isInline ? action :
|
|
@@ -1111,11 +1115,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1111
1115
|
continue;
|
|
1112
1116
|
}
|
|
1113
1117
|
const builtinAction = resolvedAction;
|
|
1114
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction
|
|
1115
|
-
|
|
1116
|
-
|
|
1118
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction,
|
|
1119
|
+
// this holds all params
|
|
1120
|
+
extra);
|
|
1117
1121
|
intermediateState = nextState;
|
|
1118
|
-
if ('
|
|
1122
|
+
if ('retryResolve' in builtinAction) {
|
|
1123
|
+
retries?.push([builtinAction, params]);
|
|
1124
|
+
}
|
|
1125
|
+
if ('execute' in builtinAction) {
|
|
1119
1126
|
if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
|
|
1120
1127
|
builtinAction.execute(actorCtx, params);
|
|
1121
1128
|
} else {
|
|
@@ -1123,11 +1130,21 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1123
1130
|
}
|
|
1124
1131
|
}
|
|
1125
1132
|
if (actions) {
|
|
1126
|
-
intermediateState =
|
|
1133
|
+
intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
|
|
1127
1134
|
}
|
|
1128
1135
|
}
|
|
1129
1136
|
return intermediateState;
|
|
1130
1137
|
}
|
|
1138
|
+
function resolveActionsAndContext(currentState, event, actorCtx, actions, deferredActorIds) {
|
|
1139
|
+
const retries = deferredActorIds ? [] : undefined;
|
|
1140
|
+
const nextState = resolveActionsAndContextWorker(currentState, event, actorCtx, actions, deferredActorIds && {
|
|
1141
|
+
deferredActorIds
|
|
1142
|
+
}, retries);
|
|
1143
|
+
retries?.forEach(([builtinAction, params]) => {
|
|
1144
|
+
builtinAction.retryResolve(actorCtx, nextState, params);
|
|
1145
|
+
});
|
|
1146
|
+
return nextState;
|
|
1147
|
+
}
|
|
1131
1148
|
function macrostep(state, event, actorCtx) {
|
|
1132
1149
|
let nextState = state;
|
|
1133
1150
|
const states = [];
|
|
@@ -1184,7 +1201,7 @@ function stopStep(event, nextState, actorCtx) {
|
|
|
1184
1201
|
for (const child of Object.values(nextState.children)) {
|
|
1185
1202
|
actions.push(stop(child));
|
|
1186
1203
|
}
|
|
1187
|
-
return resolveActionsAndContext(
|
|
1204
|
+
return resolveActionsAndContext(nextState, event, actorCtx, actions);
|
|
1188
1205
|
}
|
|
1189
1206
|
function selectTransitions(event, nextState) {
|
|
1190
1207
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var interpreter = require('./interpreter-70ed62f2.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
const cache = new WeakMap();
|
|
6
6
|
function memo(object, key, fn) {
|
|
@@ -918,31 +918,33 @@ function microstep(transitions, currentState, actorCtx, event, isInitial) {
|
|
|
918
918
|
}
|
|
919
919
|
|
|
920
920
|
function microstepProcedure(transitions, currentState, mutConfiguration, event, actorCtx, isInitial) {
|
|
921
|
-
const actions = [];
|
|
922
921
|
const historyValue = {
|
|
923
922
|
...currentState.historyValue
|
|
924
923
|
};
|
|
925
924
|
const filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
|
|
926
925
|
const internalQueue = [...currentState._internalQueue];
|
|
926
|
+
// TODO: this `cloneState` is really just a hack to prevent infinite loops
|
|
927
|
+
// we need to take another look at how internal queue is managed
|
|
928
|
+
let nextState = cloneState(currentState, {
|
|
929
|
+
_internalQueue: []
|
|
930
|
+
});
|
|
927
931
|
|
|
928
932
|
// Exit states
|
|
929
933
|
if (!isInitial) {
|
|
930
|
-
exitStates(filteredTransitions, mutConfiguration, historyValue
|
|
934
|
+
nextState = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue);
|
|
931
935
|
}
|
|
932
936
|
|
|
933
937
|
// Execute transition content
|
|
934
|
-
|
|
938
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions));
|
|
935
939
|
|
|
936
940
|
// Enter states
|
|
937
|
-
enterStates(event, filteredTransitions, mutConfiguration,
|
|
941
|
+
nextState = enterStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
|
|
938
942
|
const nextConfiguration = [...mutConfiguration];
|
|
939
943
|
const done = isInFinalState(nextConfiguration);
|
|
940
944
|
if (done) {
|
|
941
|
-
|
|
942
|
-
actions.push(...finalActions);
|
|
945
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit));
|
|
943
946
|
}
|
|
944
947
|
try {
|
|
945
|
-
const nextState = resolveActionsAndContext(actions, event, currentState, actorCtx);
|
|
946
948
|
const output = done ? getOutput(nextConfiguration, nextState.context, event, actorCtx.self) : undefined;
|
|
947
949
|
internalQueue.push(...nextState._internalQueue);
|
|
948
950
|
return cloneState(currentState, {
|
|
@@ -960,7 +962,8 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
960
962
|
throw e;
|
|
961
963
|
}
|
|
962
964
|
}
|
|
963
|
-
function enterStates(event, filteredTransitions, mutConfiguration,
|
|
965
|
+
function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
|
|
966
|
+
let nextState = currentState;
|
|
964
967
|
const statesToEnter = new Set();
|
|
965
968
|
const statesForDefaultEntry = new Set();
|
|
966
969
|
computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
|
|
@@ -971,24 +974,26 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
971
974
|
}
|
|
972
975
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
973
976
|
mutConfiguration.add(stateNodeToEnter);
|
|
974
|
-
|
|
975
|
-
actions.push(invoke(invokeDef));
|
|
976
|
-
}
|
|
977
|
+
const actions = [];
|
|
977
978
|
|
|
978
979
|
// Add entry actions
|
|
979
980
|
actions.push(...stateNodeToEnter.entry);
|
|
981
|
+
for (const invokeDef of stateNodeToEnter.invoke) {
|
|
982
|
+
actions.push(invoke(invokeDef));
|
|
983
|
+
}
|
|
980
984
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
981
985
|
for (const stateNode of statesForDefaultEntry) {
|
|
982
986
|
const initialActions = stateNode.initial.actions;
|
|
983
987
|
actions.push(...initialActions);
|
|
984
988
|
}
|
|
985
989
|
}
|
|
990
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
|
|
986
991
|
if (stateNodeToEnter.type === 'final') {
|
|
987
992
|
const parent = stateNodeToEnter.parent;
|
|
988
993
|
if (!parent.parent) {
|
|
989
994
|
continue;
|
|
990
995
|
}
|
|
991
|
-
internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output,
|
|
996
|
+
internalQueue.push(interpreter.createDoneStateEvent(parent.id, stateNodeToEnter.output ? interpreter.resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
|
|
992
997
|
if (parent.parent) {
|
|
993
998
|
const grandparent = parent.parent;
|
|
994
999
|
if (grandparent.type === 'parallel') {
|
|
@@ -999,6 +1004,7 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
999
1004
|
}
|
|
1000
1005
|
}
|
|
1001
1006
|
}
|
|
1007
|
+
return nextState;
|
|
1002
1008
|
}
|
|
1003
1009
|
function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
|
|
1004
1010
|
for (const t of transitions) {
|
|
@@ -1072,7 +1078,8 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
|
|
|
1072
1078
|
}
|
|
1073
1079
|
}
|
|
1074
1080
|
}
|
|
1075
|
-
function exitStates(transitions, mutConfiguration, historyValue
|
|
1081
|
+
function exitStates(currentState, event, actorCtx, transitions, mutConfiguration, historyValue) {
|
|
1082
|
+
let nextState = currentState;
|
|
1076
1083
|
const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
|
|
1077
1084
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
1078
1085
|
|
|
@@ -1091,19 +1098,16 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
|
|
|
1091
1098
|
}
|
|
1092
1099
|
}
|
|
1093
1100
|
for (const s of statesToExit) {
|
|
1094
|
-
|
|
1101
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, [...s.exit, ...s.invoke.map(def => stop(def.id))]);
|
|
1095
1102
|
mutConfiguration.delete(s);
|
|
1096
1103
|
}
|
|
1104
|
+
return nextState;
|
|
1097
1105
|
}
|
|
1098
|
-
function
|
|
1106
|
+
function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
|
|
1099
1107
|
const {
|
|
1100
1108
|
machine
|
|
1101
1109
|
} = currentState;
|
|
1102
|
-
|
|
1103
|
-
// we need to take another look at how internal queue is managed
|
|
1104
|
-
let intermediateState = cloneState(currentState, {
|
|
1105
|
-
_internalQueue: []
|
|
1106
|
-
});
|
|
1110
|
+
let intermediateState = currentState;
|
|
1107
1111
|
for (const action of actions) {
|
|
1108
1112
|
const isInline = typeof action === 'function';
|
|
1109
1113
|
const resolvedAction = isInline ? action :
|
|
@@ -1142,11 +1146,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1142
1146
|
continue;
|
|
1143
1147
|
}
|
|
1144
1148
|
const builtinAction = resolvedAction;
|
|
1145
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction
|
|
1146
|
-
|
|
1147
|
-
|
|
1149
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction,
|
|
1150
|
+
// this holds all params
|
|
1151
|
+
extra);
|
|
1148
1152
|
intermediateState = nextState;
|
|
1149
|
-
if ('
|
|
1153
|
+
if ('retryResolve' in builtinAction) {
|
|
1154
|
+
retries?.push([builtinAction, params]);
|
|
1155
|
+
}
|
|
1156
|
+
if ('execute' in builtinAction) {
|
|
1150
1157
|
if (actorCtx?.self.status === interpreter.ActorStatus.Running) {
|
|
1151
1158
|
builtinAction.execute(actorCtx, params);
|
|
1152
1159
|
} else {
|
|
@@ -1154,11 +1161,21 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1154
1161
|
}
|
|
1155
1162
|
}
|
|
1156
1163
|
if (actions) {
|
|
1157
|
-
intermediateState =
|
|
1164
|
+
intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
|
|
1158
1165
|
}
|
|
1159
1166
|
}
|
|
1160
1167
|
return intermediateState;
|
|
1161
1168
|
}
|
|
1169
|
+
function resolveActionsAndContext(currentState, event, actorCtx, actions, deferredActorIds) {
|
|
1170
|
+
const retries = deferredActorIds ? [] : undefined;
|
|
1171
|
+
const nextState = resolveActionsAndContextWorker(currentState, event, actorCtx, actions, deferredActorIds && {
|
|
1172
|
+
deferredActorIds
|
|
1173
|
+
}, retries);
|
|
1174
|
+
retries?.forEach(([builtinAction, params]) => {
|
|
1175
|
+
builtinAction.retryResolve(actorCtx, nextState, params);
|
|
1176
|
+
});
|
|
1177
|
+
return nextState;
|
|
1178
|
+
}
|
|
1162
1179
|
function macrostep(state, event, actorCtx) {
|
|
1163
1180
|
if (event.type === interpreter.WILDCARD) {
|
|
1164
1181
|
throw new Error(`An event cannot have the wildcard type ('${interpreter.WILDCARD}')`);
|
|
@@ -1218,7 +1235,7 @@ function stopStep(event, nextState, actorCtx) {
|
|
|
1218
1235
|
for (const child of Object.values(nextState.children)) {
|
|
1219
1236
|
actions.push(stop(child));
|
|
1220
1237
|
}
|
|
1221
|
-
return resolveActionsAndContext(
|
|
1238
|
+
return resolveActionsAndContext(nextState, event, actorCtx, actions);
|
|
1222
1239
|
}
|
|
1223
1240
|
function selectTransitions(event, nextState) {
|
|
1224
1241
|
return nextState.machine.getTransitionData(nextState, event);
|