Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow packages in window.Packages to return a .then-able #189

Open
mickmcgrath13 opened this issue Nov 10, 2016 · 0 comments
Open

Allow packages in window.Packages to return a .then-able #189

mickmcgrath13 opened this issue Nov 10, 2016 · 0 comments

Comments

@mickmcgrath13
Copy link
Contributor

mickmcgrath13 commented Nov 10, 2016

Original issue in canjs canjs/canjs/issues/2706
Corresponding bit-docs-prettify issue: bit-docs/bit-docs-prettify/issues/5

Where we loop over the packages, look for a deferred (has .then) and wait for that to resolve before proceeding.

Something like:

function processPackages(packageIndex, callback){
  var i = packageIndex || 0,
    packageNames = Object.keys(window.PACKAGES),
    packageName, packageResult;

  if(i === packageNames.length){
    if(typeof callback === 'function'){
      callback();
    }
    return;
  }

  packageName = packageNames[i];
    if (typeof window.PACKAGES[packageName] === 'function') {
        packageResult = window.PACKAGES[packageName]();
        if(packageResult && packageResult.then){
          packageResult.then(function(){
            processPackages(i+1, callback);
          });
        }else{
          processPackages(i+1, callback);
        }
    }else{
      processPackages(i+1, callback);
    }
};

// go through every package and re-init
processPackages(0, function(){
  init();
  setDocTitle();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant