src/loader.js
function load(target) {
      if (!loaded[target]) {
        var def = componentDirectory[target];
        // Initialize component, this won't cause an infinite loop because
        // we've already check that the componentDirectory is a DAG
        let requires = def.requires || [];
        return loaded[target] = Promise.all(requires.map(load)).then(deps => {
          let ctx = {};
          for (let i = 0; i < deps.length; i++) {
            ctx[def.requires[i]] = deps[i];
          }
          return new Promise((resolve, reject) => {
            try {
              resolve(def.setup.call(null, ctx));
            } catch (err) {
              reject(err);
            }
          }).catch(function(err) {
            debug(`error while loading component '${target}': ${err}`);
            throw err;
          });
        });
      }
      return loaded[target];
    }
function load(target) {
      if (!loaded[target]) {
        var def = componentDirectory[target];
        // Initialize component, this won't cause an infinite loop because
        // we've already check that the componentDirectory is a DAG
        let requires = def.requires || [];
        return loaded[target] = Promise.all(requires.map(load)).then(deps => {
          let ctx = {};
          for (let i = 0; i < deps.length; i++) {
            ctx[def.requires[i]] = deps[i];
          }
          return new Promise((resolve, reject) => {
            try {
              resolve(def.setup.call(null, ctx));
            } catch (err) {
              reject(err);
            }
          }).catch(function(err) {
            debug(`error while loading component '${target}': ${err}`);
            throw err;
          });
        });
      }
      return loaded[target];
    }
function load ( target ) { if ( ! loaded [ target ] ) { var def = componentDirectory [ target ] ; // Initialize component, this won't cause an infinite loop because // we've already check that the componentDirectory is a DAG let requires = def . requires || [ ] ; return loaded [ target ] = Promise . all ( requires . map ( load ) ) . then ( deps => { let ctx = { } ; for ( let i = 0 ; i < deps . length ; i ++ ) { ctx [ def . requires [ i ] ] = deps [ i ] ; } return new Promise ( ( resolve , reject ) => { try { resolve ( def . setup . call ( null , ctx ) ) ; } catch ( err ) { reject ( err ) ; } } ) . catch ( function ( err ) { debug ( ` ${ target } ${ err } ` ) ; throw err ; } ) ; } ) ; } return loaded [ target ] ; }
Load a component
Load a component