xstate 5.0.0-beta.33 → 5.0.0-beta.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- 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 +3 -1
- package/dist/declarations/src/stateUtils.d.ts +6 -5
- package/dist/declarations/src/types.d.ts +3 -5
- package/dist/{interpreter-825f3d6e.development.esm.js → interpreter-5c4e6634.development.esm.js} +67 -65
- package/dist/{interpreter-054e9fb7.cjs.js → interpreter-69605bf0.cjs.js} +67 -65
- package/dist/{interpreter-0c630f66.development.cjs.js → interpreter-d3567419.development.cjs.js} +67 -65
- package/dist/{interpreter-03737810.esm.js → interpreter-de5217bc.esm.js} +67 -65
- package/dist/{raise-987c242e.cjs.js → raise-0ff57677.cjs.js} +142 -124
- package/dist/{raise-4c6a5a96.development.cjs.js → raise-26e4d83c.development.cjs.js} +145 -124
- package/dist/{raise-2d92eae8.esm.js → raise-511399cc.esm.js} +142 -124
- package/dist/{raise-46f122aa.development.esm.js → raise-cdcdf834.development.esm.js} +145 -124
- package/dist/{send-bd1bd0e3.cjs.js → send-19ffc568.cjs.js} +16 -8
- package/dist/{send-4d5b92dc.development.esm.js → send-1de74f4d.development.esm.js} +16 -8
- package/dist/{send-0edee2b4.esm.js → send-211a2a94.esm.js} +16 -8
- package/dist/{send-0e8675c8.development.cjs.js → send-894c4b18.development.cjs.js} +16 -8
- package/dist/xstate.cjs.js +28 -9
- package/dist/xstate.development.cjs.js +28 -9
- package/dist/xstate.development.esm.js +31 -12
- package/dist/xstate.esm.js +31 -12
- 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,
|
|
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-5c4e6634.development.esm.js';
|
|
2
2
|
|
|
3
3
|
const cache = new WeakMap();
|
|
4
4
|
function memo(object, key, fn) {
|
|
@@ -297,20 +297,6 @@ function evaluateGuard(guard, context, event, state) {
|
|
|
297
297
|
);
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
function getOutput(configuration, context, event, self) {
|
|
301
|
-
const {
|
|
302
|
-
machine
|
|
303
|
-
} = configuration[0];
|
|
304
|
-
const {
|
|
305
|
-
root
|
|
306
|
-
} = machine;
|
|
307
|
-
if (!root.output) {
|
|
308
|
-
return undefined;
|
|
309
|
-
}
|
|
310
|
-
const finalChildStateNode = configuration.find(stateNode => stateNode.type === 'final' && stateNode.parent === machine.root);
|
|
311
|
-
const doneStateEvent = createDoneStateEvent(finalChildStateNode.id, finalChildStateNode.output ? resolveOutput(finalChildStateNode.output, context, event, self) : undefined);
|
|
312
|
-
return resolveOutput(root.output, context, doneStateEvent, self);
|
|
313
|
-
}
|
|
314
300
|
const isAtomicStateNode = stateNode => stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
315
301
|
function getChildren(stateNode) {
|
|
316
302
|
return Object.values(stateNode.states).filter(sn => sn.type !== 'history');
|
|
@@ -335,7 +321,7 @@ function getConfiguration(stateNodes) {
|
|
|
335
321
|
for (const s of configuration) {
|
|
336
322
|
// if previously active, add existing child nodes
|
|
337
323
|
if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
|
|
338
|
-
|
|
324
|
+
getInitialStateNodesWithTheirAncestors(s).forEach(sn => configurationSet.add(sn));
|
|
339
325
|
} else {
|
|
340
326
|
if (s.type === 'parallel') {
|
|
341
327
|
for (const child of getChildren(s)) {
|
|
@@ -343,7 +329,8 @@ function getConfiguration(stateNodes) {
|
|
|
343
329
|
continue;
|
|
344
330
|
}
|
|
345
331
|
if (!configurationSet.has(child)) {
|
|
346
|
-
|
|
332
|
+
const initialStates = getInitialStateNodesWithTheirAncestors(child);
|
|
333
|
+
for (const initialStateNode of initialStates) {
|
|
347
334
|
configurationSet.add(initialStateNode);
|
|
348
335
|
}
|
|
349
336
|
}
|
|
@@ -403,14 +390,14 @@ function getStateValue(rootNode, configuration) {
|
|
|
403
390
|
const config = getConfiguration(configuration);
|
|
404
391
|
return getValueFromAdj(rootNode, getAdjList(config));
|
|
405
392
|
}
|
|
406
|
-
function isInFinalState(configuration, stateNode
|
|
393
|
+
function isInFinalState(configuration, stateNode) {
|
|
407
394
|
if (stateNode.type === 'compound') {
|
|
408
|
-
return getChildren(stateNode).some(s => s.type === 'final' && configuration.
|
|
395
|
+
return getChildren(stateNode).some(s => s.type === 'final' && configuration.has(s));
|
|
409
396
|
}
|
|
410
397
|
if (stateNode.type === 'parallel') {
|
|
411
398
|
return getChildren(stateNode).every(sn => isInFinalState(configuration, sn));
|
|
412
399
|
}
|
|
413
|
-
return
|
|
400
|
+
return stateNode.type === 'final';
|
|
414
401
|
}
|
|
415
402
|
const isStateId = str => str[0] === STATE_IDENTIFIER;
|
|
416
403
|
function getCandidates(stateNode, receivedEventType) {
|
|
@@ -466,13 +453,7 @@ function getDelayedTransitions(stateNode) {
|
|
|
466
453
|
stateNode.exit.push(cancel(eventType));
|
|
467
454
|
return eventType;
|
|
468
455
|
};
|
|
469
|
-
const delayedTransitions =
|
|
470
|
-
const eventType = mutateEntryExit(transition.delay, i);
|
|
471
|
-
return {
|
|
472
|
-
...transition,
|
|
473
|
-
event: eventType
|
|
474
|
-
};
|
|
475
|
-
}) : Object.keys(afterConfig).flatMap((delay, i) => {
|
|
456
|
+
const delayedTransitions = Object.keys(afterConfig).flatMap((delay, i) => {
|
|
476
457
|
const configTransition = afterConfig[delay];
|
|
477
458
|
const resolvedTransition = typeof configTransition === 'string' ? {
|
|
478
459
|
target: configTransition
|
|
@@ -560,43 +541,23 @@ function formatTransitions(stateNode) {
|
|
|
560
541
|
return transitions;
|
|
561
542
|
}
|
|
562
543
|
function formatInitialTransition(stateNode, _target) {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
// to their state node
|
|
567
|
-
const descStateNode = typeof t === 'string' ? isStateId(t) ? stateNode.machine.getStateNodeById(t) : stateNode.states[t] : t;
|
|
568
|
-
if (!descStateNode) {
|
|
569
|
-
throw new Error(`Initial state node "${t}" not found on parent state node #${stateNode.id}`);
|
|
570
|
-
}
|
|
571
|
-
if (!isDescendant(descStateNode, stateNode)) {
|
|
572
|
-
throw new Error(`Invalid initial target: state node #${descStateNode.id} is not a descendant of #${stateNode.id}`);
|
|
573
|
-
}
|
|
574
|
-
return descStateNode;
|
|
575
|
-
});
|
|
576
|
-
const resolvedTarget = resolveTarget(stateNode, targets);
|
|
577
|
-
const transition = {
|
|
578
|
-
source: stateNode,
|
|
579
|
-
actions: [],
|
|
580
|
-
eventType: null,
|
|
581
|
-
reenter: false,
|
|
582
|
-
target: resolvedTarget,
|
|
583
|
-
toJSON: () => ({
|
|
584
|
-
...transition,
|
|
585
|
-
source: `#${stateNode.id}`,
|
|
586
|
-
target: resolvedTarget ? resolvedTarget.map(t => `#${t.id}`) : undefined
|
|
587
|
-
})
|
|
588
|
-
};
|
|
589
|
-
return transition;
|
|
544
|
+
const resolvedTarget = typeof _target === 'string' ? stateNode.states[_target] : _target ? stateNode.states[_target.target] : undefined;
|
|
545
|
+
if (!resolvedTarget && _target) {
|
|
546
|
+
throw new Error(`Initial state node "${_target}" not found on parent state node #${stateNode.id}`);
|
|
590
547
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
548
|
+
const transition = {
|
|
549
|
+
source: stateNode,
|
|
550
|
+
actions: !_target || typeof _target === 'string' ? [] : toArray(_target.actions),
|
|
551
|
+
eventType: null,
|
|
552
|
+
reenter: false,
|
|
553
|
+
target: resolvedTarget ? [resolvedTarget] : [],
|
|
554
|
+
toJSON: () => ({
|
|
555
|
+
...transition,
|
|
556
|
+
source: `#${stateNode.id}`,
|
|
557
|
+
target: resolvedTarget ? [`#${resolvedTarget.id}`] : []
|
|
558
|
+
})
|
|
559
|
+
};
|
|
560
|
+
return transition;
|
|
600
561
|
}
|
|
601
562
|
function resolveTarget(stateNode, targets) {
|
|
602
563
|
if (targets === undefined) {
|
|
@@ -639,6 +600,15 @@ function resolveHistoryTarget(stateNode) {
|
|
|
639
600
|
function isHistoryNode(stateNode) {
|
|
640
601
|
return stateNode.type === 'history';
|
|
641
602
|
}
|
|
603
|
+
function getInitialStateNodesWithTheirAncestors(stateNode) {
|
|
604
|
+
const states = getInitialStateNodes(stateNode);
|
|
605
|
+
for (const initialState of states) {
|
|
606
|
+
for (const ancestor of getProperAncestors(initialState, stateNode)) {
|
|
607
|
+
states.add(ancestor);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return states;
|
|
611
|
+
}
|
|
642
612
|
function getInitialStateNodes(stateNode) {
|
|
643
613
|
const set = new Set();
|
|
644
614
|
function iter(descStateNode) {
|
|
@@ -647,12 +617,7 @@ function getInitialStateNodes(stateNode) {
|
|
|
647
617
|
}
|
|
648
618
|
set.add(descStateNode);
|
|
649
619
|
if (descStateNode.type === 'compound') {
|
|
650
|
-
|
|
651
|
-
for (const a of getProperAncestors(targetStateNode, stateNode)) {
|
|
652
|
-
set.add(a);
|
|
653
|
-
}
|
|
654
|
-
iter(targetStateNode);
|
|
655
|
-
}
|
|
620
|
+
iter(descStateNode.initial.target[0]);
|
|
656
621
|
} else if (descStateNode.type === 'parallel') {
|
|
657
622
|
for (const child of getChildren(descStateNode)) {
|
|
658
623
|
iter(child);
|
|
@@ -660,7 +625,7 @@ function getInitialStateNodes(stateNode) {
|
|
|
660
625
|
}
|
|
661
626
|
}
|
|
662
627
|
iter(stateNode);
|
|
663
|
-
return
|
|
628
|
+
return set;
|
|
664
629
|
}
|
|
665
630
|
/**
|
|
666
631
|
* Returns the child state node from its relative `stateKey`, or throws.
|
|
@@ -916,41 +881,37 @@ function microstep(transitions, currentState, actorCtx, event, isInitial) {
|
|
|
916
881
|
}
|
|
917
882
|
|
|
918
883
|
function microstepProcedure(transitions, currentState, mutConfiguration, event, actorCtx, isInitial) {
|
|
919
|
-
const actions = [];
|
|
920
884
|
const historyValue = {
|
|
921
885
|
...currentState.historyValue
|
|
922
886
|
};
|
|
923
887
|
const filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
|
|
924
888
|
const internalQueue = [...currentState._internalQueue];
|
|
889
|
+
// TODO: this `cloneState` is really just a hack to prevent infinite loops
|
|
890
|
+
// we need to take another look at how internal queue is managed
|
|
891
|
+
let nextState = cloneState(currentState, {
|
|
892
|
+
_internalQueue: []
|
|
893
|
+
});
|
|
925
894
|
|
|
926
895
|
// Exit states
|
|
927
896
|
if (!isInitial) {
|
|
928
|
-
exitStates(filteredTransitions, mutConfiguration, historyValue
|
|
897
|
+
nextState = exitStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, historyValue);
|
|
929
898
|
}
|
|
930
899
|
|
|
931
900
|
// Execute transition content
|
|
932
|
-
|
|
901
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, filteredTransitions.flatMap(t => t.actions));
|
|
933
902
|
|
|
934
903
|
// Enter states
|
|
935
|
-
enterStates(event, filteredTransitions, mutConfiguration,
|
|
904
|
+
nextState = enterStates(nextState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
|
|
936
905
|
const nextConfiguration = [...mutConfiguration];
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const finalActions = nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit);
|
|
940
|
-
actions.push(...finalActions);
|
|
906
|
+
if (nextState.status === 'done') {
|
|
907
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit));
|
|
941
908
|
}
|
|
942
909
|
try {
|
|
943
|
-
const nextState = resolveActionsAndContext(actions, event, currentState, actorCtx);
|
|
944
|
-
const output = done ? getOutput(nextConfiguration, nextState.context, event, actorCtx.self) : undefined;
|
|
945
910
|
internalQueue.push(...nextState._internalQueue);
|
|
946
|
-
return cloneState(
|
|
911
|
+
return cloneState(nextState, {
|
|
947
912
|
configuration: nextConfiguration,
|
|
948
913
|
historyValue,
|
|
949
|
-
_internalQueue: internalQueue
|
|
950
|
-
context: nextState.context,
|
|
951
|
-
status: done ? 'done' : currentState.status,
|
|
952
|
-
output,
|
|
953
|
-
children: nextState.children
|
|
914
|
+
_internalQueue: internalQueue
|
|
954
915
|
});
|
|
955
916
|
} catch (e) {
|
|
956
917
|
// TODO: Refactor this once proper error handling is implemented.
|
|
@@ -958,7 +919,15 @@ function microstepProcedure(transitions, currentState, mutConfiguration, event,
|
|
|
958
919
|
throw e;
|
|
959
920
|
}
|
|
960
921
|
}
|
|
961
|
-
function
|
|
922
|
+
function getMachineOutput(state, event, actorCtx, rootNode, rootCompletionNode) {
|
|
923
|
+
if (!rootNode.output) {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorCtx.self) : undefined);
|
|
927
|
+
return resolveOutput(rootNode.output, state.context, doneStateEvent, actorCtx.self);
|
|
928
|
+
}
|
|
929
|
+
function enterStates(currentState, event, actorCtx, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
|
|
930
|
+
let nextState = currentState;
|
|
962
931
|
const statesToEnter = new Set();
|
|
963
932
|
const statesForDefaultEntry = new Set();
|
|
964
933
|
computeEntrySet(filteredTransitions, historyValue, statesForDefaultEntry, statesToEnter);
|
|
@@ -967,36 +936,48 @@ function enterStates(event, filteredTransitions, mutConfiguration, actions, inte
|
|
|
967
936
|
if (isInitial) {
|
|
968
937
|
statesForDefaultEntry.add(currentState.machine.root);
|
|
969
938
|
}
|
|
939
|
+
const completedNodes = new Set();
|
|
970
940
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
971
941
|
mutConfiguration.add(stateNodeToEnter);
|
|
972
|
-
|
|
973
|
-
actions.push(invoke(invokeDef));
|
|
974
|
-
}
|
|
942
|
+
const actions = [];
|
|
975
943
|
|
|
976
944
|
// Add entry actions
|
|
977
945
|
actions.push(...stateNodeToEnter.entry);
|
|
946
|
+
for (const invokeDef of stateNodeToEnter.invoke) {
|
|
947
|
+
actions.push(invoke(invokeDef));
|
|
948
|
+
}
|
|
978
949
|
if (statesForDefaultEntry.has(stateNodeToEnter)) {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
actions.push(...initialActions);
|
|
982
|
-
}
|
|
950
|
+
const initialActions = stateNodeToEnter.initial.actions;
|
|
951
|
+
actions.push(...initialActions);
|
|
983
952
|
}
|
|
953
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, actions, stateNodeToEnter.invoke.map(invokeDef => invokeDef.id));
|
|
984
954
|
if (stateNodeToEnter.type === 'final') {
|
|
985
955
|
const parent = stateNodeToEnter.parent;
|
|
986
|
-
if (
|
|
956
|
+
if (completedNodes.has(parent)) {
|
|
987
957
|
continue;
|
|
988
958
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
959
|
+
completedNodes.add(parent);
|
|
960
|
+
let rootCompletionNode = parent?.type === 'parallel' ? parent : stateNodeToEnter;
|
|
961
|
+
let ancestorMarker = parent?.parent;
|
|
962
|
+
if (ancestorMarker) {
|
|
963
|
+
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorCtx.self) : undefined));
|
|
964
|
+
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutConfiguration, ancestorMarker)) {
|
|
965
|
+
completedNodes.add(ancestorMarker);
|
|
966
|
+
internalQueue.push(createDoneStateEvent(ancestorMarker.id));
|
|
967
|
+
rootCompletionNode = ancestorMarker;
|
|
968
|
+
ancestorMarker = ancestorMarker.parent;
|
|
996
969
|
}
|
|
997
970
|
}
|
|
971
|
+
if (ancestorMarker) {
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
nextState = cloneState(nextState, {
|
|
975
|
+
status: 'done',
|
|
976
|
+
output: getMachineOutput(nextState, event, actorCtx, currentState.configuration[0].machine.root, rootCompletionNode)
|
|
977
|
+
});
|
|
998
978
|
}
|
|
999
979
|
}
|
|
980
|
+
return nextState;
|
|
1000
981
|
}
|
|
1001
982
|
function computeEntrySet(transitions, historyValue, statesForDefaultEntry, statesToEnter) {
|
|
1002
983
|
for (const t of transitions) {
|
|
@@ -1039,13 +1020,9 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
|
|
|
1039
1020
|
statesToEnter.add(stateNode);
|
|
1040
1021
|
if (stateNode.type === 'compound') {
|
|
1041
1022
|
statesForDefaultEntry.add(stateNode);
|
|
1042
|
-
const
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
}
|
|
1046
|
-
for (const initialState of initialStates) {
|
|
1047
|
-
addAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
1048
|
-
}
|
|
1023
|
+
const [initialState] = stateNode.initial.target;
|
|
1024
|
+
addDescendantStatesToEnter(initialState, historyValue, statesForDefaultEntry, statesToEnter);
|
|
1025
|
+
addAncestorStatesToEnter(initialState, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
|
|
1049
1026
|
} else {
|
|
1050
1027
|
if (stateNode.type === 'parallel') {
|
|
1051
1028
|
for (const child of getChildren(stateNode).filter(sn => !isHistoryNode(sn))) {
|
|
@@ -1070,7 +1047,8 @@ function addAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, history
|
|
|
1070
1047
|
}
|
|
1071
1048
|
}
|
|
1072
1049
|
}
|
|
1073
|
-
function exitStates(transitions, mutConfiguration, historyValue
|
|
1050
|
+
function exitStates(currentState, event, actorCtx, transitions, mutConfiguration, historyValue) {
|
|
1051
|
+
let nextState = currentState;
|
|
1074
1052
|
const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
|
|
1075
1053
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
1076
1054
|
|
|
@@ -1089,19 +1067,16 @@ function exitStates(transitions, mutConfiguration, historyValue, actions) {
|
|
|
1089
1067
|
}
|
|
1090
1068
|
}
|
|
1091
1069
|
for (const s of statesToExit) {
|
|
1092
|
-
|
|
1070
|
+
nextState = resolveActionsAndContext(nextState, event, actorCtx, [...s.exit, ...s.invoke.map(def => stop(def.id))]);
|
|
1093
1071
|
mutConfiguration.delete(s);
|
|
1094
1072
|
}
|
|
1073
|
+
return nextState;
|
|
1095
1074
|
}
|
|
1096
|
-
function
|
|
1075
|
+
function resolveActionsAndContextWorker(currentState, event, actorCtx, actions, extra, retries) {
|
|
1097
1076
|
const {
|
|
1098
1077
|
machine
|
|
1099
1078
|
} = currentState;
|
|
1100
|
-
|
|
1101
|
-
// we need to take another look at how internal queue is managed
|
|
1102
|
-
let intermediateState = cloneState(currentState, {
|
|
1103
|
-
_internalQueue: []
|
|
1104
|
-
});
|
|
1079
|
+
let intermediateState = currentState;
|
|
1105
1080
|
for (const action of actions) {
|
|
1106
1081
|
const isInline = typeof action === 'function';
|
|
1107
1082
|
const resolvedAction = isInline ? action :
|
|
@@ -1140,11 +1115,14 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1140
1115
|
continue;
|
|
1141
1116
|
}
|
|
1142
1117
|
const builtinAction = resolvedAction;
|
|
1143
|
-
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction
|
|
1144
|
-
|
|
1145
|
-
|
|
1118
|
+
const [nextState, params, actions] = builtinAction.resolve(actorCtx, intermediateState, actionArgs, resolvedAction,
|
|
1119
|
+
// this holds all params
|
|
1120
|
+
extra);
|
|
1146
1121
|
intermediateState = nextState;
|
|
1147
|
-
if ('
|
|
1122
|
+
if ('retryResolve' in builtinAction) {
|
|
1123
|
+
retries?.push([builtinAction, params]);
|
|
1124
|
+
}
|
|
1125
|
+
if ('execute' in builtinAction) {
|
|
1148
1126
|
if (actorCtx?.self.status === ActorStatus.Running) {
|
|
1149
1127
|
builtinAction.execute(actorCtx, params);
|
|
1150
1128
|
} else {
|
|
@@ -1152,11 +1130,21 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
|
|
|
1152
1130
|
}
|
|
1153
1131
|
}
|
|
1154
1132
|
if (actions) {
|
|
1155
|
-
intermediateState =
|
|
1133
|
+
intermediateState = resolveActionsAndContextWorker(intermediateState, event, actorCtx, actions, extra, retries);
|
|
1156
1134
|
}
|
|
1157
1135
|
}
|
|
1158
1136
|
return intermediateState;
|
|
1159
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
|
+
}
|
|
1160
1148
|
function macrostep(state, event, actorCtx) {
|
|
1161
1149
|
if (event.type === WILDCARD) {
|
|
1162
1150
|
throw new Error(`An event cannot have the wildcard type ('${WILDCARD}')`);
|
|
@@ -1216,7 +1204,7 @@ function stopStep(event, nextState, actorCtx) {
|
|
|
1216
1204
|
for (const child of Object.values(nextState.children)) {
|
|
1217
1205
|
actions.push(stop(child));
|
|
1218
1206
|
}
|
|
1219
|
-
return resolveActionsAndContext(
|
|
1207
|
+
return resolveActionsAndContext(nextState, event, actorCtx, actions);
|
|
1220
1208
|
}
|
|
1221
1209
|
function selectTransitions(event, nextState) {
|
|
1222
1210
|
return nextState.machine.getTransitionData(nextState, event);
|
|
@@ -1428,11 +1416,15 @@ function getPersistedState(state) {
|
|
|
1428
1416
|
tags,
|
|
1429
1417
|
machine,
|
|
1430
1418
|
children,
|
|
1419
|
+
context,
|
|
1431
1420
|
...jsonValues
|
|
1432
1421
|
} = state;
|
|
1433
1422
|
const childrenJson = {};
|
|
1434
1423
|
for (const id in children) {
|
|
1435
1424
|
const child = children[id];
|
|
1425
|
+
if (typeof child.src !== 'string') {
|
|
1426
|
+
throw new Error('An inline child actor cannot be persisted.');
|
|
1427
|
+
}
|
|
1436
1428
|
childrenJson[id] = {
|
|
1437
1429
|
state: child.getPersistedState?.(),
|
|
1438
1430
|
src: child.src
|
|
@@ -1440,9 +1432,38 @@ function getPersistedState(state) {
|
|
|
1440
1432
|
}
|
|
1441
1433
|
return {
|
|
1442
1434
|
...jsonValues,
|
|
1435
|
+
// TODO: this makes `PersistedMachineState`'s type kind of a lie
|
|
1436
|
+
// it doesn't truly use `TContext` but rather some kind of a derived form of it
|
|
1437
|
+
context: persistContext(context),
|
|
1443
1438
|
children: childrenJson
|
|
1444
1439
|
};
|
|
1445
1440
|
}
|
|
1441
|
+
function persistContext(contextPart) {
|
|
1442
|
+
let copy;
|
|
1443
|
+
for (const key in contextPart) {
|
|
1444
|
+
const value = contextPart[key];
|
|
1445
|
+
if (value && typeof value === 'object') {
|
|
1446
|
+
if ('sessionId' in value && 'send' in value && 'ref' in value) {
|
|
1447
|
+
copy ??= Array.isArray(contextPart) ? contextPart.slice() : {
|
|
1448
|
+
...contextPart
|
|
1449
|
+
};
|
|
1450
|
+
copy[key] = {
|
|
1451
|
+
xstate$$type: $$ACTOR_TYPE,
|
|
1452
|
+
id: value.id
|
|
1453
|
+
};
|
|
1454
|
+
} else {
|
|
1455
|
+
const result = persistContext(value);
|
|
1456
|
+
if (result !== value) {
|
|
1457
|
+
copy ??= Array.isArray(contextPart) ? contextPart.slice() : {
|
|
1458
|
+
...contextPart
|
|
1459
|
+
};
|
|
1460
|
+
copy[key] = result;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
return copy ?? contextPart;
|
|
1466
|
+
}
|
|
1446
1467
|
|
|
1447
1468
|
function resolveRaise(_, state, args, {
|
|
1448
1469
|
event: eventOrExpr,
|
|
@@ -1496,4 +1517,4 @@ function raise(eventOrExpr, options) {
|
|
|
1496
1517
|
return raise;
|
|
1497
1518
|
}
|
|
1498
1519
|
|
|
1499
|
-
export { raise as A, stop as B, State as S, formatTransition as a, formatInitialTransition as b, getCandidates as c, getConfiguration as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getStateNodes as h, isInFinalState as i, cloneState as j, macrostep as k, getInitialConfiguration as l, memo as m, resolveActionsAndContext as n, microstep as o,
|
|
1520
|
+
export { raise as A, stop as B, State as S, formatTransition as a, formatInitialTransition as b, getCandidates as c, getConfiguration as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getStateNodes as h, isInFinalState as i, cloneState as j, macrostep as k, getInitialConfiguration as l, memo as m, resolveActionsAndContext as n, microstep as o, getInitialStateNodes as p, isStateId as q, resolveStateValue as r, getStateNodeByPath as s, transitionNode as t, getPersistedState as u, and as v, not as w, or as x, stateIn as y, cancel as z };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var interpreter = require('./interpreter-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-0ff57677.cjs.js');
|
|
4
|
+
var interpreter = require('./interpreter-69605bf0.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorContext, {
|
|
7
7
|
machine,
|
|
@@ -27,6 +27,7 @@ function createSpawner(actorContext, {
|
|
|
27
27
|
event,
|
|
28
28
|
self: actorContext.self
|
|
29
29
|
}) : input,
|
|
30
|
+
src,
|
|
30
31
|
systemId
|
|
31
32
|
});
|
|
32
33
|
spawnedChildren[actorRef.id] = actorRef;
|
|
@@ -52,6 +53,7 @@ function createSpawner(actorContext, {
|
|
|
52
53
|
id: options.id,
|
|
53
54
|
parent: actorContext.self,
|
|
54
55
|
input: options.input,
|
|
56
|
+
src: undefined,
|
|
55
57
|
systemId
|
|
56
58
|
});
|
|
57
59
|
if (options.syncSnapshot) {
|
|
@@ -258,7 +260,7 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
258
260
|
event: eventOrExpr,
|
|
259
261
|
id,
|
|
260
262
|
delay
|
|
261
|
-
}) {
|
|
263
|
+
}, extra) {
|
|
262
264
|
const delaysMap = state.machine.implementations.delays;
|
|
263
265
|
if (typeof eventOrExpr === 'string') {
|
|
264
266
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
@@ -283,7 +285,7 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
283
285
|
// #_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.
|
|
284
286
|
targetActorRef = state.children[resolvedTarget.slice(2)];
|
|
285
287
|
} else {
|
|
286
|
-
targetActorRef = state.children[resolvedTarget];
|
|
288
|
+
targetActorRef = extra?.deferredActorIds.includes(resolvedTarget) ? resolvedTarget : state.children[resolvedTarget];
|
|
287
289
|
}
|
|
288
290
|
if (!targetActorRef) {
|
|
289
291
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
|
|
@@ -298,16 +300,21 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
298
300
|
delay: resolvedDelay
|
|
299
301
|
}];
|
|
300
302
|
}
|
|
303
|
+
function retryResolveSendTo(_, state, params) {
|
|
304
|
+
if (typeof params.to === 'string') {
|
|
305
|
+
params.to = state.children[params.to];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
301
308
|
function executeSendTo(actorContext, params) {
|
|
302
309
|
if (typeof params.delay === 'number') {
|
|
303
310
|
actorContext.self.delaySend(params);
|
|
304
311
|
return;
|
|
305
312
|
}
|
|
306
|
-
const {
|
|
307
|
-
to,
|
|
308
|
-
event
|
|
309
|
-
} = params;
|
|
310
313
|
actorContext.defer(() => {
|
|
314
|
+
const {
|
|
315
|
+
to,
|
|
316
|
+
event
|
|
317
|
+
} = params;
|
|
311
318
|
actorContext?.system._relay(actorContext.self, to, event.type === interpreter.XSTATE_ERROR ? interpreter.createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
312
319
|
});
|
|
313
320
|
}
|
|
@@ -329,6 +336,7 @@ function sendTo(to, eventOrExpr, options) {
|
|
|
329
336
|
sendTo.id = options?.id;
|
|
330
337
|
sendTo.delay = options?.delay;
|
|
331
338
|
sendTo.resolve = resolveSendTo;
|
|
339
|
+
sendTo.retryResolve = retryResolveSendTo;
|
|
332
340
|
sendTo.execute = executeSendTo;
|
|
333
341
|
return sendTo;
|
|
334
342
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { j as cloneState, e as evaluateGuard } from './raise-
|
|
2
|
-
import { f as ActorStatus,
|
|
1
|
+
import { j as cloneState, e as evaluateGuard } from './raise-cdcdf834.development.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-5c4e6634.development.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorContext, {
|
|
5
5
|
machine,
|
|
@@ -25,6 +25,7 @@ function createSpawner(actorContext, {
|
|
|
25
25
|
event,
|
|
26
26
|
self: actorContext.self
|
|
27
27
|
}) : input,
|
|
28
|
+
src,
|
|
28
29
|
systemId
|
|
29
30
|
});
|
|
30
31
|
spawnedChildren[actorRef.id] = actorRef;
|
|
@@ -50,6 +51,7 @@ function createSpawner(actorContext, {
|
|
|
50
51
|
id: options.id,
|
|
51
52
|
parent: actorContext.self,
|
|
52
53
|
input: options.input,
|
|
54
|
+
src: undefined,
|
|
53
55
|
systemId
|
|
54
56
|
});
|
|
55
57
|
if (options.syncSnapshot) {
|
|
@@ -268,7 +270,7 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
268
270
|
event: eventOrExpr,
|
|
269
271
|
id,
|
|
270
272
|
delay
|
|
271
|
-
}) {
|
|
273
|
+
}, extra) {
|
|
272
274
|
const delaysMap = state.machine.implementations.delays;
|
|
273
275
|
if (typeof eventOrExpr === 'string') {
|
|
274
276
|
throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${eventOrExpr}" }) instead`);
|
|
@@ -293,7 +295,7 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
293
295
|
// #_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.
|
|
294
296
|
targetActorRef = state.children[resolvedTarget.slice(2)];
|
|
295
297
|
} else {
|
|
296
|
-
targetActorRef = state.children[resolvedTarget];
|
|
298
|
+
targetActorRef = extra?.deferredActorIds.includes(resolvedTarget) ? resolvedTarget : state.children[resolvedTarget];
|
|
297
299
|
}
|
|
298
300
|
if (!targetActorRef) {
|
|
299
301
|
throw new Error(`Unable to send event to actor '${resolvedTarget}' from machine '${state.machine.id}'.`);
|
|
@@ -308,16 +310,21 @@ function resolveSendTo(actorContext, state, args, {
|
|
|
308
310
|
delay: resolvedDelay
|
|
309
311
|
}];
|
|
310
312
|
}
|
|
313
|
+
function retryResolveSendTo(_, state, params) {
|
|
314
|
+
if (typeof params.to === 'string') {
|
|
315
|
+
params.to = state.children[params.to];
|
|
316
|
+
}
|
|
317
|
+
}
|
|
311
318
|
function executeSendTo(actorContext, params) {
|
|
312
319
|
if (typeof params.delay === 'number') {
|
|
313
320
|
actorContext.self.delaySend(params);
|
|
314
321
|
return;
|
|
315
322
|
}
|
|
316
|
-
const {
|
|
317
|
-
to,
|
|
318
|
-
event
|
|
319
|
-
} = params;
|
|
320
323
|
actorContext.defer(() => {
|
|
324
|
+
const {
|
|
325
|
+
to,
|
|
326
|
+
event
|
|
327
|
+
} = params;
|
|
321
328
|
actorContext?.system._relay(actorContext.self, to, event.type === XSTATE_ERROR ? createErrorActorEvent(actorContext.self.id, event.data) : event);
|
|
322
329
|
});
|
|
323
330
|
}
|
|
@@ -342,6 +349,7 @@ function sendTo(to, eventOrExpr, options) {
|
|
|
342
349
|
sendTo.id = options?.id;
|
|
343
350
|
sendTo.delay = options?.delay;
|
|
344
351
|
sendTo.resolve = resolveSendTo;
|
|
352
|
+
sendTo.retryResolve = retryResolveSendTo;
|
|
345
353
|
sendTo.execute = executeSendTo;
|
|
346
354
|
return sendTo;
|
|
347
355
|
}
|