Skip to content

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

@mickmcgrath13

Description

@mickmcgrath13

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();
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions