/// import { EventEmitter } from 'events'; import { History as CompatHistory } from 'history'; import { Overwrite } from 'utility-types'; import Pointer, { IPointerMatch } from "./pointer"; export declare type RouteCallback = (name: string, params: Map, query: Map) => void; export interface IRoute { /** * Route unique identifier */ name: string; path: string; callback: RouteCallback; onBefore?: (match: IPointerMatch, replace: UpdateStateCallback, push: UpdateStateCallback) => void; } /** * How user should pass query to router */ export declare type IRouteInputQuery = Map; /** * Input params for router methods */ export declare type IRouteInputParams = Map; export declare type UpdateStateCallback = (name: string, params?: IRouteInputParams, query?: IRouteInputParams) => void; export declare type IRouteOnParameter = Overwrite; export declare type IRouteMatch = IPointerMatch & { query: Map; }; export declare enum StateChangeType { Push = 1, Replace = 2 } declare class Router extends EventEmitter { private history; routes: Map; pointer: Pointer; /** * Pending route changing work */ pending?: Promise; /** * Next path changes */ private nextChanges; private callbackChange; private unlistenHistory?; constructor(history: CompatHistory); on(name: 'routeNotFound', callback: (newPath: string) => void): this; /** * Trigger state change without touching the history itself. */ reload(): void; /** * Listen to valid changes on route. Meaning, that it'll be called whenever you * change from one route to another. * @param callback Callback that will be called when route change is received */ listen(callback: RouteCallback): void; /** * Removes callback from callback change list. * @param callback Callback reference that was added through listen() */ removeRouteListener(callback: RouteCallback): void; addRoute({ name, path, callback, onBefore }: IRouteOnParameter): this; findRouteOrFail(name: string): IRoute; resolve(name: string, params?: IRouteInputParams, query?: IRouteInputQuery): string | undefined; /** * Start listening to history changes and execute * callbacks according to current path. Will be resolved when * the whole process was performed. */ init(): Promise; destroy(): void; /** * The same as `history.pushState` but it'll resolve name, params and query * into a valid pathname and push it to history * @param name Route name * @param params Route params * @param query Route query */ pushState(name: string, params?: IRouteInputParams, query?: IRouteInputQuery): Promise; /** * The same as `pushState` but it'll replace current state with resolved * pathname * @param name Route name * @param params Route params * @param query Route query */ replaceState(name: string, params?: IRouteInputParams, query?: IRouteInputQuery): Promise; private getLocationPath; private executeOnBefore; private onChangePath; private getMatchInformation; /** * Receive a path changing notification and trigger * the right callback of the route which it was changed to * @param newPath New path */ private changePath; private onRouteNotFound; private onMatchRoute; private changeState; } export default Router; //# sourceMappingURL=router.d.ts.map