import { Container, DelegateDef } from '../core'; import * as Environment from '../environment'; import Message, { MessageConstructor } from '../message'; import StateManager, { Callback, Config } from './state_manager'; export declare type ExecContextPartial = { relay: () => object; state?: (cfg?: object) => object; path?: string[]; }; export declare type ExecContextDef = { env?: Environment.Environment; container: Container; parent?: ExecContext | ExecContextPartial; delegate?: DelegateDef; }; /** * Binds together a container, environment, and a state manager to handles message execution within a * container. * * @param {Function} getContainer A function that returns the container context to operate in * @param {Map} updateMap A Map instance pairing message constructors to update handlers * @param {Function} init An initialization function that executes the container's `init` function * with the initial state. * @return {Object} Returns an execution handler with the following functions: * - initialize: A wrapper function used to delay the container's initial execution until its API * is invoked * - dispatch: Accepts a message to dispatch to the container */ export default class ExecContext { /** * Returns true if the passed context is a partial definition and not a full `ExecContext` instance. */ static isPartial: (ctx: ExecContext | ExecContextPartial) => boolean; id: string; parent?: ExecContext; delegate?: DelegateDef; path: (string | symbol)[]; env?: Environment.Environment; container?: Container; protected errLog: any; protected getState: (params?: object) => object; protected stateMgr?: StateManager; constructor({ env, container, parent, delegate }: ExecContextDef); subscribe(listener: Callback, config?: Config): () => any; /** * Checks that a Message object is valid and is handled by the bound container, then dispatches it. */ dispatch(msg: Message): any; commands(msg: any, cmds: any): any; commandDispatcher(): any; push(val: any, config?: object & { path: any[]; }): any; state(cfg?: object): object; /** * Returns the container's relay value, based on the state of the current model. */ relay(): any; /** * Returns a Redux-compatible reducer, which optionally accepts a map of action types to message constructors * which the container should handle. * * @param {Object} msgTypes */ reducer(msgTypes?: {}): (prev: any, action: any) => object; /** * Returns a function that wraps a DOM event in a message and dispatches it to the attached container. */ emit(msgType: any): (x: any) => any; /** * Called when the execution context shuts down. Clears attached subscription processes. */ destroy(): void; /** * Checks if the container or container's ancestor handles messages of a given type * * @param msgType A message constructor * @return Returns true if the container (or an ancestor) has an update handler matching * the given constructor, otherwise false. */ get handles(): (msgType: MessageConstructor) => boolean; stateManager(): StateManager; private subscriptions; private internalDispatch; }