export type Event_T = [name: string, payload: any]; export interface Machine_T { states: Array>; } export interface State_T { name: string; eventReactionCouplings: Array>; } export interface EventReactionCouplings_T { eventName: string; reactions: Array>; } export type Reaction_T = SideEffect_T | ContextMutation_T | Peer_T | Goto_T; export interface SideEffect_T { type: 'SideEffect'; fn: SideEffectFunction_T; } export type SideEffectFunction_T = (ctx: C, e: Event_T, self: Interpreter_T, originalContext: C) => void; export interface ContextMutation_T { type: 'ContextMutation'; fn: ContextMutationFunction_T; } export type ContextMutationFunction_T = (ctx: C, e: Event_T, self: Interpreter_T) => C; export interface Peer_T { type: 'SetPeer' | 'SetPeers' | 'AddPeers'; name: string; peerCreationFunction: PeerCreationFunction_T; } export type PeerCreationFunction_T = (ctx: C, e: Event_T, self: Interpreter_T) => Interpreter_T | Array>; export interface Goto_T { type: 'Goto'; targetStateName: string; } export declare const Machine: (...states: State_T[]) => Machine_T; export declare const State: (name: string, ...eventReactionCouplings: EventReactionCouplings_T[]) => State_T; export declare const On: (eventName: string, ...reactions: Reaction_T[]) => EventReactionCouplings_T; export declare const SideEffect: (fn: SideEffectFunction_T) => SideEffect_T; export declare const Goto: (targetStateName: string) => Goto_T; export declare const Context: (fn: ContextMutationFunction_T) => ContextMutation_T; export declare const Peer: (name: string, peerCreationFunction: PeerCreationFunction_T) => Peer_T; export declare const Peers: (name: string, peerCreationFunction: PeerCreationFunction_T) => Peer_T; export declare const AddPeers: (name: string, peerCreationFunction: PeerCreationFunction_T) => Peer_T; export interface Interpreter_T { machine: Machine_T; state: string; context: C; peers: Record | Array>>; peerSubscriptionIds: Map, string>; eventQueue: Array; subscriptionsToEvents: Record>; subscriptionsToState: Record>; subscriptionsToSettledState: Record>; isTransitioning: boolean; isPaused: boolean; start: () => Interpreter_T; Peer: (name: string, peer: Interpreter_T) => Interpreter_T; Peers: (name: string, peers: Array>) => Interpreter_T; } /** * Description placeholder * * @export * @param {Machine_T} machine * @param {any} initialContext * @param {?string} [initialStateName] * @returns {Interpreter_T} */ export declare function Interpreter(machine: Machine_T, initialContext: any, initialStateName?: string): Interpreter_T; export declare function start(interpreter: Interpreter_T): void; export declare function pause(interpreter: Interpreter_T): void; /** Inject an Event into the Interpreter's "tick queue". * * An event can be signify something "new" happening, such that its reactions should run on the next Tick; * or it can signify a milestone "within" the current Tick, such that a Tick can be thought of as having * "sub-Ticks". * * This distinction is significant for proper ordering of reaction execution, and also for determining * whether to run a reaction at all. If an Event is received, and is specified to be applied on a past * Tick, it is discarded. */ export declare function send(interpreter: Interpreter_T, event: Event_T): void; export declare const enqueue: typeof send; export type EventsSubscriptionCallbackFunction_T = (e: Event_T, self: Interpreter_T) => void; export type StateSubscriptionCallbackFunction_T = (e: Event_T, self: Interpreter_T) => void; export type SettledStateSubscriptionCallbackFunction_T = (self: Interpreter_T) => void; export declare function subscribe(interpreter: Interpreter_T, callback: SettledStateSubscriptionCallbackFunction_T): string; export declare const subscribeToSettledState: typeof subscribe; export declare function subscribeToState(interpreter: Interpreter_T, callback: StateSubscriptionCallbackFunction_T): string; export declare function subscribeToEvents(interpreter: Interpreter_T, callback: StateSubscriptionCallbackFunction_T): string; export declare function unsubscribe(interpreter: Interpreter_T, subscriptionId: string): void; export declare function setPeer(self: Interpreter_T, name: string, peer: Interpreter_T): void; export declare function setPeers(self: Interpreter_T, name: string, peers: Array>): void; export declare function addPeers(self: Interpreter_T, name: string, peers: Array>): void;