import { StateMachine, Event, EventObject, DefaultContext, StateSchema, OmniEventObject, OmniEvent, InvokeCallback, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, Unsubscribable, MachineOptions } from './types'; import { State } from './State'; import { Actor } from './Actor'; export declare type StateListener = (state: State, event: OmniEventObject) => void; export declare type ContextListener = (context: TContext, prevContext: TContext | undefined) => void; export declare type EventListener = (event: TEvent) => void; export declare type Listener = () => void; export interface Clock { setTimeout(fn: (...args: any[]) => void, timeout: number): any; clearTimeout(id: any): void; } interface SpawnOptions { name?: string; autoForward?: boolean; sync?: boolean; } export declare class Interpreter implements Subscribable>, Actor, OmniEventObject> { machine: StateMachine; /** * The default interpreter options: * * - `clock` uses the global `setTimeout` and `clearTimeout` functions * - `logger` uses the global `console.log()` method */ static defaultOptions: InterpreterOptions; /** * The current state of the interpreted machine. */ state: State; /** * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions. */ clock: Clock; options: Readonly; private scheduler; private delayedEventsMap; private listeners; private contextListeners; private stopListeners; private doneListeners; private eventListeners; private sendListeners; private logger; /** * Whether the service is started. */ initialized: boolean; /** * The initial state of the machine. */ initialState: State; parent?: Interpreter; id: string; children: Map; private forwardTo; private devTools?; /** * Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any. * * @param machine The machine to be interpreted * @param options Interpreter options */ constructor(machine: StateMachine, options?: Partial); static interpret: typeof interpret; /** * Executes the actions of the given state, with that state's `context` and `event`. * * @param state The state whose actions will be executed * @param actionsConfig The action implementations to use */ execute(state: State, actionsConfig?: MachineOptions['actions']): void; private update; onTransition(listener: StateListener): Interpreter; subscribe(nextListener?: (state: State) => void, errorListener?: (error: any) => void, completeListener?: () => void): Unsubscribable; /** * Adds an event listener that is notified whenever an event is sent to the running interpreter. * @param listener The event listener */ onEvent(listener: EventListener): Interpreter; /** * Adds an event listener that is notified whenever a `send` event occurs. * @param listener The event listener */ onSend(listener: EventListener): Interpreter; /** * Adds a context listener that is notified whenever the state context changes. * @param listener The context listener */ onChange(listener: ContextListener): Interpreter; /** * Adds a listener that is notified when the machine is stopped. * @param listener The listener */ onStop(listener: Listener): Interpreter; /** * Adds a state listener that is notified when the statechart has reached its final state. * @param listener The state listener */ onDone(listener: EventListener): Interpreter; /** * Removes a listener. * @param listener The listener to remove */ off(listener: (...args: any[]) => void): Interpreter; /** * Alias for Interpreter.prototype.start */ init: (initialState?: string | import("./types").StateValueMap | State | undefined) => Interpreter; /** * Starts the interpreter from the given state, or the initial state. * @param initialState The state to start the statechart from */ start(initialState?: State | StateValue): Interpreter; /** * Stops the interpreter and unsubscribe all listeners. * * This will also notify the `onStop` listeners. */ stop(): Interpreter; /** * Sends an event to the running interpreter to trigger a transition. * * An array of events (batched) can be sent as well, which will send all * batched events to the running interpreter. The listeners will be * notified only **once** when all events are processed. * * @param event The event(s) to send */ send: (event: SingleOrArray>, payload?: (Record & { type?: undefined; }) | undefined) => State; private batch; /** * Returns a send function bound to this interpreter instance. * * @param event The event to be sent by the sender. */ sender(event: Event): () => State; sendTo: (event: OmniEventObject, to: string | number | Actor) => void; /** * Returns the next state given the interpreter's current state and the event. * * This is a pure method that does _not_ update the interpreter's state. * * @param event The event to determine the next state */ nextState(event: OmniEvent): State; private forward; private defer; private cancel; private exec; private stopChild; spawn(entity: Spawnable, name: string, options?: SpawnOptions): Actor; spawnMachine(machine: StateMachine, options?: { id?: string; autoForward?: boolean; sync?: boolean; }): Actor>; private spawnPromise; private spawnCallback; private spawnObservable; private spawnActivity; private spawnEffect; private reportUnhandledExceptionOnInvocation; private attachDev; toJSON(): { id: string; }; } export declare type Spawnable = StateMachine | Promise | InvokeCallback | Subscribable; export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): Actor; /** * Creates a new Interpreter instance for the given machine with the provided options, if any. * * @param machine The machine to interpret * @param options Interpreter options */ export declare function interpret(machine: StateMachine, options?: Partial): Interpreter; export {};