UNPKG

1.6 kBTypeScriptView Raw
1import { ActorRefFromLogic, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, GetConcreteByKey, InputFrom, IsLiteralString, IsNotNever, ProvidedActor, RequiredActorOptions } from "./types.js";
2type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TActor extends {
3 src: TSrc;
4} ? ConditionalRequired<[
5 options?: {
6 id?: TActor['id'];
7 systemId?: string;
8 input?: InputFrom<TActor['logic']>;
9 syncSnapshot?: boolean;
10 } & {
11 [K in RequiredActorOptions<TActor>]: unknown;
12 }
13], IsNotNever<RequiredActorOptions<TActor>>> : never;
14export type Spawner<TActor extends ProvidedActor> = IsLiteralString<TActor['src']> extends true ? {
15 <TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>): ActorRefFromLogic<GetConcreteByKey<TActor, 'src', TSrc>['logic']>;
16 <TLogic extends AnyActorLogic>(src: TLogic, options?: {
17 id?: never;
18 systemId?: string;
19 input?: InputFrom<TLogic>;
20 syncSnapshot?: boolean;
21 }): ActorRefFromLogic<TLogic>;
22} : <TLogic extends AnyActorLogic | string>(src: TLogic, options?: {
23 id?: string;
24 systemId?: string;
25 input?: TLogic extends string ? unknown : InputFrom<TLogic>;
26 syncSnapshot?: boolean;
27}) => TLogic extends AnyActorLogic ? ActorRefFromLogic<TLogic> : AnyActorRef;
28export declare function createSpawner(actorScope: AnyActorScope, { machine, context }: AnyMachineSnapshot, event: AnyEventObject, spawnedChildren: Record<string, AnyActorRef>): Spawner<any>;
29export {};