xstate 5.0.0-beta.44 → 5.0.0-beta.45
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 +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -2
- 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 +93 -5
- package/actors/dist/xstate-actors.development.cjs.js +93 -5
- package/actors/dist/xstate-actors.development.esm.js +93 -5
- package/actors/dist/xstate-actors.esm.js +93 -5
- 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/State.d.ts +11 -11
- package/dist/declarations/src/StateMachine.d.ts +1 -1
- package/dist/declarations/src/actions/choose.d.ts +3 -3
- package/dist/declarations/src/actions/pure.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +39 -0
- package/dist/declarations/src/actors/transition.d.ts +53 -4
- package/dist/declarations/src/{Machine.d.ts → createMachine.d.ts} +1 -1
- package/dist/declarations/src/guards.d.ts +26 -4
- package/dist/declarations/src/index.d.ts +2 -1
- package/dist/declarations/src/interpreter.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +32 -0
- package/dist/declarations/src/stateUtils.d.ts +7 -7
- package/dist/declarations/src/types.d.ts +16 -13
- package/dist/{raise-5854eaca.esm.js → raise-2b5a4e4c.esm.js} +82 -105
- package/dist/{raise-348cc74e.development.esm.js → raise-90139fbc.development.esm.js} +82 -105
- package/dist/{raise-ed700d14.development.cjs.js → raise-b3fb3c65.development.cjs.js} +82 -106
- package/dist/{raise-fb6f017b.cjs.js → raise-fabffc3d.cjs.js} +82 -106
- package/dist/{send-a0193bdb.development.esm.js → send-24cc8018.development.esm.js} +3 -28
- package/dist/{send-b7b4befa.esm.js → send-8e7e41e7.esm.js} +3 -28
- package/dist/{send-53e5693c.cjs.js → send-c124176f.cjs.js} +3 -28
- package/dist/{send-00466e37.development.cjs.js → send-d0bc7eed.development.cjs.js} +3 -28
- package/dist/xstate.cjs.js +46 -14
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +46 -14
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +42 -11
- package/dist/xstate.esm.js +42 -11
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -386,6 +386,7 @@ class Actor {
|
|
|
386
386
|
this.logger = void 0;
|
|
387
387
|
this._processingStatus = ProcessingStatus.NotStarted;
|
|
388
388
|
this._parent = void 0;
|
|
389
|
+
this._syncSnapshot = void 0;
|
|
389
390
|
this.ref = void 0;
|
|
390
391
|
this._actorScope = void 0;
|
|
391
392
|
this._systemId = void 0;
|
|
@@ -402,6 +403,7 @@ class Actor {
|
|
|
402
403
|
clock,
|
|
403
404
|
logger,
|
|
404
405
|
parent,
|
|
406
|
+
syncSnapshot,
|
|
405
407
|
id,
|
|
406
408
|
systemId,
|
|
407
409
|
inspect
|
|
@@ -416,6 +418,7 @@ class Actor {
|
|
|
416
418
|
this.logger = logger;
|
|
417
419
|
this.clock = clock;
|
|
418
420
|
this._parent = parent;
|
|
421
|
+
this._syncSnapshot = syncSnapshot;
|
|
419
422
|
this.options = resolvedOptions;
|
|
420
423
|
this.src = resolvedOptions.src ?? logic;
|
|
421
424
|
this.ref = this;
|
|
@@ -574,6 +577,19 @@ class Actor {
|
|
|
574
577
|
// Do not restart the service if it is already started
|
|
575
578
|
return this;
|
|
576
579
|
}
|
|
580
|
+
if (this._syncSnapshot) {
|
|
581
|
+
this.subscribe({
|
|
582
|
+
next: snapshot => {
|
|
583
|
+
if (snapshot.status === 'active') {
|
|
584
|
+
this._parent.send({
|
|
585
|
+
type: `xstate.snapshot.${this.id}`,
|
|
586
|
+
snapshot
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
error: () => {}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
577
593
|
this.system._register(this.sessionId, this);
|
|
578
594
|
if (this._systemId) {
|
|
579
595
|
this.system._set(this._systemId, this);
|
|
@@ -851,20 +867,6 @@ const interpret = createActor;
|
|
|
851
867
|
* @deprecated Use `Actor` instead.
|
|
852
868
|
*/
|
|
853
869
|
|
|
854
|
-
const cache = new WeakMap();
|
|
855
|
-
function memo(object, key, fn) {
|
|
856
|
-
let memoizedData = cache.get(object);
|
|
857
|
-
if (!memoizedData) {
|
|
858
|
-
memoizedData = {
|
|
859
|
-
[key]: fn()
|
|
860
|
-
};
|
|
861
|
-
cache.set(object, memoizedData);
|
|
862
|
-
} else if (!(key in memoizedData)) {
|
|
863
|
-
memoizedData[key] = fn();
|
|
864
|
-
}
|
|
865
|
-
return memoizedData[key];
|
|
866
|
-
}
|
|
867
|
-
|
|
868
870
|
function resolveCancel(_, state, actionArgs, actionParams, {
|
|
869
871
|
sendId
|
|
870
872
|
}) {
|
|
@@ -906,6 +908,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
906
908
|
id: resolvedId,
|
|
907
909
|
src,
|
|
908
910
|
parent: actorScope?.self,
|
|
911
|
+
syncSnapshot,
|
|
909
912
|
systemId,
|
|
910
913
|
input: typeof input === 'function' ? input({
|
|
911
914
|
context: state.context,
|
|
@@ -913,19 +916,6 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
|
|
|
913
916
|
self: actorScope?.self
|
|
914
917
|
}) : input
|
|
915
918
|
});
|
|
916
|
-
if (syncSnapshot) {
|
|
917
|
-
actorRef.subscribe({
|
|
918
|
-
next: snapshot => {
|
|
919
|
-
if (snapshot.status === 'active') {
|
|
920
|
-
actorScope.self.send({
|
|
921
|
-
type: `xstate.snapshot.${id}`,
|
|
922
|
-
snapshot
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
},
|
|
926
|
-
error: () => {}
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
919
|
}
|
|
930
920
|
return [cloneMachineSnapshot(state, {
|
|
931
921
|
children: {
|
|
@@ -1035,7 +1025,7 @@ function checkStateIn(state, _, {
|
|
|
1035
1025
|
}) {
|
|
1036
1026
|
if (typeof stateValue === 'string' && isStateId(stateValue)) {
|
|
1037
1027
|
const target = state.machine.getStateNodeById(stateValue);
|
|
1038
|
-
return state.
|
|
1028
|
+
return state._nodes.some(sn => sn === target);
|
|
1039
1029
|
}
|
|
1040
1030
|
return state.matches(stateValue);
|
|
1041
1031
|
}
|
|
@@ -1146,26 +1136,25 @@ function getProperAncestors(stateNode, toStateNode) {
|
|
|
1146
1136
|
}
|
|
1147
1137
|
return ancestors;
|
|
1148
1138
|
}
|
|
1149
|
-
function
|
|
1150
|
-
const
|
|
1151
|
-
const
|
|
1152
|
-
const adjList = getAdjList(configurationSet);
|
|
1139
|
+
function getAllStateNodes(stateNodes) {
|
|
1140
|
+
const nodeSet = new Set(stateNodes);
|
|
1141
|
+
const adjList = getAdjList(nodeSet);
|
|
1153
1142
|
|
|
1154
1143
|
// add descendants
|
|
1155
|
-
for (const s of
|
|
1144
|
+
for (const s of nodeSet) {
|
|
1156
1145
|
// if previously active, add existing child nodes
|
|
1157
1146
|
if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
|
|
1158
|
-
getInitialStateNodesWithTheirAncestors(s).forEach(sn =>
|
|
1147
|
+
getInitialStateNodesWithTheirAncestors(s).forEach(sn => nodeSet.add(sn));
|
|
1159
1148
|
} else {
|
|
1160
1149
|
if (s.type === 'parallel') {
|
|
1161
1150
|
for (const child of getChildren(s)) {
|
|
1162
1151
|
if (child.type === 'history') {
|
|
1163
1152
|
continue;
|
|
1164
1153
|
}
|
|
1165
|
-
if (!
|
|
1154
|
+
if (!nodeSet.has(child)) {
|
|
1166
1155
|
const initialStates = getInitialStateNodesWithTheirAncestors(child);
|
|
1167
1156
|
for (const initialStateNode of initialStates) {
|
|
1168
|
-
|
|
1157
|
+
nodeSet.add(initialStateNode);
|
|
1169
1158
|
}
|
|
1170
1159
|
}
|
|
1171
1160
|
}
|
|
@@ -1174,14 +1163,14 @@ function getConfiguration(stateNodes) {
|
|
|
1174
1163
|
}
|
|
1175
1164
|
|
|
1176
1165
|
// add all ancestors
|
|
1177
|
-
for (const s of
|
|
1166
|
+
for (const s of nodeSet) {
|
|
1178
1167
|
let m = s.parent;
|
|
1179
1168
|
while (m) {
|
|
1180
|
-
|
|
1169
|
+
nodeSet.add(m);
|
|
1181
1170
|
m = m.parent;
|
|
1182
1171
|
}
|
|
1183
1172
|
}
|
|
1184
|
-
return
|
|
1173
|
+
return nodeSet;
|
|
1185
1174
|
}
|
|
1186
1175
|
function getValueFromAdj(baseNode, adjList) {
|
|
1187
1176
|
const childStateNodes = adjList.get(baseNode);
|
|
@@ -1205,9 +1194,9 @@ function getValueFromAdj(baseNode, adjList) {
|
|
|
1205
1194
|
}
|
|
1206
1195
|
return stateValue;
|
|
1207
1196
|
}
|
|
1208
|
-
function getAdjList(
|
|
1197
|
+
function getAdjList(stateNodes) {
|
|
1209
1198
|
const adjList = new Map();
|
|
1210
|
-
for (const s of
|
|
1199
|
+
for (const s of stateNodes) {
|
|
1211
1200
|
if (!adjList.has(s)) {
|
|
1212
1201
|
adjList.set(s, []);
|
|
1213
1202
|
}
|
|
@@ -1220,16 +1209,16 @@ function getAdjList(configuration) {
|
|
|
1220
1209
|
}
|
|
1221
1210
|
return adjList;
|
|
1222
1211
|
}
|
|
1223
|
-
function getStateValue(rootNode,
|
|
1224
|
-
const config =
|
|
1212
|
+
function getStateValue(rootNode, stateNodes) {
|
|
1213
|
+
const config = getAllStateNodes(stateNodes);
|
|
1225
1214
|
return getValueFromAdj(rootNode, getAdjList(config));
|
|
1226
1215
|
}
|
|
1227
|
-
function isInFinalState(
|
|
1216
|
+
function isInFinalState(stateNodeSet, stateNode) {
|
|
1228
1217
|
if (stateNode.type === 'compound') {
|
|
1229
|
-
return getChildren(stateNode).some(s => s.type === 'final' &&
|
|
1218
|
+
return getChildren(stateNode).some(s => s.type === 'final' && stateNodeSet.has(s));
|
|
1230
1219
|
}
|
|
1231
1220
|
if (stateNode.type === 'parallel') {
|
|
1232
|
-
return getChildren(stateNode).every(sn => isInFinalState(
|
|
1221
|
+
return getChildren(stateNode).every(sn => isInFinalState(stateNodeSet, sn));
|
|
1233
1222
|
}
|
|
1234
1223
|
return stateNode.type === 'final';
|
|
1235
1224
|
}
|
|
@@ -1589,13 +1578,13 @@ function hasIntersection(s1, s2) {
|
|
|
1589
1578
|
}
|
|
1590
1579
|
return false;
|
|
1591
1580
|
}
|
|
1592
|
-
function removeConflictingTransitions(enabledTransitions,
|
|
1581
|
+
function removeConflictingTransitions(enabledTransitions, stateNodeSet, historyValue) {
|
|
1593
1582
|
const filteredTransitions = new Set();
|
|
1594
1583
|
for (const t1 of enabledTransitions) {
|
|
1595
1584
|
let t1Preempted = false;
|
|
1596
1585
|
const transitionsToRemove = new Set();
|
|
1597
1586
|
for (const t2 of filteredTransitions) {
|
|
1598
|
-
if (hasIntersection(computeExitSet([t1],
|
|
1587
|
+
if (hasIntersection(computeExitSet([t1], stateNodeSet, historyValue), computeExitSet([t2], stateNodeSet, historyValue))) {
|
|
1599
1588
|
if (isDescendant(t1.source, t2.source)) {
|
|
1600
1589
|
transitionsToRemove.add(t2);
|
|
1601
1590
|
} else {
|
|
@@ -1662,7 +1651,7 @@ function getTransitionDomain(transition, historyValue) {
|
|
|
1662
1651
|
}
|
|
1663
1652
|
return transition.source.machine.root;
|
|
1664
1653
|
}
|
|
1665
|
-
function computeExitSet(transitions,
|
|
1654
|
+
function computeExitSet(transitions, stateNodeSet, historyValue) {
|
|
1666
1655
|
const statesToExit = new Set();
|
|
1667
1656
|
for (const t of transitions) {
|
|
1668
1657
|
if (t.target?.length) {
|
|
@@ -1670,7 +1659,7 @@ function computeExitSet(transitions, configuration, historyValue) {
|
|
|
1670
1659
|
if (t.reenter && t.source === domain) {
|
|
1671
1660
|
statesToExit.add(domain);
|
|
1672
1661
|
}
|
|
1673
|
-
for (const stateNode of
|
|
1662
|
+
for (const stateNode of stateNodeSet) {
|
|
1674
1663
|
if (isDescendant(stateNode, domain)) {
|
|
1675
1664
|
statesToExit.add(stateNode);
|
|
1676
1665
|
}
|
|
@@ -1679,12 +1668,12 @@ function computeExitSet(transitions, configuration, historyValue) {
|
|
|
1679
1668
|
}
|
|
1680
1669
|
return [...statesToExit];
|
|
1681
1670
|
}
|
|
1682
|
-
function
|
|
1683
|
-
if (
|
|
1671
|
+
function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
|
|
1672
|
+
if (prevStateNodes.length !== nextStateNodeSet.size) {
|
|
1684
1673
|
return false;
|
|
1685
1674
|
}
|
|
1686
|
-
for (const node of
|
|
1687
|
-
if (!
|
|
1675
|
+
for (const node of prevStateNodes) {
|
|
1676
|
+
if (!nextStateNodeSet.has(node)) {
|
|
1688
1677
|
return false;
|
|
1689
1678
|
}
|
|
1690
1679
|
}
|
|
@@ -1698,31 +1687,31 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
|
|
|
1698
1687
|
if (!transitions.length) {
|
|
1699
1688
|
return currentState;
|
|
1700
1689
|
}
|
|
1701
|
-
const
|
|
1690
|
+
const mutStateNodeSet = new Set(currentState._nodes);
|
|
1702
1691
|
let historyValue = currentState.historyValue;
|
|
1703
|
-
const filteredTransitions = removeConflictingTransitions(transitions,
|
|
1692
|
+
const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
|
|
1704
1693
|
let nextState = currentState;
|
|
1705
1694
|
|
|
1706
1695
|
// Exit states
|
|
1707
1696
|
if (!isInitial) {
|
|
1708
|
-
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions,
|
|
1697
|
+
[nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
|
|
1709
1698
|
}
|
|
1710
1699
|
|
|
1711
1700
|
// Execute transition content
|
|
1712
1701
|
nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
|
|
1713
1702
|
|
|
1714
1703
|
// Enter states
|
|
1715
|
-
nextState = enterStates(nextState, event, actorScope, filteredTransitions,
|
|
1716
|
-
const
|
|
1704
|
+
nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
|
|
1705
|
+
const nextStateNodes = [...mutStateNodeSet];
|
|
1717
1706
|
if (nextState.status === 'done') {
|
|
1718
|
-
nextState = resolveActionsAndContext(nextState, event, actorScope,
|
|
1707
|
+
nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
|
|
1719
1708
|
}
|
|
1720
1709
|
try {
|
|
1721
|
-
if (historyValue === currentState.historyValue &&
|
|
1710
|
+
if (historyValue === currentState.historyValue && areStateNodeCollectionsEqual(currentState._nodes, mutStateNodeSet)) {
|
|
1722
1711
|
return nextState;
|
|
1723
1712
|
}
|
|
1724
1713
|
return cloneMachineSnapshot(nextState, {
|
|
1725
|
-
|
|
1714
|
+
_nodes: nextStateNodes,
|
|
1726
1715
|
historyValue
|
|
1727
1716
|
});
|
|
1728
1717
|
} catch (e) {
|
|
@@ -1738,7 +1727,7 @@ function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode
|
|
|
1738
1727
|
const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
|
|
1739
1728
|
return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
|
|
1740
1729
|
}
|
|
1741
|
-
function enterStates(currentState, event, actorScope, filteredTransitions,
|
|
1730
|
+
function enterStates(currentState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
|
|
1742
1731
|
let nextState = currentState;
|
|
1743
1732
|
const statesToEnter = new Set();
|
|
1744
1733
|
// those are states that were directly targeted or indirectly targeted by the explicit target
|
|
@@ -1753,7 +1742,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
1753
1742
|
}
|
|
1754
1743
|
const completedNodes = new Set();
|
|
1755
1744
|
for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
|
|
1756
|
-
|
|
1745
|
+
mutStateNodeSet.add(stateNodeToEnter);
|
|
1757
1746
|
const actions = [];
|
|
1758
1747
|
|
|
1759
1748
|
// Add entry actions
|
|
@@ -1776,7 +1765,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
|
|
|
1776
1765
|
if (parent?.type === 'compound') {
|
|
1777
1766
|
internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
|
|
1778
1767
|
}
|
|
1779
|
-
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(
|
|
1768
|
+
while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
|
|
1780
1769
|
completedNodes.add(ancestorMarker);
|
|
1781
1770
|
internalQueue.push(createDoneStateEvent(ancestorMarker.id));
|
|
1782
1771
|
rootCompletionNode = ancestorMarker;
|
|
@@ -1886,9 +1875,9 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
|
|
|
1886
1875
|
function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
|
|
1887
1876
|
addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
|
|
1888
1877
|
}
|
|
1889
|
-
function exitStates(currentState, event, actorScope, transitions,
|
|
1878
|
+
function exitStates(currentState, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
|
|
1890
1879
|
let nextState = currentState;
|
|
1891
|
-
const statesToExit = computeExitSet(transitions,
|
|
1880
|
+
const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
|
|
1892
1881
|
statesToExit.sort((a, b) => b.order - a.order);
|
|
1893
1882
|
let changedHistory;
|
|
1894
1883
|
|
|
@@ -1906,12 +1895,12 @@ function exitStates(currentState, event, actorScope, transitions, mutConfigurati
|
|
|
1906
1895
|
changedHistory ??= {
|
|
1907
1896
|
...historyValue
|
|
1908
1897
|
};
|
|
1909
|
-
changedHistory[historyNode.id] = Array.from(
|
|
1898
|
+
changedHistory[historyNode.id] = Array.from(mutStateNodeSet).filter(predicate);
|
|
1910
1899
|
}
|
|
1911
1900
|
}
|
|
1912
1901
|
for (const s of statesToExit) {
|
|
1913
1902
|
nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
|
|
1914
|
-
|
|
1903
|
+
mutStateNodeSet.delete(s);
|
|
1915
1904
|
}
|
|
1916
1905
|
return [nextState, changedHistory || historyValue];
|
|
1917
1906
|
}
|
|
@@ -2040,7 +2029,7 @@ function selectTransitions(event, nextState) {
|
|
|
2040
2029
|
}
|
|
2041
2030
|
function selectEventlessTransitions(nextState, event) {
|
|
2042
2031
|
const enabledTransitionSet = new Set();
|
|
2043
|
-
const atomicStates = nextState.
|
|
2032
|
+
const atomicStates = nextState._nodes.filter(isAtomicStateNode);
|
|
2044
2033
|
for (const stateNode of atomicStates) {
|
|
2045
2034
|
loop: for (const s of [stateNode].concat(getProperAncestors(stateNode, undefined))) {
|
|
2046
2035
|
if (!s.always) {
|
|
@@ -2054,7 +2043,7 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
2054
2043
|
}
|
|
2055
2044
|
}
|
|
2056
2045
|
}
|
|
2057
|
-
return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState.
|
|
2046
|
+
return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState._nodes), nextState.historyValue);
|
|
2058
2047
|
}
|
|
2059
2048
|
|
|
2060
2049
|
/**
|
|
@@ -2063,8 +2052,8 @@ function selectEventlessTransitions(nextState, event) {
|
|
|
2063
2052
|
* @param stateValue The partial state value to resolve.
|
|
2064
2053
|
*/
|
|
2065
2054
|
function resolveStateValue(rootNode, stateValue) {
|
|
2066
|
-
const
|
|
2067
|
-
return getStateValue(rootNode, [...
|
|
2055
|
+
const allStateNodes = getAllStateNodes(getStateNodes(rootNode, stateValue));
|
|
2056
|
+
return getStateValue(rootNode, [...allStateNodes]);
|
|
2068
2057
|
}
|
|
2069
2058
|
|
|
2070
2059
|
function isMachineSnapshot(value) {
|
|
@@ -2084,10 +2073,11 @@ const machineSnapshotCan = function can(event) {
|
|
|
2084
2073
|
};
|
|
2085
2074
|
const machineSnapshotToJSON = function toJSON() {
|
|
2086
2075
|
const {
|
|
2087
|
-
|
|
2076
|
+
_nodes: nodes,
|
|
2088
2077
|
tags,
|
|
2089
2078
|
machine,
|
|
2090
|
-
|
|
2079
|
+
getNextEvents,
|
|
2080
|
+
getMeta,
|
|
2091
2081
|
toJSON,
|
|
2092
2082
|
can,
|
|
2093
2083
|
hasTag,
|
|
@@ -2099,13 +2089,11 @@ const machineSnapshotToJSON = function toJSON() {
|
|
|
2099
2089
|
tags: Array.from(tags)
|
|
2100
2090
|
};
|
|
2101
2091
|
};
|
|
2102
|
-
const
|
|
2103
|
-
return
|
|
2104
|
-
return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
|
|
2105
|
-
});
|
|
2092
|
+
const machineSnapshotGetNextEvents = function getNextEvents() {
|
|
2093
|
+
return [...new Set(flatten([...this._nodes.map(sn => sn.ownEvents)]))];
|
|
2106
2094
|
};
|
|
2107
|
-
const
|
|
2108
|
-
return this.
|
|
2095
|
+
const machineSnapshotGetMeta = function getMeta() {
|
|
2096
|
+
return this._nodes.reduce((acc, stateNode) => {
|
|
2109
2097
|
if (stateNode.meta !== undefined) {
|
|
2110
2098
|
acc[stateNode.id] = stateNode.meta;
|
|
2111
2099
|
}
|
|
@@ -2113,48 +2101,35 @@ const machineSnapshotMeta = function nextEvents() {
|
|
|
2113
2101
|
}, {});
|
|
2114
2102
|
};
|
|
2115
2103
|
function createMachineSnapshot(config, machine) {
|
|
2116
|
-
|
|
2104
|
+
return {
|
|
2117
2105
|
status: config.status,
|
|
2118
2106
|
output: config.output,
|
|
2119
2107
|
error: config.error,
|
|
2120
2108
|
machine,
|
|
2121
2109
|
context: config.context,
|
|
2122
|
-
|
|
2123
|
-
value: getStateValue(machine.root, config.
|
|
2124
|
-
tags: new Set(flatten(config.
|
|
2110
|
+
_nodes: config._nodes,
|
|
2111
|
+
value: getStateValue(machine.root, config._nodes),
|
|
2112
|
+
tags: new Set(flatten(config._nodes.map(sn => sn.tags))),
|
|
2125
2113
|
children: config.children,
|
|
2126
2114
|
historyValue: config.historyValue || {},
|
|
2127
2115
|
// this one is generic in the target and it's hard to create a matching non-generic source signature
|
|
2128
2116
|
matches: machineSnapshotMatches,
|
|
2129
2117
|
hasTag: machineSnapshotHasTag,
|
|
2130
2118
|
can: machineSnapshotCan,
|
|
2119
|
+
getNextEvents: machineSnapshotGetNextEvents,
|
|
2120
|
+
getMeta: machineSnapshotGetMeta,
|
|
2131
2121
|
toJSON: machineSnapshotToJSON
|
|
2132
2122
|
};
|
|
2133
|
-
Object.defineProperties(snapshot, {
|
|
2134
|
-
nextEvents: {
|
|
2135
|
-
get: machineSnapshotNextEvents,
|
|
2136
|
-
configurable: true,
|
|
2137
|
-
enumerable: true
|
|
2138
|
-
},
|
|
2139
|
-
meta: {
|
|
2140
|
-
get: machineSnapshotMeta,
|
|
2141
|
-
configurable: true,
|
|
2142
|
-
enumerable: true
|
|
2143
|
-
}
|
|
2144
|
-
});
|
|
2145
|
-
return snapshot;
|
|
2146
2123
|
}
|
|
2147
2124
|
function cloneMachineSnapshot(state, config = {}) {
|
|
2148
|
-
return createMachineSnapshot(
|
|
2149
|
-
// TODO: it's wasteful that this spread triggers getters
|
|
2150
|
-
{
|
|
2125
|
+
return createMachineSnapshot({
|
|
2151
2126
|
...state,
|
|
2152
2127
|
...config
|
|
2153
2128
|
}, state.machine);
|
|
2154
2129
|
}
|
|
2155
2130
|
function getPersistedState(state, options) {
|
|
2156
2131
|
const {
|
|
2157
|
-
|
|
2132
|
+
_nodes: nodes,
|
|
2158
2133
|
tags,
|
|
2159
2134
|
machine,
|
|
2160
2135
|
children,
|
|
@@ -2162,8 +2137,9 @@ function getPersistedState(state, options) {
|
|
|
2162
2137
|
can,
|
|
2163
2138
|
hasTag,
|
|
2164
2139
|
matches,
|
|
2140
|
+
getNextEvents,
|
|
2141
|
+
getMeta,
|
|
2165
2142
|
toJSON,
|
|
2166
|
-
nextEvents,
|
|
2167
2143
|
...jsonValues
|
|
2168
2144
|
} = state;
|
|
2169
2145
|
const childrenJson = {};
|
|
@@ -2172,7 +2148,8 @@ function getPersistedState(state, options) {
|
|
|
2172
2148
|
childrenJson[id] = {
|
|
2173
2149
|
state: child.getPersistedState(options),
|
|
2174
2150
|
src: child.src,
|
|
2175
|
-
systemId: child._systemId
|
|
2151
|
+
systemId: child._systemId,
|
|
2152
|
+
syncSnapshot: child._syncSnapshot
|
|
2176
2153
|
};
|
|
2177
2154
|
}
|
|
2178
2155
|
const persisted = {
|
|
@@ -2261,4 +2238,4 @@ function raise(eventOrExpr, options) {
|
|
|
2261
2238
|
return raise;
|
|
2262
2239
|
}
|
|
2263
2240
|
|
|
2264
|
-
export { $$ACTOR_TYPE as $,
|
|
2241
|
+
export { $$ACTOR_TYPE as $, resolveReferencedActor as A, createActor as B, Actor as C, interpret as D, isMachineSnapshot as E, matchesState as F, pathToStateValue as G, toObserver as H, and as I, not as J, or as K, stateIn as L, cancel as M, NULL_EVENT as N, raise as O, stop as P, spawn as Q, ProcessingStatus as R, STATE_DELIMITER as S, createErrorActorEvent as T, XSTATE_ERROR as U, XSTATE_STOP as X, toTransitionConfigArray as a, formatTransition as b, createInvokeId as c, formatInitialTransition as d, evaluateGuard as e, formatTransitions as f, getDelayedTransitions as g, getCandidates as h, getAllStateNodes as i, getStateNodes as j, createMachineSnapshot as k, isInFinalState as l, mapValues as m, isErrorActorEvent as n, cloneMachineSnapshot as o, macrostep as p, transitionNode as q, resolveStateValue as r, resolveActionsAndContext as s, toArray as t, createInitEvent as u, microstep as v, getInitialStateNodes as w, isStateId as x, getStateNodeByPath as y, getPersistedState as z };
|