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.
Files changed (48) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +93 -5
  8. package/actors/dist/xstate-actors.development.cjs.js +93 -5
  9. package/actors/dist/xstate-actors.development.esm.js +93 -5
  10. package/actors/dist/xstate-actors.esm.js +93 -5
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/declarations/src/State.d.ts +11 -11
  14. package/dist/declarations/src/StateMachine.d.ts +1 -1
  15. package/dist/declarations/src/actions/choose.d.ts +3 -3
  16. package/dist/declarations/src/actions/pure.d.ts +4 -4
  17. package/dist/declarations/src/actors/observable.d.ts +39 -0
  18. package/dist/declarations/src/actors/transition.d.ts +53 -4
  19. package/dist/declarations/src/{Machine.d.ts → createMachine.d.ts} +1 -1
  20. package/dist/declarations/src/guards.d.ts +26 -4
  21. package/dist/declarations/src/index.d.ts +2 -1
  22. package/dist/declarations/src/interpreter.d.ts +1 -0
  23. package/dist/declarations/src/setup.d.ts +32 -0
  24. package/dist/declarations/src/stateUtils.d.ts +7 -7
  25. package/dist/declarations/src/types.d.ts +16 -13
  26. package/dist/{raise-5854eaca.esm.js → raise-2b5a4e4c.esm.js} +82 -105
  27. package/dist/{raise-348cc74e.development.esm.js → raise-90139fbc.development.esm.js} +82 -105
  28. package/dist/{raise-ed700d14.development.cjs.js → raise-b3fb3c65.development.cjs.js} +82 -106
  29. package/dist/{raise-fb6f017b.cjs.js → raise-fabffc3d.cjs.js} +82 -106
  30. package/dist/{send-a0193bdb.development.esm.js → send-24cc8018.development.esm.js} +3 -28
  31. package/dist/{send-b7b4befa.esm.js → send-8e7e41e7.esm.js} +3 -28
  32. package/dist/{send-53e5693c.cjs.js → send-c124176f.cjs.js} +3 -28
  33. package/dist/{send-00466e37.development.cjs.js → send-d0bc7eed.development.cjs.js} +3 -28
  34. package/dist/xstate.cjs.js +46 -14
  35. package/dist/xstate.cjs.mjs +1 -0
  36. package/dist/xstate.development.cjs.js +46 -14
  37. package/dist/xstate.development.cjs.mjs +1 -0
  38. package/dist/xstate.development.esm.js +42 -11
  39. package/dist/xstate.esm.js +42 -11
  40. package/dist/xstate.umd.min.js +1 -1
  41. package/dist/xstate.umd.min.js.map +1 -1
  42. package/guards/dist/xstate-guards.cjs.js +1 -1
  43. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  44. package/guards/dist/xstate-guards.development.esm.js +1 -1
  45. package/guards/dist/xstate-guards.esm.js +1 -1
  46. package/guards/dist/xstate-guards.umd.min.js +1 -1
  47. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  48. package/package.json +1 -1
@@ -391,6 +391,7 @@ class Actor {
391
391
  this.logger = void 0;
392
392
  this._processingStatus = ProcessingStatus.NotStarted;
393
393
  this._parent = void 0;
394
+ this._syncSnapshot = void 0;
394
395
  this.ref = void 0;
395
396
  this._actorScope = void 0;
396
397
  this._systemId = void 0;
@@ -407,6 +408,7 @@ class Actor {
407
408
  clock,
408
409
  logger,
409
410
  parent,
411
+ syncSnapshot,
410
412
  id,
411
413
  systemId,
412
414
  inspect
@@ -421,6 +423,7 @@ class Actor {
421
423
  this.logger = logger;
422
424
  this.clock = clock;
423
425
  this._parent = parent;
426
+ this._syncSnapshot = syncSnapshot;
424
427
  this.options = resolvedOptions;
425
428
  this.src = resolvedOptions.src ?? logic;
426
429
  this.ref = this;
@@ -579,6 +582,19 @@ class Actor {
579
582
  // Do not restart the service if it is already started
580
583
  return this;
581
584
  }
585
+ if (this._syncSnapshot) {
586
+ this.subscribe({
587
+ next: snapshot => {
588
+ if (snapshot.status === 'active') {
589
+ this._parent.send({
590
+ type: `xstate.snapshot.${this.id}`,
591
+ snapshot
592
+ });
593
+ }
594
+ },
595
+ error: () => {}
596
+ });
597
+ }
582
598
  this.system._register(this.sessionId, this);
583
599
  if (this._systemId) {
584
600
  this.system._set(this._systemId, this);
@@ -864,20 +880,6 @@ const interpret = createActor;
864
880
  * @deprecated Use `Actor` instead.
865
881
  */
866
882
 
867
- const cache = new WeakMap();
868
- function memo(object, key, fn) {
869
- let memoizedData = cache.get(object);
870
- if (!memoizedData) {
871
- memoizedData = {
872
- [key]: fn()
873
- };
874
- cache.set(object, memoizedData);
875
- } else if (!(key in memoizedData)) {
876
- memoizedData[key] = fn();
877
- }
878
- return memoizedData[key];
879
- }
880
-
881
883
  function resolveCancel(_, state, actionArgs, actionParams, {
882
884
  sendId
883
885
  }) {
@@ -922,6 +924,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
922
924
  id: resolvedId,
923
925
  src,
924
926
  parent: actorScope?.self,
927
+ syncSnapshot,
925
928
  systemId,
926
929
  input: typeof input === 'function' ? input({
927
930
  context: state.context,
@@ -929,19 +932,6 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
929
932
  self: actorScope?.self
930
933
  }) : input
931
934
  });
932
- if (syncSnapshot) {
933
- actorRef.subscribe({
934
- next: snapshot => {
935
- if (snapshot.status === 'active') {
936
- actorScope.self.send({
937
- type: `xstate.snapshot.${id}`,
938
- snapshot
939
- });
940
- }
941
- },
942
- error: () => {}
943
- });
944
- }
945
935
  }
946
936
  if (!actorRef) {
947
937
  console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
@@ -1060,7 +1050,7 @@ function checkStateIn(state, _, {
1060
1050
  }) {
1061
1051
  if (typeof stateValue === 'string' && isStateId(stateValue)) {
1062
1052
  const target = state.machine.getStateNodeById(stateValue);
1063
- return state.configuration.some(sn => sn === target);
1053
+ return state._nodes.some(sn => sn === target);
1064
1054
  }
1065
1055
  return state.matches(stateValue);
1066
1056
  }
@@ -1179,26 +1169,25 @@ function getProperAncestors(stateNode, toStateNode) {
1179
1169
  }
1180
1170
  return ancestors;
1181
1171
  }
1182
- function getConfiguration(stateNodes) {
1183
- const configuration = new Set(stateNodes);
1184
- const configurationSet = new Set(stateNodes);
1185
- const adjList = getAdjList(configurationSet);
1172
+ function getAllStateNodes(stateNodes) {
1173
+ const nodeSet = new Set(stateNodes);
1174
+ const adjList = getAdjList(nodeSet);
1186
1175
 
1187
1176
  // add descendants
1188
- for (const s of configuration) {
1177
+ for (const s of nodeSet) {
1189
1178
  // if previously active, add existing child nodes
1190
1179
  if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
1191
- getInitialStateNodesWithTheirAncestors(s).forEach(sn => configurationSet.add(sn));
1180
+ getInitialStateNodesWithTheirAncestors(s).forEach(sn => nodeSet.add(sn));
1192
1181
  } else {
1193
1182
  if (s.type === 'parallel') {
1194
1183
  for (const child of getChildren(s)) {
1195
1184
  if (child.type === 'history') {
1196
1185
  continue;
1197
1186
  }
1198
- if (!configurationSet.has(child)) {
1187
+ if (!nodeSet.has(child)) {
1199
1188
  const initialStates = getInitialStateNodesWithTheirAncestors(child);
1200
1189
  for (const initialStateNode of initialStates) {
1201
- configurationSet.add(initialStateNode);
1190
+ nodeSet.add(initialStateNode);
1202
1191
  }
1203
1192
  }
1204
1193
  }
@@ -1207,14 +1196,14 @@ function getConfiguration(stateNodes) {
1207
1196
  }
1208
1197
 
1209
1198
  // add all ancestors
1210
- for (const s of configurationSet) {
1199
+ for (const s of nodeSet) {
1211
1200
  let m = s.parent;
1212
1201
  while (m) {
1213
- configurationSet.add(m);
1202
+ nodeSet.add(m);
1214
1203
  m = m.parent;
1215
1204
  }
1216
1205
  }
1217
- return configurationSet;
1206
+ return nodeSet;
1218
1207
  }
1219
1208
  function getValueFromAdj(baseNode, adjList) {
1220
1209
  const childStateNodes = adjList.get(baseNode);
@@ -1238,9 +1227,9 @@ function getValueFromAdj(baseNode, adjList) {
1238
1227
  }
1239
1228
  return stateValue;
1240
1229
  }
1241
- function getAdjList(configuration) {
1230
+ function getAdjList(stateNodes) {
1242
1231
  const adjList = new Map();
1243
- for (const s of configuration) {
1232
+ for (const s of stateNodes) {
1244
1233
  if (!adjList.has(s)) {
1245
1234
  adjList.set(s, []);
1246
1235
  }
@@ -1253,16 +1242,16 @@ function getAdjList(configuration) {
1253
1242
  }
1254
1243
  return adjList;
1255
1244
  }
1256
- function getStateValue(rootNode, configuration) {
1257
- const config = getConfiguration(configuration);
1245
+ function getStateValue(rootNode, stateNodes) {
1246
+ const config = getAllStateNodes(stateNodes);
1258
1247
  return getValueFromAdj(rootNode, getAdjList(config));
1259
1248
  }
1260
- function isInFinalState(configuration, stateNode) {
1249
+ function isInFinalState(stateNodeSet, stateNode) {
1261
1250
  if (stateNode.type === 'compound') {
1262
- return getChildren(stateNode).some(s => s.type === 'final' && configuration.has(s));
1251
+ return getChildren(stateNode).some(s => s.type === 'final' && stateNodeSet.has(s));
1263
1252
  }
1264
1253
  if (stateNode.type === 'parallel') {
1265
- return getChildren(stateNode).every(sn => isInFinalState(configuration, sn));
1254
+ return getChildren(stateNode).every(sn => isInFinalState(stateNodeSet, sn));
1266
1255
  }
1267
1256
  return stateNode.type === 'final';
1268
1257
  }
@@ -1633,13 +1622,13 @@ function hasIntersection(s1, s2) {
1633
1622
  }
1634
1623
  return false;
1635
1624
  }
1636
- function removeConflictingTransitions(enabledTransitions, configuration, historyValue) {
1625
+ function removeConflictingTransitions(enabledTransitions, stateNodeSet, historyValue) {
1637
1626
  const filteredTransitions = new Set();
1638
1627
  for (const t1 of enabledTransitions) {
1639
1628
  let t1Preempted = false;
1640
1629
  const transitionsToRemove = new Set();
1641
1630
  for (const t2 of filteredTransitions) {
1642
- if (hasIntersection(computeExitSet([t1], configuration, historyValue), computeExitSet([t2], configuration, historyValue))) {
1631
+ if (hasIntersection(computeExitSet([t1], stateNodeSet, historyValue), computeExitSet([t2], stateNodeSet, historyValue))) {
1643
1632
  if (isDescendant(t1.source, t2.source)) {
1644
1633
  transitionsToRemove.add(t2);
1645
1634
  } else {
@@ -1706,7 +1695,7 @@ function getTransitionDomain(transition, historyValue) {
1706
1695
  }
1707
1696
  return transition.source.machine.root;
1708
1697
  }
1709
- function computeExitSet(transitions, configuration, historyValue) {
1698
+ function computeExitSet(transitions, stateNodeSet, historyValue) {
1710
1699
  const statesToExit = new Set();
1711
1700
  for (const t of transitions) {
1712
1701
  if (t.target?.length) {
@@ -1714,7 +1703,7 @@ function computeExitSet(transitions, configuration, historyValue) {
1714
1703
  if (t.reenter && t.source === domain) {
1715
1704
  statesToExit.add(domain);
1716
1705
  }
1717
- for (const stateNode of configuration) {
1706
+ for (const stateNode of stateNodeSet) {
1718
1707
  if (isDescendant(stateNode, domain)) {
1719
1708
  statesToExit.add(stateNode);
1720
1709
  }
@@ -1723,12 +1712,12 @@ function computeExitSet(transitions, configuration, historyValue) {
1723
1712
  }
1724
1713
  return [...statesToExit];
1725
1714
  }
1726
- function areConfigurationsEqual(previousConfiguration, nextConfigurationSet) {
1727
- if (previousConfiguration.length !== nextConfigurationSet.size) {
1715
+ function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
1716
+ if (prevStateNodes.length !== nextStateNodeSet.size) {
1728
1717
  return false;
1729
1718
  }
1730
- for (const node of previousConfiguration) {
1731
- if (!nextConfigurationSet.has(node)) {
1719
+ for (const node of prevStateNodes) {
1720
+ if (!nextStateNodeSet.has(node)) {
1732
1721
  return false;
1733
1722
  }
1734
1723
  }
@@ -1742,31 +1731,31 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
1742
1731
  if (!transitions.length) {
1743
1732
  return currentState;
1744
1733
  }
1745
- const mutConfiguration = new Set(currentState.configuration);
1734
+ const mutStateNodeSet = new Set(currentState._nodes);
1746
1735
  let historyValue = currentState.historyValue;
1747
- const filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
1736
+ const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
1748
1737
  let nextState = currentState;
1749
1738
 
1750
1739
  // Exit states
1751
1740
  if (!isInitial) {
1752
- [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, historyValue, internalQueue);
1741
+ [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
1753
1742
  }
1754
1743
 
1755
1744
  // Execute transition content
1756
1745
  nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
1757
1746
 
1758
1747
  // Enter states
1759
- nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
1760
- const nextConfiguration = [...mutConfiguration];
1748
+ nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
1749
+ const nextStateNodes = [...mutStateNodeSet];
1761
1750
  if (nextState.status === 'done') {
1762
- nextState = resolveActionsAndContext(nextState, event, actorScope, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
1751
+ nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
1763
1752
  }
1764
1753
  try {
1765
- if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
1754
+ if (historyValue === currentState.historyValue && areStateNodeCollectionsEqual(currentState._nodes, mutStateNodeSet)) {
1766
1755
  return nextState;
1767
1756
  }
1768
1757
  return cloneMachineSnapshot(nextState, {
1769
- configuration: nextConfiguration,
1758
+ _nodes: nextStateNodes,
1770
1759
  historyValue
1771
1760
  });
1772
1761
  } catch (e) {
@@ -1782,7 +1771,7 @@ function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode
1782
1771
  const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
1783
1772
  return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
1784
1773
  }
1785
- function enterStates(currentState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
1774
+ function enterStates(currentState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
1786
1775
  let nextState = currentState;
1787
1776
  const statesToEnter = new Set();
1788
1777
  // those are states that were directly targeted or indirectly targeted by the explicit target
@@ -1797,7 +1786,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
1797
1786
  }
1798
1787
  const completedNodes = new Set();
1799
1788
  for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
1800
- mutConfiguration.add(stateNodeToEnter);
1789
+ mutStateNodeSet.add(stateNodeToEnter);
1801
1790
  const actions = [];
1802
1791
 
1803
1792
  // Add entry actions
@@ -1820,7 +1809,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
1820
1809
  if (parent?.type === 'compound') {
1821
1810
  internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
1822
1811
  }
1823
- while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutConfiguration, ancestorMarker)) {
1812
+ while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
1824
1813
  completedNodes.add(ancestorMarker);
1825
1814
  internalQueue.push(createDoneStateEvent(ancestorMarker.id));
1826
1815
  rootCompletionNode = ancestorMarker;
@@ -1930,9 +1919,9 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
1930
1919
  function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1931
1920
  addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
1932
1921
  }
1933
- function exitStates(currentState, event, actorScope, transitions, mutConfiguration, historyValue, internalQueue) {
1922
+ function exitStates(currentState, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
1934
1923
  let nextState = currentState;
1935
- const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
1924
+ const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
1936
1925
  statesToExit.sort((a, b) => b.order - a.order);
1937
1926
  let changedHistory;
1938
1927
 
@@ -1950,12 +1939,12 @@ function exitStates(currentState, event, actorScope, transitions, mutConfigurati
1950
1939
  changedHistory ??= {
1951
1940
  ...historyValue
1952
1941
  };
1953
- changedHistory[historyNode.id] = Array.from(mutConfiguration).filter(predicate);
1942
+ changedHistory[historyNode.id] = Array.from(mutStateNodeSet).filter(predicate);
1954
1943
  }
1955
1944
  }
1956
1945
  for (const s of statesToExit) {
1957
1946
  nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
1958
- mutConfiguration.delete(s);
1947
+ mutStateNodeSet.delete(s);
1959
1948
  }
1960
1949
  return [nextState, changedHistory || historyValue];
1961
1950
  }
@@ -2087,7 +2076,7 @@ function selectTransitions(event, nextState) {
2087
2076
  }
2088
2077
  function selectEventlessTransitions(nextState, event) {
2089
2078
  const enabledTransitionSet = new Set();
2090
- const atomicStates = nextState.configuration.filter(isAtomicStateNode);
2079
+ const atomicStates = nextState._nodes.filter(isAtomicStateNode);
2091
2080
  for (const stateNode of atomicStates) {
2092
2081
  loop: for (const s of [stateNode].concat(getProperAncestors(stateNode, undefined))) {
2093
2082
  if (!s.always) {
@@ -2101,7 +2090,7 @@ function selectEventlessTransitions(nextState, event) {
2101
2090
  }
2102
2091
  }
2103
2092
  }
2104
- return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState.configuration), nextState.historyValue);
2093
+ return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState._nodes), nextState.historyValue);
2105
2094
  }
2106
2095
 
2107
2096
  /**
@@ -2110,8 +2099,8 @@ function selectEventlessTransitions(nextState, event) {
2110
2099
  * @param stateValue The partial state value to resolve.
2111
2100
  */
2112
2101
  function resolveStateValue(rootNode, stateValue) {
2113
- const configuration = getConfiguration(getStateNodes(rootNode, stateValue));
2114
- return getStateValue(rootNode, [...configuration]);
2102
+ const allStateNodes = getAllStateNodes(getStateNodes(rootNode, stateValue));
2103
+ return getStateValue(rootNode, [...allStateNodes]);
2115
2104
  }
2116
2105
 
2117
2106
  function isMachineSnapshot(value) {
@@ -2134,10 +2123,11 @@ const machineSnapshotCan = function can(event) {
2134
2123
  };
2135
2124
  const machineSnapshotToJSON = function toJSON() {
2136
2125
  const {
2137
- configuration,
2126
+ _nodes: nodes,
2138
2127
  tags,
2139
2128
  machine,
2140
- nextEvents,
2129
+ getNextEvents,
2130
+ getMeta,
2141
2131
  toJSON,
2142
2132
  can,
2143
2133
  hasTag,
@@ -2149,13 +2139,11 @@ const machineSnapshotToJSON = function toJSON() {
2149
2139
  tags: Array.from(tags)
2150
2140
  };
2151
2141
  };
2152
- const machineSnapshotNextEvents = function nextEvents() {
2153
- return memo(this, 'nextEvents', () => {
2154
- return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
2155
- });
2142
+ const machineSnapshotGetNextEvents = function getNextEvents() {
2143
+ return [...new Set(flatten([...this._nodes.map(sn => sn.ownEvents)]))];
2156
2144
  };
2157
- const machineSnapshotMeta = function nextEvents() {
2158
- return this.configuration.reduce((acc, stateNode) => {
2145
+ const machineSnapshotGetMeta = function getMeta() {
2146
+ return this._nodes.reduce((acc, stateNode) => {
2159
2147
  if (stateNode.meta !== undefined) {
2160
2148
  acc[stateNode.id] = stateNode.meta;
2161
2149
  }
@@ -2163,48 +2151,35 @@ const machineSnapshotMeta = function nextEvents() {
2163
2151
  }, {});
2164
2152
  };
2165
2153
  function createMachineSnapshot(config, machine) {
2166
- const snapshot = {
2154
+ return {
2167
2155
  status: config.status,
2168
2156
  output: config.output,
2169
2157
  error: config.error,
2170
2158
  machine,
2171
2159
  context: config.context,
2172
- configuration: config.configuration,
2173
- value: getStateValue(machine.root, config.configuration),
2174
- tags: new Set(flatten(config.configuration.map(sn => sn.tags))),
2160
+ _nodes: config._nodes,
2161
+ value: getStateValue(machine.root, config._nodes),
2162
+ tags: new Set(flatten(config._nodes.map(sn => sn.tags))),
2175
2163
  children: config.children,
2176
2164
  historyValue: config.historyValue || {},
2177
2165
  // this one is generic in the target and it's hard to create a matching non-generic source signature
2178
2166
  matches: machineSnapshotMatches,
2179
2167
  hasTag: machineSnapshotHasTag,
2180
2168
  can: machineSnapshotCan,
2169
+ getNextEvents: machineSnapshotGetNextEvents,
2170
+ getMeta: machineSnapshotGetMeta,
2181
2171
  toJSON: machineSnapshotToJSON
2182
2172
  };
2183
- Object.defineProperties(snapshot, {
2184
- nextEvents: {
2185
- get: machineSnapshotNextEvents,
2186
- configurable: true,
2187
- enumerable: true
2188
- },
2189
- meta: {
2190
- get: machineSnapshotMeta,
2191
- configurable: true,
2192
- enumerable: true
2193
- }
2194
- });
2195
- return snapshot;
2196
2173
  }
2197
2174
  function cloneMachineSnapshot(state, config = {}) {
2198
- return createMachineSnapshot(
2199
- // TODO: it's wasteful that this spread triggers getters
2200
- {
2175
+ return createMachineSnapshot({
2201
2176
  ...state,
2202
2177
  ...config
2203
2178
  }, state.machine);
2204
2179
  }
2205
2180
  function getPersistedState(state, options) {
2206
2181
  const {
2207
- configuration,
2182
+ _nodes: nodes,
2208
2183
  tags,
2209
2184
  machine,
2210
2185
  children,
@@ -2212,8 +2187,9 @@ function getPersistedState(state, options) {
2212
2187
  can,
2213
2188
  hasTag,
2214
2189
  matches,
2190
+ getNextEvents,
2191
+ getMeta,
2215
2192
  toJSON,
2216
- nextEvents,
2217
2193
  ...jsonValues
2218
2194
  } = state;
2219
2195
  const childrenJson = {};
@@ -2225,7 +2201,8 @@ function getPersistedState(state, options) {
2225
2201
  childrenJson[id] = {
2226
2202
  state: child.getPersistedState(options),
2227
2203
  src: child.src,
2228
- systemId: child._systemId
2204
+ systemId: child._systemId,
2205
+ syncSnapshot: child._syncSnapshot
2229
2206
  };
2230
2207
  }
2231
2208
  const persisted = {
@@ -2336,8 +2313,8 @@ exports.evaluateGuard = evaluateGuard;
2336
2313
  exports.formatInitialTransition = formatInitialTransition;
2337
2314
  exports.formatTransition = formatTransition;
2338
2315
  exports.formatTransitions = formatTransitions;
2316
+ exports.getAllStateNodes = getAllStateNodes;
2339
2317
  exports.getCandidates = getCandidates;
2340
- exports.getConfiguration = getConfiguration;
2341
2318
  exports.getDelayedTransitions = getDelayedTransitions;
2342
2319
  exports.getInitialStateNodes = getInitialStateNodes;
2343
2320
  exports.getPersistedState = getPersistedState;
@@ -2351,7 +2328,6 @@ exports.isStateId = isStateId;
2351
2328
  exports.macrostep = macrostep;
2352
2329
  exports.mapValues = mapValues;
2353
2330
  exports.matchesState = matchesState;
2354
- exports.memo = memo;
2355
2331
  exports.microstep = microstep;
2356
2332
  exports.not = not;
2357
2333
  exports.or = or;