import { Event, BaseMachine, TransitionNames, TransitionArgs } from './index'; /** * Minimal reference shared by machine actors and actor-like adapters. * * @typeParam T - Snapshot returned to readers and subscribers. * @typeParam E - Event accepted by {@link ActorRef.dispatch}. */ export interface ActorRef { /** Enqueues an event for processing. */ dispatch: (event: E) => void; /** Returns the actor's current snapshot synchronously. */ getSnapshot: () => T; /** Observes successful snapshot replacements; returns an unsubscribe callback. */ subscribe: (observer: (state: T) => void) => () => void; } /** * Inspection event type. */ export type InspectionEvent = { type: '@actor/send'; actor: ActorRef; event: unknown; snapshot: unknown; }; /** * A reactive container for a state machine that handles dispatching, * queueing of async transitions, and state observability. * * Events are processed in arrival order. A promise-returning transition blocks * later events until it settles. Stopping the actor invalidates pending results, * clears queued events, and removes subscribers. * * @typeParam M - Complete machine or typestate union owned by the actor. * @example * ```ts * const actor = createActor(counter); * actor.subscribe(snapshot => console.log(snapshot.context.count)); * actor.send.add(2); * actor.ref.send({ type: 'reset', args: [] }); * ``` */ export declare class Actor> implements ActorRef> { private _state; private _observers; private _queue; private _processing; private _stopped; private _generation; private static _inspector; /** * Registers a global inspector. */ static inspect(inspector: ((event: InspectionEvent) => void) | null): void; /** * The "Magic" Dispatcher. * Maps machine transition names to callable functions. */ readonly send: { [K in TransitionNames]: (...args: TransitionArgs) => void; }; /** * A stable reference to the dispatch method, useful for passing around. */ readonly ref: { send: (event: Event) => void; }; constructor(initialMachine: M); /** * Returns the current immutable snapshot of the machine. */ getSnapshot(): M; /** * Subscribes to state changes. * @param observer Callback function to be invoked on every state change. * @returns Unsubscribe function. */ subscribe(observer: (state: M) => void): () => void; /** * Selects a slice of the state. */ select(selector: (state: M) => T): T; /** * Starts the actor. */ start(): this; /** * Stops the actor. */ stop(): void; /** * Dispatches an event to the actor. * Handles both sync and async transitions. */ dispatch(event: Event): void; private _flush; private _notify; } /** * Creates an actor that owns and serializes transitions for `machine`. * * @typeParam M - Machine or typestate union to own. * @param machine - Initial immutable snapshot. * @returns A stopped-state-aware actor with RPC-style `send` and event-style `ref.send`. * @example * ```ts * const actor = createActor(createCounter({ count: 0 })); * actor.send.increment(); * ``` */ export declare function createActor>(machine: M): Actor; /** * Creates an actor reference from a machine; alias of {@link createActor}. * * @typeParam M - Machine or typestate union to own. * @param machine - Initial immutable snapshot. * @returns The actor through the portable {@link ActorRef} interface. */ export declare function spawn>(machine: M): ActorRef>; /** * Creates an actor whose context tracks one eagerly started promise. * * The promise function runs in a microtask after construction. Resolution moves * context to `resolved`; rejection moves it to `rejected`. Stopping the actor * prevents later snapshot replacement but does not cancel the underlying promise. * * @typeParam T - Promise fulfillment value. * @param promiseFn - Lazy promise producer invoked once. * @returns An actor with pending/resolved/rejected context. * @example * ```ts * const request = fromPromise(() => fetch('/api').then(r => r.json())); * request.subscribe(snapshot => console.log(snapshot.context.status)); * ``` */ export declare function fromPromise(promiseFn: () => Promise): Actor, ...args: any[]) => any>>>; /** * Creates an actor whose context follows an Observable-like source. * * `next`, `error`, and `complete` notifications become actor transitions. * Calling `actor.stop()` unsubscribes from the source exactly once. * * @typeParam T - Observable value type. * @param observable - Source exposing an RxJS-compatible `subscribe` method. * @returns An actor with active/done/error context. * @example * ```ts * const actor = fromObservable(source$); * actor.subscribe(snapshot => console.log(snapshot.context)); * actor.stop(); // also unsubscribes from source$ * ``` */ export declare function fromObservable(observable: { subscribe: (next: (val: T) => void, error?: (err: unknown) => void, complete?: () => void) => { unsubscribe: () => void; }; }): Actor, ...args: any[]) => any>>>; //# sourceMappingURL=actor.d.ts.map