packages/rebound-router/lib/rebound-router.js
function(route, container) {

    var appName, routeName,
        isService = (container !== this.config.container),
        isError = (route === ERROR_ROUTE_NAME);

    // Normalize Route
    route || (route = '');

    // Get the app name from this route
    appName = routeName = (route.split('/')[0] || 'index');

    // If this isn't the error route, Find Any Custom Route Mappings
    if(!isService && !isError){
      this._currentRoute = route.split('/')[0];
      _.any(this.config.handlers, (handler) => {
        if (handler.regex.test(route)){
          appName = handler.app;
          this._currentRoute = handler.route;
          return true;
        }
      });
    }

    // Wrap these async resource fetches in a promise and return it.
    // This promise resolves when both css and js resources are loaded
    // It rejects if either of the css or js resources fails to load.
    return new Promise((resolve, reject) => {

      var throwError = (err) => {
        // If we are already in an error state, this means we were unable to load
        // a custom error page. Uninstall anything we have and insert our default 404 page.
        if(this.status === ERROR){
          if(isService) return resolve(err);
          this._uninstallResource();
          container.innerHTML = DEFAULT_404_PAGE;
          return resolve(err);
        }

        // Set our status to error and attempt to load a custom error page.
        console.error('Could not ' + ((isService) ? 'load the ' + appName + ' service:' : 'find the ' + (appName || 'index') + ' app.'), 'at', ('/' + route));
        this.status = ERROR;
        this._currentRoute = route;
        resolve(this._fetchResource(ERROR_ROUTE_NAME, container));
      };

      // If the values we got from installing our resources are unexpected, 404
      // Otherwise, set status, activate the css, and install the page component
      var install = (response) => {
        var cssElement = response[0], jsElement = response[1];
        if(!(cssElement instanceof Element) || !(jsElement instanceof Element) ) return throwError();
        (!isService && !isError) && (this.status = SUCCESS);
        cssElement && cssElement.removeAttribute('disabled');
        this._installResource(jsElement.getAttribute('data-name'), appName, container).then(resolve, resolve);
      };

      // If loading a page, set status to loading
      (!isService && !isError) && (this.status = LOADING);

      // If Page Is Already Loaded Then The Route Does Not Exist. 404 and Exit.
      if (this.current && this.current.__pageId === (this.uid + '-' + appName)){ return throwError(); }

      // Fetch our css and js in paralell, install or throw when both complete
      Promise.all([this._fetchCSS(routeName, appName), this._fetchJavascript(routeName, appName)])
      .then(install, throwError);

    });
  }
function(route, container) {

    var appName, routeName,
        isService = (container !== this.config.container),
        isError = (route === ERROR_ROUTE_NAME);

    // Normalize Route
    route || (route = '');

    // Get the app name from this route
    appName = routeName = (route.split('/')[0] || 'index');

    // If this isn't the error route, Find Any Custom Route Mappings
    if(!isService && !isError){
      this._currentRoute = route.split('/')[0];
      _.any(this.config.handlers, (handler) => {
        if (handler.regex.test(route)){
          appName = handler.app;
          this._currentRoute = handler.route;
          return true;
        }
      });
    }

    // Wrap these async resource fetches in a promise and return it.
    // This promise resolves when both css and js resources are loaded
    // It rejects if either of the css or js resources fails to load.
    return new Promise((resolve, reject) => {

      var throwError = (err) => {
        // If we are already in an error state, this means we were unable to load
        // a custom error page. Uninstall anything we have and insert our default 404 page.
        if(this.status === ERROR){
          if(isService) return resolve(err);
          this._uninstallResource();
          container.innerHTML = DEFAULT_404_PAGE;
          return resolve(err);
        }

        // Set our status to error and attempt to load a custom error page.
        console.error('Could not ' + ((isService) ? 'load the ' + appName + ' service:' : 'find the ' + (appName || 'index') + ' app.'), 'at', ('/' + route));
        this.status = ERROR;
        this._currentRoute = route;
        resolve(this._fetchResource(ERROR_ROUTE_NAME, container));
      };

      // If the values we got from installing our resources are unexpected, 404
      // Otherwise, set status, activate the css, and install the page component
      var install = (response) => {
        var cssElement = response[0], jsElement = response[1];
        if(!(cssElement instanceof Element) || !(jsElement instanceof Element) ) return throwError();
        (!isService && !isError) && (this.status = SUCCESS);
        cssElement && cssElement.removeAttribute('disabled');
        this._installResource(jsElement.getAttribute('data-name'), appName, container).then(resolve, resolve);
      };

      // If loading a page, set status to loading
      (!isService && !isError) && (this.status = LOADING);

      // If Page Is Already Loaded Then The Route Does Not Exist. 404 and Exit.
      if (this.current && this.current.__pageId === (this.uid + '-' + appName)){ return throwError(); }

      // Fetch our css and js in paralell, install or throw when both complete
      Promise.all([this._fetchCSS(routeName, appName), this._fetchJavascript(routeName, appName)])
      .then(install, throwError);

    });
  }
function ( route , container ) { var appName , routeName , isService = ( container !== this . config . container ) , isError = ( route === ERROR_ROUTE_NAME ) ; // Normalize Route route || ( route = '' ) ; // Get the app name from this route appName = routeName = ( route . split ( '/' ) [ 0 ] || 'index' ) ; // If this isn't the error route, Find Any Custom Route Mappings if ( ! isService && ! isError ) { this . _currentRoute = route . split ( '/' ) [ 0 ] ; _ . any ( this . config . handlers , ( handler ) => { if ( handler . regex . test ( route ) ) { appName = handler . app ; this . _currentRoute = handler . route ; return true ; } } ) ; } // Wrap these async resource fetches in a promise and return it. // This promise resolves when both css and js resources are loaded // It rejects if either of the css or js resources fails to load. return new Promise ( ( resolve , reject ) => { var throwError = ( err ) => { // If we are already in an error state, this means we were unable to load // a custom error page. Uninstall anything we have and insert our default 404 page. if ( this . status === ERROR ) { if ( isService ) return resolve ( err ) ; this . _uninstallResource ( ) ; container . innerHTML = DEFAULT_404_PAGE ; return resolve ( err ) ; } // Set our status to error and attempt to load a custom error page. console . error ( 'Could not ' + ( ( isService ) ? 'load the ' + appName + ' service:' : 'find the ' + ( appName || 'index' ) + ' app.' ) , 'at' , ( '/' + route ) ) ; this . status = ERROR ; this . _currentRoute = route ; resolve ( this . _fetchResource ( ERROR_ROUTE_NAME , container ) ) ; } ; // If the values we got from installing our resources are unexpected, 404 // Otherwise, set status, activate the css, and install the page component var install = ( response ) => { var cssElement = response [ 0 ] , jsElement = response [ 1 ] ; if ( ! ( cssElement instanceof Element ) || ! ( jsElement instanceof Element ) ) return throwError ( ) ; ( ! isService && ! isError ) && ( this . status = SUCCESS ) ; cssElement && cssElement . removeAttribute ( 'disabled' ) ; this . _installResource ( jsElement . getAttribute ( 'data-name' ) , appName , container ) . then ( resolve , resolve ) ; } ; // If loading a page, set status to loading ( ! isService && ! isError ) && ( this . status = LOADING ) ; // If Page Is Already Loaded Then The Route Does Not Exist. 404 and Exit. if ( this . current && this . current . __pageId === ( this . uid + '-' + appName ) ) { return throwError ( ) ; } // Fetch our css and js in paralell, install or throw when both complete Promise . all ( [ this . _fetchCSS ( routeName , appName ) , this . _fetchJavascript ( routeName , appName ) ] ) . then ( install , throwError ) ; } ) ; }
Fetches HTML and CSS
Fetches HTML and CSS