UNPKG

1.36 kBTypeScriptView Raw
1import { ActorContext, ActorRef, Behavior, EventObject } from './types';
2/**
3 * Returns an actor behavior from a reducer and its initial state.
4 *
5 * @param transition The pure reducer that returns the next state given the current state and event.
6 * @param initialState The initial state of the reducer.
7 * @returns An actor behavior
8 */
9export declare function fromReducer<TState, TEvent extends EventObject>(transition: (state: TState, event: TEvent, actorContext: ActorContext<TEvent, TState>) => TState, initialState: TState): Behavior<TEvent, TState>;
10declare type PromiseEvents<T> = {
11 type: 'fulfill';
12 data: T;
13} | {
14 type: 'reject';
15 error: unknown;
16};
17declare type PromiseState<T> = {
18 status: 'pending';
19 data: undefined;
20 error: undefined;
21} | {
22 status: 'fulfilled';
23 data: T;
24 error: undefined;
25} | {
26 status: 'rejected';
27 data: undefined;
28 error: any;
29};
30export declare function fromPromise<T>(promiseFn: () => Promise<T>): Behavior<PromiseEvents<T>, PromiseState<T>>;
31interface SpawnBehaviorOptions {
32 id?: string;
33 parent?: ActorRef<any>;
34}
35export declare function spawnBehavior<TEvent extends EventObject, TEmitted>(behavior: Behavior<TEvent, TEmitted>, options?: SpawnBehaviorOptions): ActorRef<TEvent, TEmitted>;
36export {};
37//# sourceMappingURL=behaviors.d.ts.map
\No newline at end of file