/** * Router should match given message to defined controller. * @constructor * @param {function} [resolveFunc] used as parser for message to match with controllers. * @param Controller Function Interface, supposed to be, for example, (msg: chrome.runtime.ExtensionMessage) => any */ export declare class Router any> { /** * `_NotFoundController` is a default controller for unmatched routing. * @private * @static */ private static _NotFoundController; resolveFunc: (message: any, sender?: any) => any; routes: { [name: string]: T; }; constructor(resolveFunc?: any); /** * `on` can register ControllerFunc to specified route name. * @param {string} name routing name for given ControllerFunc * @param {function} controllerFunc exacutable function when specified route is matched */ on(name: string, controllerFunc: T): void; /** * `listener` provides listener function which can satisfy Chrome EventListener Func. * @return {function} EventListenerFunction * @see https://developer.chrome.com/extensions/runtime#event-onMessage */ listener(): T; /** * `listen` is an entry point for each `onMessage` invocation. * @private * parameters below are defined by `chorme` EventListener interface. * @param {any} message * @param {any} sender * @param {function} sendResponse * * TODO: some chrome interface can receive more than 1 arguments, * TODO: e.g. https://developer.chrome.com/apps/notifications#event-onButtonClicked * TODO: to handle this varieties of EventListener interfaces, * TODO: it should handle `arguments` and see if the last arg is Func. */ private listen; /** * `match` resolves message to routing name, and return registered controller. * @private * @param {any} message * @param {any} sender * @return {function} Matched Controller */ private match; /** * @private * `_resolveRoute` resolve given message to routing name if matched. * It prefers "resolveFunc" if it is given in constructor. * @param {any} message * @param {any} sender * @return {string} Matched Routing Name */ private _resolveRoute; /** * @private * `_defaultResolveFunc` is a default resolve func, * which simply resolves routing name with priorities bellow * 1. just use message itself, if the message is `string` * 2. just use message.act or message.action, if the message is object. * @param {any} message * @return {string} Routing Name */ private _defaultResolveFunc; /** * `_formatResponse` regulates response format. * @private * @param {any} response */ private _formatResponse; }