import { AnyActorSystem } from "../system.js"; import { ActorLogic, ActorRefFrom, EventObject, NonReducibleUnknown, Snapshot, Subscribable, Subscription } from "../types.js"; export type ObservableSnapshot = Snapshot & { context: TContext | undefined; input: TInput | undefined; _subscription: Subscription | undefined; }; export type ObservableActorLogic = ActorLogic, { type: string; [k: string]: unknown; }, TInput, AnyActorSystem, EventObject>; export type ObservableActorRef = ActorRefFrom>; /** * Observable actor logic is described by an observable stream of values. Actors created from observable logic (“observable actors”) can: * * - Emit snapshots of the observable’s emitted value * * The observable’s emitted value is used as its observable actor’s `context`. * * Sending events to observable actors will have no effect. * * @param observableCreator A function that creates an observable. It receives one argument, an object with the following properties: * - `input` - Data that was provided to the observable actor * - `self` - The parent actor * - `system` - The actor system to which the observable actor belongs * * It should return a {@link Subscribable}, which is compatible with an RxJS Observable, although RxJS is not required to create them. * * @example * ```ts * import { fromObservable, createActor } from 'xstate' * import { interval } from 'rxjs'; * * const logic = fromObservable((obj) => interval(1000)); * * const actor = createActor(logic); * * actor.subscribe((snapshot) => { * console.log(snapshot.context); * }); * * actor.start(); * // At every second: * // Logs 0 * // Logs 1 * // Logs 2 * // ... * ``` * * @see {@link https://rxjs.dev} for documentation on RxJS Observable and observable creators. * @see {@link Subscribable} interface in XState, which is based on and compatible with RxJS Observable. */ export declare function fromObservable(observableCreator: ({ input, system }: { input: TInput; system: AnyActorSystem; self: ObservableActorRef; }) => Subscribable): ObservableActorLogic; /** * Creates event observable logic that listens to an observable that delivers event objects. * * Event observable actor logic is described by an observable stream of {@link https://stately.ai/docs/transitions#event-objects | event objects}. Actors created from event observable logic (“event observable actors”) can: * * - Implicitly send events to its parent actor * - Emit snapshots of its emitted event objects * * Sending events to event observable actors will have no effect. * * @param lazyObservable A function that creates an observable that delivers event objects. It receives one argument, an object with the following properties: * * - `input` - Data that was provided to the event observable actor * - `self` - The parent actor * - `system` - The actor system to which the event observable actor belongs. * * It should return a {@link Subscribable}, which is compatible with an RxJS Observable, although RxJS is not required to create them. * * @example * ```ts * import { * fromEventObservable, * Subscribable, * EventObject, * createMachine, * createActor * } from 'xstate'; * import { fromEvent } from 'rxjs'; * * const mouseClickLogic = fromEventObservable(() => * fromEvent(document.body, 'click') as Subscribable * ); * * const canvasMachine = createMachine({ * invoke: { * // Will send mouse `click` events to the canvas actor * src: mouseClickLogic, * } * }); * * const canvasActor = createActor(canvasMachine); * canvasActor.start(); * ``` */ export declare function fromEventObservable(lazyObservable: ({ input, system }: { input: TInput; system: AnyActorSystem; self: ObservableActorRef; }) => Subscribable): ObservableActorLogic;