src/page.js
function makePage(cfg) {
    return (options) => {
        _.defaultsDeep(cfg, defaults);

        console.log('making page... options:', cfg);

        // return a promise that resolves after completion of the ajax request
        // if no ready method or url configuration exist, the promise is resolved immediately and the resultant dom is returned
        return new Promise((resolve, reject) => {
            if (_.isFunction(cfg.ready)) { // if present, call the ready function
                console.log('calling page ready... options:', options);
                // resolves promise with a doc if there is a response param passed
                // if the response param is null/falsy value, resolve with null (usefull for catching and supressing any navigation later)
                cfg.ready(options, (response) => resolve((response || _.isUndefined(response)) ? makeDom(cfg, response) : null), reject);
            } else if (cfg.url) { // make ajax request if a url is provided
                Ajax
                    .get(cfg.url, cfg.options)
                    .then((xhr) => {
                        resolve(makeDom(cfg, xhr.response));
                    }, (xhr) => {
                        // if present, call the error handler
                        if (_.isFunction(cfg.onError)) {
                            cfg.onError(xhr.response, xhr);
                        } else {
                            reject(xhr);
                        }
                    });
            } else { // no url/ready method provided, resolve the promise immediately
                resolve(makeDom(cfg));
            }
        });
    }
}
function makePage(cfg) {
    return (options) => {
        _.defaultsDeep(cfg, defaults);

        console.log('making page... options:', cfg);

        // return a promise that resolves after completion of the ajax request
        // if no ready method or url configuration exist, the promise is resolved immediately and the resultant dom is returned
        return new Promise((resolve, reject) => {
            if (_.isFunction(cfg.ready)) { // if present, call the ready function
                console.log('calling page ready... options:', options);
                // resolves promise with a doc if there is a response param passed
                // if the response param is null/falsy value, resolve with null (usefull for catching and supressing any navigation later)
                cfg.ready(options, (response) => resolve((response || _.isUndefined(response)) ? makeDom(cfg, response) : null), reject);
            } else if (cfg.url) { // make ajax request if a url is provided
                Ajax
                    .get(cfg.url, cfg.options)
                    .then((xhr) => {
                        resolve(makeDom(cfg, xhr.response));
                    }, (xhr) => {
                        // if present, call the error handler
                        if (_.isFunction(cfg.onError)) {
                            cfg.onError(xhr.response, xhr);
                        } else {
                            reject(xhr);
                        }
                    });
            } else { // no url/ready method provided, resolve the promise immediately
                resolve(makeDom(cfg));
            }
        });
    }
}
function makePage ( cfg ) { return ( options ) => { _ . defaultsDeep ( cfg , defaults ) ; console . log ( 'making page... options:' , cfg ) ; // return a promise that resolves after completion of the ajax request // if no ready method or url configuration exist, the promise is resolved immediately and the resultant dom is returned return new Promise ( ( resolve , reject ) => { if ( _ . isFunction ( cfg . ready ) ) { // if present, call the ready function console . log ( 'calling page ready... options:' , options ) ; // resolves promise with a doc if there is a response param passed // if the response param is null/falsy value, resolve with null (usefull for catching and supressing any navigation later) cfg . ready ( options , ( response ) => resolve ( ( response || _ . isUndefined ( response ) ) ? makeDom ( cfg , response ) : null ) , reject ) ; } else if ( cfg . url ) { // make ajax request if a url is provided Ajax . get ( cfg . url , cfg . options ) . then ( ( xhr ) => { resolve ( makeDom ( cfg , xhr . response ) ) ; } , ( xhr ) => { // if present, call the error handler if ( _ . isFunction ( cfg . onError ) ) { cfg . onError ( xhr . response , xhr ) ; } else { reject ( xhr ) ; } } ) ; } else { // no url/ready method provided, resolve the promise immediately resolve ( makeDom ( cfg ) ) ; } } ) ; } }
Generated a page function which returns a promise after invocation.

@private

@param  {Object} cfg     The page configuration object
@return {Function}       A function that returns promise upon execution
Generated a page function which returns a promise after invocation .