xstate 5.0.0-beta.44 → 5.0.0-beta.46

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 (51) 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 +134 -9
  8. package/actors/dist/xstate-actors.development.cjs.js +134 -9
  9. package/actors/dist/xstate-actors.development.esm.js +134 -9
  10. package/actors/dist/xstate-actors.esm.js +134 -9
  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 +18 -28
  14. package/dist/declarations/src/StateMachine.d.ts +11 -29
  15. package/dist/declarations/src/StateNode.d.ts +8 -6
  16. package/dist/declarations/src/actions/choose.d.ts +3 -3
  17. package/dist/declarations/src/actions/pure.d.ts +4 -4
  18. package/dist/declarations/src/actors/observable.d.ts +80 -4
  19. package/dist/declarations/src/actors/transition.d.ts +53 -4
  20. package/dist/declarations/src/createMachine.d.ts +5 -0
  21. package/dist/declarations/src/guards.d.ts +26 -4
  22. package/dist/declarations/src/index.d.ts +3 -2
  23. package/dist/declarations/src/interpreter.d.ts +1 -0
  24. package/dist/declarations/src/setup.d.ts +35 -0
  25. package/dist/declarations/src/stateUtils.d.ts +7 -7
  26. package/dist/declarations/src/types.d.ts +54 -25
  27. package/dist/declarations/src/utils.d.ts +2 -1
  28. package/dist/{raise-5854eaca.esm.js → raise-1682abb7.esm.js} +99 -135
  29. package/dist/{raise-fb6f017b.cjs.js → raise-a1d3d7e9.cjs.js} +100 -136
  30. package/dist/{raise-ed700d14.development.cjs.js → raise-a9e7e31c.development.cjs.js} +100 -136
  31. package/dist/{raise-348cc74e.development.esm.js → raise-fa23c2b9.development.esm.js} +99 -135
  32. package/dist/{send-53e5693c.cjs.js → send-2fa3a204.cjs.js} +24 -28
  33. package/dist/{send-00466e37.development.cjs.js → send-5b256a89.development.cjs.js} +24 -28
  34. package/dist/{send-a0193bdb.development.esm.js → send-9acdf858.development.esm.js} +24 -28
  35. package/dist/{send-b7b4befa.esm.js → send-a237e4e8.esm.js} +24 -28
  36. package/dist/xstate.cjs.js +102 -92
  37. package/dist/xstate.cjs.mjs +2 -0
  38. package/dist/xstate.development.cjs.js +102 -92
  39. package/dist/xstate.development.cjs.mjs +2 -0
  40. package/dist/xstate.development.esm.js +97 -89
  41. package/dist/xstate.esm.js +97 -89
  42. package/dist/xstate.umd.min.js +1 -1
  43. package/dist/xstate.umd.min.js.map +1 -1
  44. package/guards/dist/xstate-guards.cjs.js +1 -1
  45. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  46. package/guards/dist/xstate-guards.development.esm.js +1 -1
  47. package/guards/dist/xstate-guards.esm.js +1 -1
  48. package/guards/dist/xstate-guards.umd.min.js +1 -1
  49. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/declarations/src/Machine.d.ts +0 -5
@@ -321,6 +321,9 @@ function resolveReferencedActor(machine, src) {
321
321
  }
322
322
  return machine.implementations.actors[src];
323
323
  }
324
+ function getAllOwnEventDescriptors(snapshot) {
325
+ return [...new Set(flatten([...snapshot._nodes.map(sn => sn.ownEvents)]))];
326
+ }
324
327
 
325
328
  const $$ACTOR_TYPE = 1;
326
329
  // those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
@@ -347,32 +350,6 @@ const defaultOptions = {
347
350
  * An Actor is a running process that can receive events, send events and change its behavior based on the events it receives, which can cause effects outside of the actor. When you run a state machine, it becomes an actor.
348
351
  */
349
352
  class Actor {
350
- /**
351
- * The current internal state of the actor.
352
- */
353
-
354
- /**
355
- * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
356
- */
357
-
358
- /**
359
- * The unique identifier for this actor relative to its parent.
360
- */
361
-
362
- /** @internal */
363
-
364
- // Actor Ref
365
-
366
- // TODO: add typings for system
367
-
368
- /**
369
- * The globally unique process ID for this invocation.
370
- */
371
-
372
- /**
373
- * The system to which this actor belongs.
374
- */
375
-
376
353
  /**
377
354
  * Creates a new actor instance for the given logic with the provided options, if any.
378
355
  *
@@ -381,23 +358,43 @@ class Actor {
381
358
  */
382
359
  constructor(logic, options) {
383
360
  this.logic = logic;
361
+ /**
362
+ * The current internal state of the actor.
363
+ */
384
364
  this._state = void 0;
365
+ /**
366
+ * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
367
+ */
385
368
  this.clock = void 0;
386
369
  this.options = void 0;
370
+ /**
371
+ * The unique identifier for this actor relative to its parent.
372
+ */
387
373
  this.id = void 0;
388
374
  this.mailbox = new Mailbox(this._process.bind(this));
389
375
  this.delayedEventsMap = {};
390
376
  this.observers = new Set();
391
377
  this.logger = void 0;
378
+ /** @internal */
392
379
  this._processingStatus = ProcessingStatus.NotStarted;
380
+ // Actor Ref
393
381
  this._parent = void 0;
382
+ this._syncSnapshot = void 0;
394
383
  this.ref = void 0;
384
+ // TODO: add typings for system
395
385
  this._actorScope = void 0;
396
386
  this._systemId = void 0;
387
+ /**
388
+ * The globally unique process ID for this invocation.
389
+ */
397
390
  this.sessionId = void 0;
391
+ /**
392
+ * The system to which this actor belongs.
393
+ */
398
394
  this.system = void 0;
399
395
  this._doneEvent = void 0;
400
396
  this.src = void 0;
397
+ // array of functions to defer
401
398
  this._deferred = [];
402
399
  const resolvedOptions = {
403
400
  ...defaultOptions,
@@ -407,6 +404,7 @@ class Actor {
407
404
  clock,
408
405
  logger,
409
406
  parent,
407
+ syncSnapshot,
410
408
  id,
411
409
  systemId,
412
410
  inspect
@@ -421,6 +419,7 @@ class Actor {
421
419
  this.logger = logger;
422
420
  this.clock = clock;
423
421
  this._parent = parent;
422
+ this._syncSnapshot = syncSnapshot;
424
423
  this.options = resolvedOptions;
425
424
  this.src = resolvedOptions.src ?? logic;
426
425
  this.ref = this;
@@ -460,9 +459,6 @@ class Actor {
460
459
  _initState(persistedState) {
461
460
  this._state = persistedState ? this.logic.restoreState ? this.logic.restoreState(persistedState, this._actorScope) : persistedState : this.logic.getInitialState(this._actorScope, this.options?.input);
462
461
  }
463
-
464
- // array of functions to defer
465
-
466
462
  update(snapshot, event) {
467
463
  // Update state
468
464
  this._state = snapshot;
@@ -579,6 +575,19 @@ class Actor {
579
575
  // Do not restart the service if it is already started
580
576
  return this;
581
577
  }
578
+ if (this._syncSnapshot) {
579
+ this.subscribe({
580
+ next: snapshot => {
581
+ if (snapshot.status === 'active') {
582
+ this._parent.send({
583
+ type: `xstate.snapshot.${this.id}`,
584
+ snapshot
585
+ });
586
+ }
587
+ },
588
+ error: () => {}
589
+ });
590
+ }
582
591
  this.system._register(this.sessionId, this);
583
592
  if (this._systemId) {
584
593
  this.system._set(this._systemId, this);
@@ -864,20 +873,6 @@ const interpret = createActor;
864
873
  * @deprecated Use `Actor` instead.
865
874
  */
866
875
 
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
876
  function resolveCancel(_, state, actionArgs, actionParams, {
882
877
  sendId
883
878
  }) {
@@ -922,6 +917,7 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
922
917
  id: resolvedId,
923
918
  src,
924
919
  parent: actorScope?.self,
920
+ syncSnapshot,
925
921
  systemId,
926
922
  input: typeof input === 'function' ? input({
927
923
  context: state.context,
@@ -929,19 +925,6 @@ function resolveSpawn(actorScope, state, actionArgs, _actionParams, {
929
925
  self: actorScope?.self
930
926
  }) : input
931
927
  });
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
928
  }
946
929
  if (!actorRef) {
947
930
  console.warn(`Actor type '${src}' not found in machine '${actorScope.id}'.`);
@@ -1060,7 +1043,7 @@ function checkStateIn(state, _, {
1060
1043
  }) {
1061
1044
  if (typeof stateValue === 'string' && isStateId(stateValue)) {
1062
1045
  const target = state.machine.getStateNodeById(stateValue);
1063
- return state.configuration.some(sn => sn === target);
1046
+ return state._nodes.some(sn => sn === target);
1064
1047
  }
1065
1048
  return state.matches(stateValue);
1066
1049
  }
@@ -1179,26 +1162,25 @@ function getProperAncestors(stateNode, toStateNode) {
1179
1162
  }
1180
1163
  return ancestors;
1181
1164
  }
1182
- function getConfiguration(stateNodes) {
1183
- const configuration = new Set(stateNodes);
1184
- const configurationSet = new Set(stateNodes);
1185
- const adjList = getAdjList(configurationSet);
1165
+ function getAllStateNodes(stateNodes) {
1166
+ const nodeSet = new Set(stateNodes);
1167
+ const adjList = getAdjList(nodeSet);
1186
1168
 
1187
1169
  // add descendants
1188
- for (const s of configuration) {
1170
+ for (const s of nodeSet) {
1189
1171
  // if previously active, add existing child nodes
1190
1172
  if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
1191
- getInitialStateNodesWithTheirAncestors(s).forEach(sn => configurationSet.add(sn));
1173
+ getInitialStateNodesWithTheirAncestors(s).forEach(sn => nodeSet.add(sn));
1192
1174
  } else {
1193
1175
  if (s.type === 'parallel') {
1194
1176
  for (const child of getChildren(s)) {
1195
1177
  if (child.type === 'history') {
1196
1178
  continue;
1197
1179
  }
1198
- if (!configurationSet.has(child)) {
1180
+ if (!nodeSet.has(child)) {
1199
1181
  const initialStates = getInitialStateNodesWithTheirAncestors(child);
1200
1182
  for (const initialStateNode of initialStates) {
1201
- configurationSet.add(initialStateNode);
1183
+ nodeSet.add(initialStateNode);
1202
1184
  }
1203
1185
  }
1204
1186
  }
@@ -1207,14 +1189,14 @@ function getConfiguration(stateNodes) {
1207
1189
  }
1208
1190
 
1209
1191
  // add all ancestors
1210
- for (const s of configurationSet) {
1192
+ for (const s of nodeSet) {
1211
1193
  let m = s.parent;
1212
1194
  while (m) {
1213
- configurationSet.add(m);
1195
+ nodeSet.add(m);
1214
1196
  m = m.parent;
1215
1197
  }
1216
1198
  }
1217
- return configurationSet;
1199
+ return nodeSet;
1218
1200
  }
1219
1201
  function getValueFromAdj(baseNode, adjList) {
1220
1202
  const childStateNodes = adjList.get(baseNode);
@@ -1238,9 +1220,9 @@ function getValueFromAdj(baseNode, adjList) {
1238
1220
  }
1239
1221
  return stateValue;
1240
1222
  }
1241
- function getAdjList(configuration) {
1223
+ function getAdjList(stateNodes) {
1242
1224
  const adjList = new Map();
1243
- for (const s of configuration) {
1225
+ for (const s of stateNodes) {
1244
1226
  if (!adjList.has(s)) {
1245
1227
  adjList.set(s, []);
1246
1228
  }
@@ -1253,16 +1235,16 @@ function getAdjList(configuration) {
1253
1235
  }
1254
1236
  return adjList;
1255
1237
  }
1256
- function getStateValue(rootNode, configuration) {
1257
- const config = getConfiguration(configuration);
1238
+ function getStateValue(rootNode, stateNodes) {
1239
+ const config = getAllStateNodes(stateNodes);
1258
1240
  return getValueFromAdj(rootNode, getAdjList(config));
1259
1241
  }
1260
- function isInFinalState(configuration, stateNode) {
1242
+ function isInFinalState(stateNodeSet, stateNode) {
1261
1243
  if (stateNode.type === 'compound') {
1262
- return getChildren(stateNode).some(s => s.type === 'final' && configuration.has(s));
1244
+ return getChildren(stateNode).some(s => s.type === 'final' && stateNodeSet.has(s));
1263
1245
  }
1264
1246
  if (stateNode.type === 'parallel') {
1265
- return getChildren(stateNode).every(sn => isInFinalState(configuration, sn));
1247
+ return getChildren(stateNode).every(sn => isInFinalState(stateNodeSet, sn));
1266
1248
  }
1267
1249
  return stateNode.type === 'final';
1268
1250
  }
@@ -1633,13 +1615,13 @@ function hasIntersection(s1, s2) {
1633
1615
  }
1634
1616
  return false;
1635
1617
  }
1636
- function removeConflictingTransitions(enabledTransitions, configuration, historyValue) {
1618
+ function removeConflictingTransitions(enabledTransitions, stateNodeSet, historyValue) {
1637
1619
  const filteredTransitions = new Set();
1638
1620
  for (const t1 of enabledTransitions) {
1639
1621
  let t1Preempted = false;
1640
1622
  const transitionsToRemove = new Set();
1641
1623
  for (const t2 of filteredTransitions) {
1642
- if (hasIntersection(computeExitSet([t1], configuration, historyValue), computeExitSet([t2], configuration, historyValue))) {
1624
+ if (hasIntersection(computeExitSet([t1], stateNodeSet, historyValue), computeExitSet([t2], stateNodeSet, historyValue))) {
1643
1625
  if (isDescendant(t1.source, t2.source)) {
1644
1626
  transitionsToRemove.add(t2);
1645
1627
  } else {
@@ -1706,7 +1688,7 @@ function getTransitionDomain(transition, historyValue) {
1706
1688
  }
1707
1689
  return transition.source.machine.root;
1708
1690
  }
1709
- function computeExitSet(transitions, configuration, historyValue) {
1691
+ function computeExitSet(transitions, stateNodeSet, historyValue) {
1710
1692
  const statesToExit = new Set();
1711
1693
  for (const t of transitions) {
1712
1694
  if (t.target?.length) {
@@ -1714,7 +1696,7 @@ function computeExitSet(transitions, configuration, historyValue) {
1714
1696
  if (t.reenter && t.source === domain) {
1715
1697
  statesToExit.add(domain);
1716
1698
  }
1717
- for (const stateNode of configuration) {
1699
+ for (const stateNode of stateNodeSet) {
1718
1700
  if (isDescendant(stateNode, domain)) {
1719
1701
  statesToExit.add(stateNode);
1720
1702
  }
@@ -1723,12 +1705,12 @@ function computeExitSet(transitions, configuration, historyValue) {
1723
1705
  }
1724
1706
  return [...statesToExit];
1725
1707
  }
1726
- function areConfigurationsEqual(previousConfiguration, nextConfigurationSet) {
1727
- if (previousConfiguration.length !== nextConfigurationSet.size) {
1708
+ function areStateNodeCollectionsEqual(prevStateNodes, nextStateNodeSet) {
1709
+ if (prevStateNodes.length !== nextStateNodeSet.size) {
1728
1710
  return false;
1729
1711
  }
1730
- for (const node of previousConfiguration) {
1731
- if (!nextConfigurationSet.has(node)) {
1712
+ for (const node of prevStateNodes) {
1713
+ if (!nextStateNodeSet.has(node)) {
1732
1714
  return false;
1733
1715
  }
1734
1716
  }
@@ -1742,31 +1724,31 @@ function microstep(transitions, currentState, actorScope, event, isInitial, inte
1742
1724
  if (!transitions.length) {
1743
1725
  return currentState;
1744
1726
  }
1745
- const mutConfiguration = new Set(currentState.configuration);
1727
+ const mutStateNodeSet = new Set(currentState._nodes);
1746
1728
  let historyValue = currentState.historyValue;
1747
- const filteredTransitions = removeConflictingTransitions(transitions, mutConfiguration, historyValue);
1729
+ const filteredTransitions = removeConflictingTransitions(transitions, mutStateNodeSet, historyValue);
1748
1730
  let nextState = currentState;
1749
1731
 
1750
1732
  // Exit states
1751
1733
  if (!isInitial) {
1752
- [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, historyValue, internalQueue);
1734
+ [nextState, historyValue] = exitStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, historyValue, internalQueue);
1753
1735
  }
1754
1736
 
1755
1737
  // Execute transition content
1756
1738
  nextState = resolveActionsAndContext(nextState, event, actorScope, filteredTransitions.flatMap(t => t.actions), internalQueue);
1757
1739
 
1758
1740
  // Enter states
1759
- nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial);
1760
- const nextConfiguration = [...mutConfiguration];
1741
+ nextState = enterStates(nextState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial);
1742
+ const nextStateNodes = [...mutStateNodeSet];
1761
1743
  if (nextState.status === 'done') {
1762
- nextState = resolveActionsAndContext(nextState, event, actorScope, nextConfiguration.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
1744
+ nextState = resolveActionsAndContext(nextState, event, actorScope, nextStateNodes.sort((a, b) => b.order - a.order).flatMap(state => state.exit), internalQueue);
1763
1745
  }
1764
1746
  try {
1765
- if (historyValue === currentState.historyValue && areConfigurationsEqual(currentState.configuration, mutConfiguration)) {
1747
+ if (historyValue === currentState.historyValue && areStateNodeCollectionsEqual(currentState._nodes, mutStateNodeSet)) {
1766
1748
  return nextState;
1767
1749
  }
1768
1750
  return cloneMachineSnapshot(nextState, {
1769
- configuration: nextConfiguration,
1751
+ _nodes: nextStateNodes,
1770
1752
  historyValue
1771
1753
  });
1772
1754
  } catch (e) {
@@ -1782,7 +1764,7 @@ function getMachineOutput(state, event, actorScope, rootNode, rootCompletionNode
1782
1764
  const doneStateEvent = createDoneStateEvent(rootCompletionNode.id, rootCompletionNode.output && rootCompletionNode.parent ? resolveOutput(rootCompletionNode.output, state.context, event, actorScope.self) : undefined);
1783
1765
  return resolveOutput(rootNode.output, state.context, doneStateEvent, actorScope.self);
1784
1766
  }
1785
- function enterStates(currentState, event, actorScope, filteredTransitions, mutConfiguration, internalQueue, historyValue, isInitial) {
1767
+ function enterStates(currentState, event, actorScope, filteredTransitions, mutStateNodeSet, internalQueue, historyValue, isInitial) {
1786
1768
  let nextState = currentState;
1787
1769
  const statesToEnter = new Set();
1788
1770
  // those are states that were directly targeted or indirectly targeted by the explicit target
@@ -1797,7 +1779,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
1797
1779
  }
1798
1780
  const completedNodes = new Set();
1799
1781
  for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
1800
- mutConfiguration.add(stateNodeToEnter);
1782
+ mutStateNodeSet.add(stateNodeToEnter);
1801
1783
  const actions = [];
1802
1784
 
1803
1785
  // Add entry actions
@@ -1820,7 +1802,7 @@ function enterStates(currentState, event, actorScope, filteredTransitions, mutCo
1820
1802
  if (parent?.type === 'compound') {
1821
1803
  internalQueue.push(createDoneStateEvent(parent.id, stateNodeToEnter.output ? resolveOutput(stateNodeToEnter.output, nextState.context, event, actorScope.self) : undefined));
1822
1804
  }
1823
- while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutConfiguration, ancestorMarker)) {
1805
+ while (ancestorMarker?.type === 'parallel' && !completedNodes.has(ancestorMarker) && isInFinalState(mutStateNodeSet, ancestorMarker)) {
1824
1806
  completedNodes.add(ancestorMarker);
1825
1807
  internalQueue.push(createDoneStateEvent(ancestorMarker.id));
1826
1808
  rootCompletionNode = ancestorMarker;
@@ -1930,9 +1912,9 @@ function addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultE
1930
1912
  function addProperAncestorStatesToEnter(stateNode, toStateNode, statesToEnter, historyValue, statesForDefaultEntry) {
1931
1913
  addAncestorStatesToEnter(statesToEnter, historyValue, statesForDefaultEntry, getProperAncestors(stateNode, toStateNode));
1932
1914
  }
1933
- function exitStates(currentState, event, actorScope, transitions, mutConfiguration, historyValue, internalQueue) {
1915
+ function exitStates(currentState, event, actorScope, transitions, mutStateNodeSet, historyValue, internalQueue) {
1934
1916
  let nextState = currentState;
1935
- const statesToExit = computeExitSet(transitions, mutConfiguration, historyValue);
1917
+ const statesToExit = computeExitSet(transitions, mutStateNodeSet, historyValue);
1936
1918
  statesToExit.sort((a, b) => b.order - a.order);
1937
1919
  let changedHistory;
1938
1920
 
@@ -1950,12 +1932,12 @@ function exitStates(currentState, event, actorScope, transitions, mutConfigurati
1950
1932
  changedHistory ??= {
1951
1933
  ...historyValue
1952
1934
  };
1953
- changedHistory[historyNode.id] = Array.from(mutConfiguration).filter(predicate);
1935
+ changedHistory[historyNode.id] = Array.from(mutStateNodeSet).filter(predicate);
1954
1936
  }
1955
1937
  }
1956
1938
  for (const s of statesToExit) {
1957
1939
  nextState = resolveActionsAndContext(nextState, event, actorScope, [...s.exit, ...s.invoke.map(def => stop(def.id))], internalQueue);
1958
- mutConfiguration.delete(s);
1940
+ mutStateNodeSet.delete(s);
1959
1941
  }
1960
1942
  return [nextState, changedHistory || historyValue];
1961
1943
  }
@@ -2087,7 +2069,7 @@ function selectTransitions(event, nextState) {
2087
2069
  }
2088
2070
  function selectEventlessTransitions(nextState, event) {
2089
2071
  const enabledTransitionSet = new Set();
2090
- const atomicStates = nextState.configuration.filter(isAtomicStateNode);
2072
+ const atomicStates = nextState._nodes.filter(isAtomicStateNode);
2091
2073
  for (const stateNode of atomicStates) {
2092
2074
  loop: for (const s of [stateNode].concat(getProperAncestors(stateNode, undefined))) {
2093
2075
  if (!s.always) {
@@ -2101,7 +2083,7 @@ function selectEventlessTransitions(nextState, event) {
2101
2083
  }
2102
2084
  }
2103
2085
  }
2104
- return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState.configuration), nextState.historyValue);
2086
+ return removeConflictingTransitions(Array.from(enabledTransitionSet), new Set(nextState._nodes), nextState.historyValue);
2105
2087
  }
2106
2088
 
2107
2089
  /**
@@ -2110,8 +2092,8 @@ function selectEventlessTransitions(nextState, event) {
2110
2092
  * @param stateValue The partial state value to resolve.
2111
2093
  */
2112
2094
  function resolveStateValue(rootNode, stateValue) {
2113
- const configuration = getConfiguration(getStateNodes(rootNode, stateValue));
2114
- return getStateValue(rootNode, [...configuration]);
2095
+ const allStateNodes = getAllStateNodes(getStateNodes(rootNode, stateValue));
2096
+ return getStateValue(rootNode, [...allStateNodes]);
2115
2097
  }
2116
2098
 
2117
2099
  function isMachineSnapshot(value) {
@@ -2134,10 +2116,10 @@ const machineSnapshotCan = function can(event) {
2134
2116
  };
2135
2117
  const machineSnapshotToJSON = function toJSON() {
2136
2118
  const {
2137
- configuration,
2119
+ _nodes: nodes,
2138
2120
  tags,
2139
2121
  machine,
2140
- nextEvents,
2122
+ getMeta,
2141
2123
  toJSON,
2142
2124
  can,
2143
2125
  hasTag,
@@ -2149,13 +2131,8 @@ const machineSnapshotToJSON = function toJSON() {
2149
2131
  tags: Array.from(tags)
2150
2132
  };
2151
2133
  };
2152
- const machineSnapshotNextEvents = function nextEvents() {
2153
- return memo(this, 'nextEvents', () => {
2154
- return [...new Set(flatten([...this.configuration.map(sn => sn.ownEvents)]))];
2155
- });
2156
- };
2157
- const machineSnapshotMeta = function nextEvents() {
2158
- return this.configuration.reduce((acc, stateNode) => {
2134
+ const machineSnapshotGetMeta = function getMeta() {
2135
+ return this._nodes.reduce((acc, stateNode) => {
2159
2136
  if (stateNode.meta !== undefined) {
2160
2137
  acc[stateNode.id] = stateNode.meta;
2161
2138
  }
@@ -2163,48 +2140,34 @@ const machineSnapshotMeta = function nextEvents() {
2163
2140
  }, {});
2164
2141
  };
2165
2142
  function createMachineSnapshot(config, machine) {
2166
- const snapshot = {
2143
+ return {
2167
2144
  status: config.status,
2168
2145
  output: config.output,
2169
2146
  error: config.error,
2170
2147
  machine,
2171
2148
  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))),
2149
+ _nodes: config._nodes,
2150
+ value: getStateValue(machine.root, config._nodes),
2151
+ tags: new Set(flatten(config._nodes.map(sn => sn.tags))),
2175
2152
  children: config.children,
2176
2153
  historyValue: config.historyValue || {},
2177
2154
  // this one is generic in the target and it's hard to create a matching non-generic source signature
2178
2155
  matches: machineSnapshotMatches,
2179
2156
  hasTag: machineSnapshotHasTag,
2180
2157
  can: machineSnapshotCan,
2158
+ getMeta: machineSnapshotGetMeta,
2181
2159
  toJSON: machineSnapshotToJSON
2182
2160
  };
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
2161
  }
2197
2162
  function cloneMachineSnapshot(state, config = {}) {
2198
- return createMachineSnapshot(
2199
- // TODO: it's wasteful that this spread triggers getters
2200
- {
2163
+ return createMachineSnapshot({
2201
2164
  ...state,
2202
2165
  ...config
2203
2166
  }, state.machine);
2204
2167
  }
2205
2168
  function getPersistedState(state, options) {
2206
2169
  const {
2207
- configuration,
2170
+ _nodes: nodes,
2208
2171
  tags,
2209
2172
  machine,
2210
2173
  children,
@@ -2212,8 +2175,8 @@ function getPersistedState(state, options) {
2212
2175
  can,
2213
2176
  hasTag,
2214
2177
  matches,
2178
+ getMeta,
2215
2179
  toJSON,
2216
- nextEvents,
2217
2180
  ...jsonValues
2218
2181
  } = state;
2219
2182
  const childrenJson = {};
@@ -2225,7 +2188,8 @@ function getPersistedState(state, options) {
2225
2188
  childrenJson[id] = {
2226
2189
  state: child.getPersistedState(options),
2227
2190
  src: child.src,
2228
- systemId: child._systemId
2191
+ systemId: child._systemId,
2192
+ syncSnapshot: child._syncSnapshot
2229
2193
  };
2230
2194
  }
2231
2195
  const persisted = {
@@ -2336,8 +2300,9 @@ exports.evaluateGuard = evaluateGuard;
2336
2300
  exports.formatInitialTransition = formatInitialTransition;
2337
2301
  exports.formatTransition = formatTransition;
2338
2302
  exports.formatTransitions = formatTransitions;
2303
+ exports.getAllOwnEventDescriptors = getAllOwnEventDescriptors;
2304
+ exports.getAllStateNodes = getAllStateNodes;
2339
2305
  exports.getCandidates = getCandidates;
2340
- exports.getConfiguration = getConfiguration;
2341
2306
  exports.getDelayedTransitions = getDelayedTransitions;
2342
2307
  exports.getInitialStateNodes = getInitialStateNodes;
2343
2308
  exports.getPersistedState = getPersistedState;
@@ -2351,7 +2316,6 @@ exports.isStateId = isStateId;
2351
2316
  exports.macrostep = macrostep;
2352
2317
  exports.mapValues = mapValues;
2353
2318
  exports.matchesState = matchesState;
2354
- exports.memo = memo;
2355
2319
  exports.microstep = microstep;
2356
2320
  exports.not = not;
2357
2321
  exports.or = or;