Skip to content

Commit

Permalink
Oops, infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Feb 9, 2024
1 parent 352c3ce commit 697e1b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/getNextSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export function createInertActorScope<T extends AnyActorLogic>(
stopChild: () => {},
system: self.system,
spawnChild: (logic) => {
return createActor(logic) as any;
const child = createActor(logic) as any;

child.start();

return child;
}
};

Expand Down
15 changes: 12 additions & 3 deletions packages/core/test/actorLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,21 @@ describe('transition function logic (fromTransition)', () => {
any,
any,
any
>((_state, _event, { spawnChild }) => {
>((state, _event, { spawnChild }) => {
if (state) {
return state;
}
const childActor = spawnChild(fromPromise(() => Promise.resolve(42)));
return childActor;
}, undefined);

const actor = createActor(transitionLogic).start();
const actor = createActor(transitionLogic);
actor.subscribe({
error: (err) => {
console.error(err);
}
});
actor.start();
actor.send({ type: 'anyEvent' });

expect(isActorRef(actor.getSnapshot().context)).toBeTruthy();
Expand Down Expand Up @@ -844,7 +853,7 @@ describe('machine logic', () => {
id: 'child',
src: createMachine({
context: ({ input }) => ({
// this is only meant to showcase why we can't invoke this actor when it's missing in the persisted state
// this is meant to showcase why we can't invoke this actor when it's missing in the persisted state
// because we don't have access to the right input as it depends on the event that was used to enter state `b`
value: input.deep.prop
})
Expand Down

0 comments on commit 697e1b0

Please sign in to comment.