import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription, StateConfig, InteropSubscribable } from './types'; import { State } from './State'; import { symbolObservable } from './utils'; import { AreAllImplementationsAssumedToBeProvided, MissingImplementationsError, TypegenDisabled } from './typegenTypes'; export declare type StateListener = any, TTypestate extends Typestate = { value: any; context: TContext; }, TResolvedTypesMeta = TypegenDisabled> = (state: State, event: TEvent) => 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 enum InterpreterStatus { NotStarted = 0, Running = 1, Stopped = 2 } export declare class Interpreter = { value: any; context: TContext; }, TResolvedTypesMeta = TypegenDisabled> implements ActorRef> { machine: StateMachine; /** * The default interpreter options: * * - `clock` uses the global `setTimeout` and `clearTimeout` functions * - `logger` uses the global `console.log()` method */ static defaultOptions: { execute: boolean; deferEvents: boolean; clock: Clock; logger: any; devTools: boolean; }; /** * The current state of the interpreted machine. */ private _state?; private _initialState?; /** * 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; status: InterpreterStatus; parent?: Interpreter; id: string; /** * The globally unique process ID for this invocation. */ sessionId: string; children: Map>; private forwardTo; private _outgoingQueue; private devTools?; private _doneEvent?; /** * 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?: InterpreterOptions); get initialState(): State; /** * @deprecated Use `.getSnapshot()` instead. */ get state(): State; 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): this; subscribe(observer: Partial>>): Subscription; subscribe(nextListener?: (state: State) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription; /** * Adds an event listener that is notified whenever an event is sent to the running interpreter. * @param listener The event listener */ onEvent(listener: EventListener): this; /** * Adds an event listener that is notified whenever a `send` event occurs. * @param listener The event listener */ onSend(listener: EventListener): this; /** * Adds a context listener that is notified whenever the state context changes. * @param listener The context listener */ onChange(listener: ContextListener): this; /** * Adds a listener that is notified when the machine is stopped. * @param listener The listener */ onStop(listener: Listener): this; /** * Adds a state listener that is notified when the statechart has reached its final state. * @param listener The state listener */ onDone(listener: EventListener): this; /** * Removes a listener. * @param listener The listener to remove */ off(listener: (...args: any[]) => void): this; /** * Alias for Interpreter.prototype.start */ init: (initialState?: State | StateConfig | StateValue) => this; /** * Starts the interpreter from the given state, or the initial state. * @param initialState The state to start the statechart from */ start(initialState?: State | StateConfig | StateValue): this; private _stopChildren; private _stop; /** * Stops the interpreter and unsubscribe all listeners. * * This will also notify the `onStop` listeners. */ stop(): this; /** * 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> | SCXML.Event, payload?: EventData) => 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; private sendTo; private _nextState; /** * 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: Event | SCXML.Event): State; private forward; private defer; private cancel; private _exec; private exec; private removeChild; private stopChild; spawn(entity: Spawnable, name: string, options?: SpawnOptions): ActorRef; spawnMachine(machine: StateMachine, options?: { id?: string; autoForward?: boolean; sync?: boolean; }): ActorRef>; private spawnBehavior; private spawnPromise; private spawnCallback; private spawnObservable; private spawnActor; private spawnActivity; private spawnEffect; private attachDev; toJSON(): { id: string; }; [Symbol.observable](): InteropSubscribable>; getSnapshot(): State; } export declare function spawn>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom; export declare function spawn(entity: StateMachine, nameOrOptions?: string | SpawnOptions): ActorRefFrom>; export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): ActorRef; /** * 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 = { value: any; context: TContext; }, TResolvedTypesMeta = TypegenDisabled>(machine: AreAllImplementationsAssumedToBeProvided extends true ? StateMachine : MissingImplementationsError, options?: InterpreterOptions): Interpreter; export {}; //# sourceMappingURL=interpreter.d.ts.map