( actorLogic: T )
| 12 | |
| 13 | /** @internal */ |
| 14 | export 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. */ |
| 51 | export function getInitialSnapshot<T extends AnyActorLogic>( |
no test coverage detected