behaviors.d.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { 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. */
  9. export declare function fromReducer<TState, TEvent extends EventObject>(transition: (state: TState, event: TEvent, actorContext: ActorContext<TEvent, TState>) => TState, initialState: TState): Behavior<TEvent, TState>;
  10. declare type PromiseEvents<T> = {
  11. type: 'fulfill';
  12. data: T;
  13. } | {
  14. type: 'reject';
  15. error: unknown;
  16. };
  17. declare 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. };
  30. export declare function fromPromise<T>(promiseFn: () => Promise<T>): Behavior<PromiseEvents<T>, PromiseState<T>>;
  31. interface SpawnBehaviorOptions {
  32. id?: string;
  33. parent?: ActorRef<any>;
  34. }
  35. export declare function spawnBehavior<TEvent extends EventObject, TEmitted>(behavior: Behavior<TEvent, TEmitted>, options?: SpawnBehaviorOptions): ActorRef<TEvent, TEmitted>;
  36. export {};
  37. //# sourceMappingURL=behaviors.d.ts.map