///
///
import history = require("history");
import { AbstractAction, AbstractSkeletosState, ISkeletosCommand, SkeletosCursor } from "skeletos";
import { AbstractRootRouteState } from "../../";
import { HammerpackWebserviceUtil } from "skeletos-hammerpack";
/**
* An abstract action that allows you to use Skeletos and skeletos-web-router and turn your application into a Single
* Page Application.
*/
export declare abstract class AbstractInitializeBrowserAction extends AbstractAction {
/**
* The corresponding cursor for #rootState.
*/
protected rootCursor: SkeletosCursor;
/**
* The root state that we created from deserializing the serialized state stored in window.
*/
protected rootState: RootStateType;
/**
* The original Console handler before we hook into it.
*/
protected oldConsoleHandlers: {
[name: string]: IConsoleHandler;
};
/**
* The HammerpackUtils for things like figuring out static resource paths.
*/
protected hammerpackUtil: HammerpackWebserviceUtil;
/**
* An instance of the History object to listen and change URL state.
*/
protected browserHistory: history.History;
/**
* Use this to compare the old route and new changed route on Skeletos state changes.
*/
private oldRootRouteState;
/**
* Use this to compare the hash of old route and new changed route on Skeletos state changes.
*/
private oldRootRouteStateFastCompare;
/**
* Use this to compare the old URL and the new URL on URL History changes.
*/
private oldLocation;
constructor();
protected getCommands(): ISkeletosCommand[] | object;
/**
* Hooks the console so that every time there is an error or a warning in the console, you have the opportunity
* to display the error somewhere else or to even send it back to the server or to analytics.
*/
protected hookConsole(): void;
/**
* Sets up the default logger.
*
* Default: uses ConsoleLogger. Note that all errors and warnings output in the console can also be hooked
* separately using onConsoleError() and onConsoleWarning().
*/
protected setupLogger(): void;
/**
* What to do when there is an error.
*
* @param message
* @param optionalParams
*/
protected onConsoleError(message?: any, ...optionalParams: any[]): void;
/**
* What to do when there is a warning.
*
* @param message
* @param optionalParams
*/
protected onConsoleWarning(message?: any, ...optionalParams: any[]): void;
/**
* Deserializes the Skeletos state that is stored in window on page load/hot-reload.
*/
protected deserializeSkeletosState(): void;
/**
* Deserializes and stores the hammerpack params in #hammerpackUtil.
*/
protected deserializeHammerpack(): void;
/**
* Initializes the locale. By default, doesn't do anything.
*/
protected initializeLocale(): void;
/**
* Initializes client-side routing. This gives you the ability to act as a Single Page Application.
*/
protected initializeRouting(): void;
/**
* If you want to block the page from transitioning to another page, then return a string -- a question for the
* user that they can say yes or no to -- so as to allow or prevent the user from leaving the page.
*
* For example, "You have unsaved changes, which you will lose if you navigate away from this page Are you sure you
* want to navigate away from this page?"
*
* If you want to block the page from transitioning without a string, return false explicitly.
*
* If you do not want to block the page from transitioning, do not return anything, or return null, or return undefined.
*
* Default: returns null.
*
* @param {Location} targetLocation
* @param {RootRouteStateType} targetRootRouteState
* @param {RootRouteStateType} currentRootRouteState
* @returns {string | false | void | null}
*/
protected getLeavePagePrompt(targetLocation: history.Location, targetRootRouteState: RootRouteStateType, currentRootRouteState: RootRouteStateType, currentRootState: RootStateType): string | false | void;
/**
* What happens where this is a change in the URL? Use this to, for example, add hooks into Google Analytics.
*
* Default: changes the document title based on `#getRootRouteState(..).pageMetadata.title`
*
* @param {Location} location
*/
protected onUrlChange(location: history.Location, currentRootRouteState: RootRouteStateType, oldRootRouteState: RootRouteStateType): void;
/**
* Renders the page.
*
* @param {RootStateType} rootState
* @param {RootRouteStateType} rootRouteState
*/
protected abstract render(rootState: RootStateType, rootRouteState: RootRouteStateType): void;
/**
* What to do upon hot reload. Typically you would want to re-render your page.
*
* Default: calls `#render()`
*/
protected onHotModuleReload(): void;
/**
* What to do before the hot-reload is going to be reloaded. Typically, we would want to save any client state
* somewhere then reload that state when we are reloaded.
*/
onBeforeHotModuleReload(): void;
/**
* Creates a root state using the given cursor.
*
* @param {SkeletosCursor} rootCursor
* @returns {RootStateType}
*/
protected abstract createRootState(rootCursor: SkeletosCursor): RootStateType;
/**
* Gets the root route state from the root state.
*
* @param {RootStateType} rootState
* @returns {RootRouteStateType}
*/
protected abstract getRootRouteState(rootState: RootStateType): RootRouteStateType;
protected doBeforeExecute(): void;
protected doAfterExecute(err?: Error): void;
private doHookConsole(messageType, handler);
private doStateChange();
private doUrlChange(location);
private locationToString(location);
private doRender();
}
export declare type IConsoleHandler = (message?: any, ...optionalParams: any[]) => void;