MCPcopy
hub / github.com/statelyai/xstate / createInertActorScope

Function createInertActorScope

packages/core/src/getNextSnapshot.ts:14–48  ·  view source on GitHub ↗
(
  actorLogic: T
)

Source from the content-addressed store, hash-verified

12
13/** @internal */
14export function createInertActorScope<T extends AnyActorLogic>(
15 actorLogic: T
16): AnyActorScope {
17 const self = createActor(actorLogic as AnyActorLogic);
18 // The Actor constructor eagerly calls `getInitialSnapshot` during `_initState`,
19 // which can register child actors with `systemId` in `self.system`.
20 // Replace `self.system` with a fresh system so that child actors spawned by
21 // the *caller's* explicit `getInitialSnapshot` / `transition` call register
22 // into a clean system and do not collide with those from the eager
23 // construction call. This is what makes `initialTransition(machine)` safe
24 // even when invoked actors carry a `systemId`.
25 const freshSystem = createSystem(self, {
26 clock: self.system._clock,
27 logger: self.system._logger
28 });
29 (self as any).system = freshSystem;
30 const inertActorScope: ActorScope<
31 SnapshotFrom<T>,
32 EventFromLogic<T>,
33 any,
34 EmittedFrom<T>
35 > = {
36 self,
37 defer: () => {},
38 id: '',
39 logger: () => {},
40 sessionId: '',
41 stopChild: () => {},
42 system: freshSystem,
43 emit: () => {},
44 actionExecutor: () => {}
45 };
46
47 return inertActorScope;
48}
49
50/** @deprecated Use `initialTransition(…)` instead. */
51export function getInitialSnapshot<T extends AnyActorLogic>(

Callers 7

microstep.test.tsFile · 0.90
transitionFunction · 0.90
initialTransitionFunction · 0.90
getMicrostepsFunction · 0.90
getInitialMicrostepsFunction · 0.90
getInitialSnapshotFunction · 0.85
getNextSnapshotFunction · 0.85

Calls 2

createActorFunction · 0.90
createSystemFunction · 0.90

Tested by

no test coverage detected