-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to spawn actor from any logic #4724
base: main
Are you sure you want to change the base?
Changes from 6 commits
a08f2ee
873ef21
a6f4f3e
352c3ce
697e1b0
8a7ea9e
29279f5
902db97
e59e6d3
a6b60bc
f6844f7
44bf275
831aeec
ba08e79
47991b5
bb770ab
36572e7
9a69517
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ import { symbolObservable } from './symbolObservable.ts'; | |||||||||||||||||
import { AnyActorSystem, Clock, createSystem } from './system.ts'; | ||||||||||||||||||
|
||||||||||||||||||
import type { | ||||||||||||||||||
ActorRefFrom, | ||||||||||||||||||
ActorScope, | ||||||||||||||||||
AnyActorLogic, | ||||||||||||||||||
ConditionalRequired, | ||||||||||||||||||
|
@@ -178,6 +179,21 @@ export class Actor<TLogic extends AnyActorLogic> | |||||||||||||||||
); | ||||||||||||||||||
} | ||||||||||||||||||
(child as any)._stop(); | ||||||||||||||||||
}, | ||||||||||||||||||
spawnChild: <T extends AnyActorLogic>( | ||||||||||||||||||
logic: T, | ||||||||||||||||||
actorOptions?: ActorOptions<T> | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should reuse the type tricks from here: xstate/packages/core/src/createActor.ts Lines 763 to 770 in 8a7ea9e
|
||||||||||||||||||
) => { | ||||||||||||||||||
const actor = createActor(logic, { | ||||||||||||||||||
parent: this, | ||||||||||||||||||
...actorOptions | ||||||||||||||||||
}); | ||||||||||||||||||
|
||||||||||||||||||
if (this._processingStatus === ProcessingStatus.Running) { | ||||||||||||||||||
actor.start(); | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+190
to
+192
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about the actors spawned when |
||||||||||||||||||
|
||||||||||||||||||
return actor as ActorRefFrom<T>; | ||||||||||||||||||
} | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2106,6 +2106,10 @@ export interface ActorScope< | |
defer: (fn: () => void) => void; | ||
system: TSystem; | ||
stopChild: (child: AnyActorRef) => void; | ||
spawnChild: <T extends AnyActorLogic>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
logic: T, | ||
actorOptions?: ActorOptions<T> | ||
) => ActorRefFrom<T>; | ||
} | ||
|
||
export type AnyActorScope = ActorScope<any, any, AnyActorSystem>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't all of those actor logics receive
stopChild
as well?