lib/Router.js
function Router(window, urlStateMap, frontController)
{
        EventEmitter.call(this);
        this.window = window;
        this.urlStateMap = urlStateMap;
        this.frontController = frontController;
        this.currentStateList = null;

        this._pendingTransitionPromise = null;
        this._pendingReplace = null;
        this._initialHistoryState = null;
        this._queue = {
                hasEntry: false,
                stateList: null,
                fromHistory: false,
                upgrade: false,
                push: false,
                promise: null,
                resolve: null,
                reject: null
        };

        if (!window || !urlStateMap || !frontController)
        {
                throw Error('Missing argument');
        }

        if (typeof this.urlStateMap.toURL !== 'function' ||
            typeof this.urlStateMap.fromURL !== 'function')
        {
                throw Error('Argument `urlStateMap` must implement toURL(states) and fromURL(url)');
        }

        if (!Router.isSupported(this.window))
        {
                throw Error('Argument `window` does not support the history API');
        }

        if (this.frontController.isStatefulController1 !== true)
        {
                throw Error('Argument `frontController` is not a stateful-controller');
        }

        this._onpopstate = this._onpopstate.bind(this);
}
function Router(window, urlStateMap, frontController)
{
        EventEmitter.call(this);
        this.window = window;
        this.urlStateMap = urlStateMap;
        this.frontController = frontController;
        this.currentStateList = null;

        this._pendingTransitionPromise = null;
        this._pendingReplace = null;
        this._initialHistoryState = null;
        this._queue = {
                hasEntry: false,
                stateList: null,
                fromHistory: false,
                upgrade: false,
                push: false,
                promise: null,
                resolve: null,
                reject: null
        };

        if (!window || !urlStateMap || !frontController)
        {
                throw Error('Missing argument');
        }

        if (typeof this.urlStateMap.toURL !== 'function' ||
            typeof this.urlStateMap.fromURL !== 'function')
        {
                throw Error('Argument `urlStateMap` must implement toURL(states) and fromURL(url)');
        }

        if (!Router.isSupported(this.window))
        {
                throw Error('Argument `window` does not support the history API');
        }

        if (this.frontController.isStatefulController1 !== true)
        {
                throw Error('Argument `frontController` is not a stateful-controller');
        }

        this._onpopstate = this._onpopstate.bind(this);
}
A client-side router for `stateful-controller` using the history API
@module stateful-controller-browser-router
@author Joris van der Wel <joris@jorisvanderwel.com>
 Construct a new router

@constructor
@augments EventEmitter
@alias module:stateful-controller-browser-router
@param {!Window} window The window containing your DOM Document. In the browser you should simple pass `window` here
@param {!URLStateMap} urlStateMap An object implementing two functions: `toURL(StateList) -> string` and `fromURL(string) -> StateList`
@param {!module:stateful-controller/lib/Controller} frontController The controller to trigger transitions on. This is the ancestor of all your other controllers.