xstate 6.0.0-alpha.33 → 6.0.0-alpha.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/{StateMachine-ff580dd5.cjs.js → StateMachine-204661ea.cjs.js} +27 -137
  2. package/dist/{StateMachine-d073209c.esm.js → StateMachine-269b22a3.esm.js} +19 -124
  3. package/dist/{StateMachine-33eec203.development.esm.js → StateMachine-b72b23cc.development.esm.js} +19 -124
  4. package/dist/{StateMachine-d3243bd1.development.cjs.js → StateMachine-b827f6a8.development.cjs.js} +27 -137
  5. package/dist/declarations/src/StateMachine.d.ts +2 -2
  6. package/dist/declarations/src/stateUtils.d.ts +4 -4
  7. package/dist/declarations/src/types.d.ts +1 -1
  8. package/dist/{index-ab93831d.esm.js → index-16832816.esm.js} +593 -235
  9. package/dist/{index-691f27b9.development.cjs.js → index-692b05ac.development.cjs.js} +601 -236
  10. package/dist/{index-9939f02a.cjs.js → index-b440472d.cjs.js} +601 -236
  11. package/dist/{index-92227865.development.esm.js → index-ea9227d3.development.esm.js} +593 -235
  12. package/dist/xstate-actors.cjs.js +1 -1
  13. package/dist/xstate-actors.development.cjs.js +1 -1
  14. package/dist/xstate-actors.development.esm.js +1 -1
  15. package/dist/xstate-actors.esm.js +1 -1
  16. package/dist/xstate-actors.umd.min.js +1 -1
  17. package/dist/xstate-actors.umd.min.js.map +1 -1
  18. package/dist/xstate-graph.cjs.js +2 -2
  19. package/dist/xstate-graph.development.cjs.js +2 -2
  20. package/dist/xstate-graph.development.esm.js +2 -2
  21. package/dist/xstate-graph.esm.js +2 -2
  22. package/dist/xstate-graph.umd.min.js +1 -1
  23. package/dist/xstate-graph.umd.min.js.map +1 -1
  24. package/dist/xstate.cjs.js +34 -33
  25. package/dist/xstate.development.cjs.js +34 -33
  26. package/dist/xstate.development.esm.js +26 -25
  27. package/dist/xstate.esm.js +26 -25
  28. package/dist/xstate.umd.min.js +1 -1
  29. package/dist/xstate.umd.min.js.map +1 -1
  30. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-9939f02a.cjs.js');
3
+ var dist_xstateActors = require('./index-b440472d.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, actors, spawnedChildren) {
6
6
  return (src, options) => {
@@ -18,111 +18,6 @@ function createSpawner(actorScope, actors, spawnedChildren) {
18
18
  };
19
19
  }
20
20
 
21
- /** @internal */
22
- function setInertActorScopeSnapshot(actorScope, snapshot, attachActorRef = true) {
23
- actorScope.self._snapshot = snapshot;
24
- if (attachActorRef && snapshot && typeof snapshot === 'object') {
25
- dist_xstateActors.setSnapshotActorRef(snapshot, actorScope.self);
26
- }
27
- return snapshot;
28
- }
29
-
30
- /** @internal */
31
- function isInertActorScope(actorScope) {
32
- return !!actorScope.self.options?._inert;
33
- }
34
-
35
- /** @internal */
36
- function attachSnapshotActorRef(actorLogic, actorScope, snapshot) {
37
- const snapshotScope = createInertActorScope(actorLogic, snapshot, actorScope.self);
38
- return setInertActorScopeSnapshot(snapshotScope, snapshot);
39
- }
40
-
41
- /** @internal */
42
- function createInertActorScope(actorLogic, snapshot, sourceSelf) {
43
- const snapshotRef = snapshot ? dist_xstateActors.getSnapshotActorRef(snapshot) : undefined;
44
- const previousSelf = sourceSelf ?? snapshotRef?.actor;
45
- const baseSystem = previousSelf?.system;
46
- const system = previousSelf && baseSystem ? dist_xstateActors.createSnapshotSystem(baseSystem, dist_xstateActors.isMachineSnapshot(snapshot) ? snapshot.children : {}, sourceSelf ? undefined : snapshotRef?.systemState) : undefined;
47
- const self = dist_xstateActors.createActor(actorLogic, {
48
- _inert: true,
49
- ...(previousSelf ? {
50
- id: previousSelf.id,
51
- _sessionId: previousSelf.sessionId
52
- } : {}),
53
- ...(system ? {
54
- _systemRef: {
55
- current: system
56
- }
57
- } : {})
58
- });
59
- if (previousSelf?._parent) {
60
- self._parent = previousSelf._parent;
61
- }
62
- if (snapshot) {
63
- self._snapshot = snapshot;
64
- }
65
- const actorScope = {
66
- self: self,
67
- defer: () => {},
68
- id: self.id,
69
- logger: self.system._logger,
70
- sessionId: self.sessionId,
71
- stopChild: child => child._stop(),
72
- system: self.system,
73
- emit: event => self.system.emitEvent(self, event),
74
- actionExecutor: () => {}
75
- };
76
- return actorScope;
77
- }
78
-
79
- /** @deprecated Use `initialTransition(…)` instead. */
80
- function getInitialSnapshot(actorLogic, ...[input]) {
81
- const actorScope = createInertActorScope(actorLogic);
82
- return actorLogic.initialTransition(input, actorScope)[0];
83
- }
84
-
85
- /**
86
- * Determines the next snapshot for the given `actorLogic` based on the given
87
- * `snapshot` and `event`.
88
- *
89
- * If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
90
- * used.
91
- *
92
- * @deprecated Use `transition(…)` instead.
93
- * @example
94
- *
95
- * ```ts
96
- * import { getNextSnapshot } from 'xstate';
97
- * import { trafficLightMachine } from './trafficLightMachine.ts';
98
- *
99
- * const nextSnapshot = getNextSnapshot(
100
- * trafficLightMachine, // actor logic
101
- * undefined, // snapshot (or initial state if undefined)
102
- * { type: 'TIMER' }
103
- * ); // event object
104
- *
105
- * console.log(nextSnapshot.value);
106
- * // => 'yellow'
107
- *
108
- * const nextSnapshot2 = getNextSnapshot(
109
- * trafficLightMachine, // actor logic
110
- * nextSnapshot, // snapshot
111
- * { type: 'TIMER' }
112
- * ); // event object
113
- *
114
- * console.log(nextSnapshot2.value);
115
- * // =>'red'
116
- * ```
117
- */
118
- function getNextSnapshot(actorLogic, snapshot, event) {
119
- const actorScope = createInertActorScope(actorLogic, snapshot);
120
- const transitionResult = actorLogic.transition(snapshot, event, actorScope);
121
- const nextSnapshot = Array.isArray(transitionResult) ? transitionResult[0] : transitionResult;
122
- setInertActorScopeSnapshot(actorScope, nextSnapshot, false);
123
- return nextSnapshot === snapshot ? nextSnapshot : attachSnapshotActorRef(actorLogic, actorScope, nextSnapshot);
124
- }
125
-
126
21
  const cache = new WeakMap();
127
22
  function memo(object, key, fn) {
128
23
  let memoizedData = cache.get(object);
@@ -305,7 +200,7 @@ class StateNode {
305
200
  }
306
201
 
307
202
  /** @internal */
308
- next(snapshot, event, self, selectionResults) {
203
+ next(snapshot, event, actorScope, selectionResults) {
309
204
  const descriptorKey = dist_xstateActors.getEventDescriptorKey(event);
310
205
  let candidates = this._candidateCache?.get(descriptorKey);
311
206
  if (!candidates) {
@@ -313,7 +208,7 @@ class StateNode {
313
208
  (this._candidateCache ??= new Map()).set(descriptorKey, candidates);
314
209
  }
315
210
  for (const candidate of candidates) {
316
- const guardPassed = dist_xstateActors.evaluateCandidate(candidate, event, snapshot, this, self, selectionResults);
211
+ const guardPassed = dist_xstateActors.evaluateCandidate(candidate, event, snapshot, this, actorScope, selectionResults);
317
212
  if (guardPassed) {
318
213
  return [candidate];
319
214
  }
@@ -657,7 +552,7 @@ class StateMachine {
657
552
  */
658
553
  transition(snapshot, event, actorScope) {
659
554
  const usesInertScope = !actorScope;
660
- const resolvedActorScope = actorScope ?? createInertActorScope(this, snapshot);
555
+ const resolvedActorScope = actorScope ?? dist_xstateActors.createInertActorScope(this, snapshot);
661
556
  if (this.validator) {
662
557
  dist_xstateActors.assertValid(this.validator, {
663
558
  kind: 'event',
@@ -667,14 +562,14 @@ class StateMachine {
667
562
  });
668
563
  }
669
564
  if (usesInertScope) {
670
- setInertActorScopeSnapshot(resolvedActorScope, snapshot, false);
565
+ dist_xstateActors.setInertActorScopeSnapshot(resolvedActorScope, snapshot, false);
671
566
  }
672
567
  const fastSnapshot = this._transitionFast(snapshot, event, resolvedActorScope);
673
568
  if (fastSnapshot) {
674
569
  if (usesInertScope) {
675
- setInertActorScopeSnapshot(resolvedActorScope, fastSnapshot, false);
570
+ dist_xstateActors.setInertActorScopeSnapshot(resolvedActorScope, fastSnapshot, false);
676
571
  }
677
- const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? attachSnapshotActorRef(this, resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
572
+ const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? dist_xstateActors.attachSnapshotActorRef(resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
678
573
  if (this.validator) {
679
574
  dist_xstateActors.assertValid(this.validator, {
680
575
  kind: 'result',
@@ -690,9 +585,9 @@ class StateMachine {
690
585
  microsteps
691
586
  } = dist_xstateActors.macrostep(snapshot, event, resolvedActorScope, []);
692
587
  if (usesInertScope) {
693
- setInertActorScopeSnapshot(resolvedActorScope, nextSnapshot, false);
588
+ dist_xstateActors.setInertActorScopeSnapshot(resolvedActorScope, nextSnapshot, false);
694
589
  }
695
- const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : attachSnapshotActorRef(this, resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
590
+ const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : dist_xstateActors.attachSnapshotActorRef(resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
696
591
  const effects = this._collectEffects(microsteps);
697
592
  if (this.validator) {
698
593
  dist_xstateActors.assertValid(this.validator, {
@@ -708,7 +603,7 @@ class StateMachine {
708
603
  return microsteps.flatMap(([, actions]) => actions);
709
604
  }
710
605
  _attachPureActorRef(snapshot, actorScope) {
711
- if (isInertActorScope(actorScope)) {
606
+ if (dist_xstateActors.isInertActorScope(actorScope)) {
712
607
  return snapshot;
713
608
  }
714
609
  dist_xstateActors.setSnapshotActorRef(snapshot, actorScope.self, actorScope.system);
@@ -739,9 +634,11 @@ class StateMachine {
739
634
  ...snapshot.context,
740
635
  ...selected.context
741
636
  } : snapshot.context;
742
- const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
743
- collectedMicrosteps.push(selected);
744
- actorScope.self._collectedMicrosteps = collectedMicrosteps;
637
+ if (!dist_xstateActors.isInertActorScope(actorScope) && (actorScope.system._hasInspectionObservers?.() ?? true)) {
638
+ const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
639
+ collectedMicrosteps.push(selected);
640
+ actorScope.self._collectedMicrosteps = collectedMicrosteps;
641
+ }
745
642
  return dist_xstateActors.cloneMachineSnapshot(snapshot, {
746
643
  ...(context !== snapshot.context ? {
747
644
  context
@@ -769,8 +666,8 @@ class StateMachine {
769
666
  }
770
667
  return snapshots;
771
668
  }
772
- getTransitionData(snapshot, event, self, selectionResults) {
773
- return dist_xstateActors.transitionNode(this.root, snapshot.value, snapshot, event, self, selectionResults) || [];
669
+ getTransitionData(snapshot, event, actorScope, selectionResults) {
670
+ return dist_xstateActors.transitionNode(this.root, snapshot.value, snapshot, event, actorScope, selectionResults) || [];
774
671
  }
775
672
  isInternalEventType(eventType) {
776
673
  if (eventType === dist_xstateActors.XSTATE_TIMER) {
@@ -792,9 +689,8 @@ class StateMachine {
792
689
  * @internal
793
690
  */
794
691
  _canTransition(snapshot, event) {
795
- const emptyActor = getEmptyCanActor();
796
692
  const emptyActorScope = getEmptyCanActorScope();
797
- const transitionData = this.getTransitionData(snapshot, event, emptyActor);
693
+ const transitionData = this.getTransitionData(snapshot, event, emptyActorScope);
798
694
  if (!transitionData?.length) {
799
695
  return false;
800
696
  }
@@ -807,7 +703,7 @@ class StateMachine {
807
703
  const res = dist_xstateActors.getTransitionResult(transition, snapshot, event, emptyActorScope, {
808
704
  resolveActions: false
809
705
  });
810
- if (res.targets?.length || res.context || dist_xstateActors.hasEffect(transition, snapshot.context, event, snapshot, emptyActor)) {
706
+ if (res.targets?.length || res.context || dist_xstateActors.hasEffect(transition, snapshot.context, event, snapshot, emptyActorScope)) {
811
707
  return true;
812
708
  }
813
709
  }
@@ -846,12 +742,11 @@ class StateMachine {
846
742
  if (typeof context === 'function') {
847
743
  const children = {};
848
744
  const spawn = createSpawner(actorScope, this.sources.actors, children);
849
- const resolvedContext = context({
745
+ const resolvedContext = context(dist_xstateActors.withActorSelf({
850
746
  spawn,
851
747
  input: initEvent.input,
852
- self: actorScope.self,
853
748
  actors: this.sources.actors
854
- });
749
+ }, actorScope));
855
750
  const [nextState] = dist_xstateActors.resolveActionsWithContext(preInitial, initEvent, actorScope, []);
856
751
  if (resolvedContext) {
857
752
  nextState.context = resolvedContext;
@@ -883,16 +778,16 @@ class StateMachine {
883
778
  });
884
779
  }
885
780
  const usesInertScope = !actorScope;
886
- const resolvedActorScope = actorScope ?? createInertActorScope(this);
781
+ const resolvedActorScope = actorScope ?? dist_xstateActors.createInertActorScope(this);
887
782
  const initEvent = dist_xstateActors.createInitEvent(input); // TODO: fix;
888
783
  const internalQueue = [];
889
784
  const preInitialState = this._getPreInitialState(resolvedActorScope, initEvent);
890
785
  const contextSpawnEffects = Object.values(preInitialState.children).filter(Boolean).map(actor => dist_xstateActors.createSpawnEffect(actor));
891
786
  const finalizeInitialResult = (macroState, microsteps) => {
892
787
  if (usesInertScope) {
893
- setInertActorScopeSnapshot(resolvedActorScope, macroState, false);
788
+ dist_xstateActors.setInertActorScopeSnapshot(resolvedActorScope, macroState, false);
894
789
  }
895
- const returnedSnapshot = usesInertScope ? attachSnapshotActorRef(this, resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope);
790
+ const returnedSnapshot = usesInertScope ? dist_xstateActors.attachSnapshotActorRef(resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope);
896
791
  const effects = this._collectEffects(microsteps);
897
792
  if (this.validator) {
898
793
  dist_xstateActors.assertValid(this.validator, {
@@ -948,7 +843,7 @@ class StateMachine {
948
843
  }
949
844
  restoreSnapshot(snapshot, actorScope) {
950
845
  const usesInertScope = !actorScope;
951
- const resolvedActorScope = actorScope ?? createInertActorScope(this);
846
+ const resolvedActorScope = actorScope ?? dist_xstateActors.createInertActorScope(this);
952
847
  const persistedMachine = snapshot.machine;
953
848
  const legacyPersistedVersion = snapshot.version;
954
849
  const persistedVersion = typeof persistedMachine?.version === 'string' ? persistedMachine.version : legacyPersistedVersion;
@@ -1072,8 +967,8 @@ class StateMachine {
1072
967
  }
1073
968
  reviveContext(restoredSnapshot.context);
1074
969
  if (usesInertScope) {
1075
- setInertActorScopeSnapshot(resolvedActorScope, restoredSnapshot, false);
1076
- return attachSnapshotActorRef(this, resolvedActorScope, restoredSnapshot);
970
+ dist_xstateActors.setInertActorScopeSnapshot(resolvedActorScope, restoredSnapshot, false);
971
+ return dist_xstateActors.attachSnapshotActorRef(resolvedActorScope, restoredSnapshot);
1077
972
  }
1078
973
  return this._attachPureActorRef(restoredSnapshot, resolvedActorScope);
1079
974
  }
@@ -1081,8 +976,3 @@ class StateMachine {
1081
976
 
1082
977
  exports.StateMachine = StateMachine;
1083
978
  exports.StateNode = StateNode;
1084
- exports.attachSnapshotActorRef = attachSnapshotActorRef;
1085
- exports.createInertActorScope = createInertActorScope;
1086
- exports.getInitialSnapshot = getInitialSnapshot;
1087
- exports.getNextSnapshot = getNextSnapshot;
1088
- exports.setInertActorScopeSnapshot = setInertActorScopeSnapshot;
@@ -1,4 +1,4 @@
1
- import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as getCandidates, W as evaluateCandidate, Y as formatTransition, Z as NULL_EVENT, _ as toTransitionConfigArray, $ as createInvokeTimeoutEventId, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, a6 as assertValid, j as macrostep, a7 as cloneMachineSnapshot, a8 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a9 as getTransitionResult, aa as hasEffect, ab as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ac as toStatePath, ad as isStateId, ae as getStateNodeByPath, af as getPersistedSnapshot, ag as resolveReferencedActor, ah as createInvokeTimeoutEvent, ai as $$ACTOR_TYPE } from './index-ab93831d.esm.js';
1
+ import { U as STATE_DELIMITER, V as mapValues, t as toArray, W as createInvokeId, Y as getDelayedTransitions, Z as getEventDescriptorKey, _ as getCandidates, $ as evaluateCandidate, a0 as formatTransition, a1 as NULL_EVENT, a2 as toTransitionConfigArray, a3 as createInvokeTimeoutEventId, a4 as matchesActorSession, a5 as formatRouteTransitions, a6 as resolveStateValue, a7 as getAllStateNodes, B as getStateNodes, a8 as createMachineSnapshot, a9 as isInFinalState, k as createInertActorScope, aa as assertValid, s as setInertActorScopeSnapshot, l as attachSnapshotActorRef, n as macrostep, ab as isInertActorScope, ac as setSnapshotActorRef, ad as cloneMachineSnapshot, ae as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, af as getTransitionResult, ag as hasEffect, ah as createErrorPlatformEvent, ai as withActorSelf, r as resolveActionsWithContext, o as createInitEvent, q as createSpawnEffect, u as initialMicrostep, aj as toStatePath, ak as isStateId, al as getStateNodeByPath, am as getPersistedSnapshot, an as resolveReferencedActor, ao as createInvokeTimeoutEvent, ap as $$ACTOR_TYPE, j as createActor } from './index-16832816.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, actors, spawnedChildren) {
4
4
  return (src, options) => {
@@ -16,111 +16,6 @@ function createSpawner(actorScope, actors, spawnedChildren) {
16
16
  };
17
17
  }
18
18
 
19
- /** @internal */
20
- function setInertActorScopeSnapshot(actorScope, snapshot, attachActorRef = true) {
21
- actorScope.self._snapshot = snapshot;
22
- if (attachActorRef && snapshot && typeof snapshot === 'object') {
23
- setSnapshotActorRef(snapshot, actorScope.self);
24
- }
25
- return snapshot;
26
- }
27
-
28
- /** @internal */
29
- function isInertActorScope(actorScope) {
30
- return !!actorScope.self.options?._inert;
31
- }
32
-
33
- /** @internal */
34
- function attachSnapshotActorRef(actorLogic, actorScope, snapshot) {
35
- const snapshotScope = createInertActorScope(actorLogic, snapshot, actorScope.self);
36
- return setInertActorScopeSnapshot(snapshotScope, snapshot);
37
- }
38
-
39
- /** @internal */
40
- function createInertActorScope(actorLogic, snapshot, sourceSelf) {
41
- const snapshotRef = snapshot ? getSnapshotActorRef(snapshot) : undefined;
42
- const previousSelf = sourceSelf ?? snapshotRef?.actor;
43
- const baseSystem = previousSelf?.system;
44
- const system = previousSelf && baseSystem ? createSnapshotSystem(baseSystem, isMachineSnapshot(snapshot) ? snapshot.children : {}, sourceSelf ? undefined : snapshotRef?.systemState) : undefined;
45
- const self = createActor(actorLogic, {
46
- _inert: true,
47
- ...(previousSelf ? {
48
- id: previousSelf.id,
49
- _sessionId: previousSelf.sessionId
50
- } : {}),
51
- ...(system ? {
52
- _systemRef: {
53
- current: system
54
- }
55
- } : {})
56
- });
57
- if (previousSelf?._parent) {
58
- self._parent = previousSelf._parent;
59
- }
60
- if (snapshot) {
61
- self._snapshot = snapshot;
62
- }
63
- const actorScope = {
64
- self: self,
65
- defer: () => {},
66
- id: self.id,
67
- logger: self.system._logger,
68
- sessionId: self.sessionId,
69
- stopChild: child => child._stop(),
70
- system: self.system,
71
- emit: event => self.system.emitEvent(self, event),
72
- actionExecutor: () => {}
73
- };
74
- return actorScope;
75
- }
76
-
77
- /** @deprecated Use `initialTransition(…)` instead. */
78
- function getInitialSnapshot(actorLogic, ...[input]) {
79
- const actorScope = createInertActorScope(actorLogic);
80
- return actorLogic.initialTransition(input, actorScope)[0];
81
- }
82
-
83
- /**
84
- * Determines the next snapshot for the given `actorLogic` based on the given
85
- * `snapshot` and `event`.
86
- *
87
- * If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
88
- * used.
89
- *
90
- * @deprecated Use `transition(…)` instead.
91
- * @example
92
- *
93
- * ```ts
94
- * import { getNextSnapshot } from 'xstate';
95
- * import { trafficLightMachine } from './trafficLightMachine.ts';
96
- *
97
- * const nextSnapshot = getNextSnapshot(
98
- * trafficLightMachine, // actor logic
99
- * undefined, // snapshot (or initial state if undefined)
100
- * { type: 'TIMER' }
101
- * ); // event object
102
- *
103
- * console.log(nextSnapshot.value);
104
- * // => 'yellow'
105
- *
106
- * const nextSnapshot2 = getNextSnapshot(
107
- * trafficLightMachine, // actor logic
108
- * nextSnapshot, // snapshot
109
- * { type: 'TIMER' }
110
- * ); // event object
111
- *
112
- * console.log(nextSnapshot2.value);
113
- * // =>'red'
114
- * ```
115
- */
116
- function getNextSnapshot(actorLogic, snapshot, event) {
117
- const actorScope = createInertActorScope(actorLogic, snapshot);
118
- const transitionResult = actorLogic.transition(snapshot, event, actorScope);
119
- const nextSnapshot = Array.isArray(transitionResult) ? transitionResult[0] : transitionResult;
120
- setInertActorScopeSnapshot(actorScope, nextSnapshot, false);
121
- return nextSnapshot === snapshot ? nextSnapshot : attachSnapshotActorRef(actorLogic, actorScope, nextSnapshot);
122
- }
123
-
124
19
  const cache = new WeakMap();
125
20
  function memo(object, key, fn) {
126
21
  let memoizedData = cache.get(object);
@@ -303,7 +198,7 @@ class StateNode {
303
198
  }
304
199
 
305
200
  /** @internal */
306
- next(snapshot, event, self, selectionResults) {
201
+ next(snapshot, event, actorScope, selectionResults) {
307
202
  const descriptorKey = getEventDescriptorKey(event);
308
203
  let candidates = this._candidateCache?.get(descriptorKey);
309
204
  if (!candidates) {
@@ -311,7 +206,7 @@ class StateNode {
311
206
  (this._candidateCache ??= new Map()).set(descriptorKey, candidates);
312
207
  }
313
208
  for (const candidate of candidates) {
314
- const guardPassed = evaluateCandidate(candidate, event, snapshot, this, self, selectionResults);
209
+ const guardPassed = evaluateCandidate(candidate, event, snapshot, this, actorScope, selectionResults);
315
210
  if (guardPassed) {
316
211
  return [candidate];
317
212
  }
@@ -672,7 +567,7 @@ class StateMachine {
672
567
  if (usesInertScope) {
673
568
  setInertActorScopeSnapshot(resolvedActorScope, fastSnapshot, false);
674
569
  }
675
- const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? attachSnapshotActorRef(this, resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
570
+ const returnedSnapshot = usesInertScope && fastSnapshot !== snapshot ? attachSnapshotActorRef(resolvedActorScope, fastSnapshot) : this._attachPureActorRef(fastSnapshot, resolvedActorScope);
676
571
  if (this.validator) {
677
572
  assertValid(this.validator, {
678
573
  kind: 'result',
@@ -690,7 +585,7 @@ class StateMachine {
690
585
  if (usesInertScope) {
691
586
  setInertActorScopeSnapshot(resolvedActorScope, nextSnapshot, false);
692
587
  }
693
- const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : attachSnapshotActorRef(this, resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
588
+ const returnedSnapshot = usesInertScope ? nextSnapshot === snapshot ? nextSnapshot : attachSnapshotActorRef(resolvedActorScope, nextSnapshot) : this._attachPureActorRef(nextSnapshot, resolvedActorScope);
694
589
  const effects = this._collectEffects(microsteps);
695
590
  if (this.validator) {
696
591
  assertValid(this.validator, {
@@ -737,9 +632,11 @@ class StateMachine {
737
632
  ...snapshot.context,
738
633
  ...selected.context
739
634
  } : snapshot.context;
740
- const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
741
- collectedMicrosteps.push(selected);
742
- actorScope.self._collectedMicrosteps = collectedMicrosteps;
635
+ if (!isInertActorScope(actorScope) && (actorScope.system._hasInspectionObservers?.() ?? true)) {
636
+ const collectedMicrosteps = actorScope.self._collectedMicrosteps || [];
637
+ collectedMicrosteps.push(selected);
638
+ actorScope.self._collectedMicrosteps = collectedMicrosteps;
639
+ }
743
640
  return cloneMachineSnapshot(snapshot, {
744
641
  ...(context !== snapshot.context ? {
745
642
  context
@@ -767,8 +664,8 @@ class StateMachine {
767
664
  }
768
665
  return snapshots;
769
666
  }
770
- getTransitionData(snapshot, event, self, selectionResults) {
771
- return transitionNode(this.root, snapshot.value, snapshot, event, self, selectionResults) || [];
667
+ getTransitionData(snapshot, event, actorScope, selectionResults) {
668
+ return transitionNode(this.root, snapshot.value, snapshot, event, actorScope, selectionResults) || [];
772
669
  }
773
670
  isInternalEventType(eventType) {
774
671
  if (eventType === XSTATE_TIMER) {
@@ -790,9 +687,8 @@ class StateMachine {
790
687
  * @internal
791
688
  */
792
689
  _canTransition(snapshot, event) {
793
- const emptyActor = getEmptyCanActor();
794
690
  const emptyActorScope = getEmptyCanActorScope();
795
- const transitionData = this.getTransitionData(snapshot, event, emptyActor);
691
+ const transitionData = this.getTransitionData(snapshot, event, emptyActorScope);
796
692
  if (!transitionData?.length) {
797
693
  return false;
798
694
  }
@@ -805,7 +701,7 @@ class StateMachine {
805
701
  const res = getTransitionResult(transition, snapshot, event, emptyActorScope, {
806
702
  resolveActions: false
807
703
  });
808
- if (res.targets?.length || res.context || hasEffect(transition, snapshot.context, event, snapshot, emptyActor)) {
704
+ if (res.targets?.length || res.context || hasEffect(transition, snapshot.context, event, snapshot, emptyActorScope)) {
809
705
  return true;
810
706
  }
811
707
  }
@@ -844,12 +740,11 @@ class StateMachine {
844
740
  if (typeof context === 'function') {
845
741
  const children = {};
846
742
  const spawn = createSpawner(actorScope, this.sources.actors, children);
847
- const resolvedContext = context({
743
+ const resolvedContext = context(withActorSelf({
848
744
  spawn,
849
745
  input: initEvent.input,
850
- self: actorScope.self,
851
746
  actors: this.sources.actors
852
- });
747
+ }, actorScope));
853
748
  const [nextState] = resolveActionsWithContext(preInitial, initEvent, actorScope, []);
854
749
  if (resolvedContext) {
855
750
  nextState.context = resolvedContext;
@@ -890,7 +785,7 @@ class StateMachine {
890
785
  if (usesInertScope) {
891
786
  setInertActorScopeSnapshot(resolvedActorScope, macroState, false);
892
787
  }
893
- const returnedSnapshot = usesInertScope ? attachSnapshotActorRef(this, resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope);
788
+ const returnedSnapshot = usesInertScope ? attachSnapshotActorRef(resolvedActorScope, macroState) : this._attachPureActorRef(macroState, resolvedActorScope);
894
789
  const effects = this._collectEffects(microsteps);
895
790
  if (this.validator) {
896
791
  assertValid(this.validator, {
@@ -1071,10 +966,10 @@ class StateMachine {
1071
966
  reviveContext(restoredSnapshot.context);
1072
967
  if (usesInertScope) {
1073
968
  setInertActorScopeSnapshot(resolvedActorScope, restoredSnapshot, false);
1074
- return attachSnapshotActorRef(this, resolvedActorScope, restoredSnapshot);
969
+ return attachSnapshotActorRef(resolvedActorScope, restoredSnapshot);
1075
970
  }
1076
971
  return this._attachPureActorRef(restoredSnapshot, resolvedActorScope);
1077
972
  }
1078
973
  }
1079
974
 
1080
- export { StateMachine as S, attachSnapshotActorRef as a, getNextSnapshot as b, createInertActorScope as c, StateNode as d, getInitialSnapshot as g, setInertActorScopeSnapshot as s };
975
+ export { StateMachine as S, StateNode as a };