Skip to content

Commit

Permalink
👌
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos committed Mar 29, 2020
1 parent a878504 commit 8c07a7e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,12 @@ function prefetchAfterFirstMounted(apps: RegistrableApp[], opts?: ImportEntryOpt
});
}

function prefetchAll(apps: RegistrableApp[], opts?: ImportEntryOpts): void {
window.addEventListener('single-spa:no-app-change', function listener() {
if (process.env.NODE_ENV === 'development') {
console.log('[qiankun] prefetch starting for all assets...', apps);
}
apps.forEach(({ name, entry }) => prefetch(name, entry, opts));
function prefetchImmediately(apps: RegistrableApp[], opts?: ImportEntryOpts): void {
if (process.env.NODE_ENV === 'development') {
console.log('[qiankun] prefetch starting for apps...', apps);
}

window.removeEventListener('single-spa:no-app-change', listener);
});
apps.forEach(({ name, entry }) => prefetch(name, entry, opts));
}

export function prefetchApps(apps: RegistrableApp[], prefetchAction: Prefetch, importEntryOpts: ImportEntryOpts) {
Expand All @@ -114,7 +111,7 @@ export function prefetchApps(apps: RegistrableApp[], prefetchAction: Prefetch, i
(async () => {
// critical rendering apps would be prefetch as earlier as possible
const { criticalAppNames = [], minorAppsName = [] } = await prefetchAction(apps);
prefetchAll(appsName2Apps(criticalAppNames), importEntryOpts);
prefetchImmediately(appsName2Apps(criticalAppNames), importEntryOpts);
prefetchAfterFirstMounted(appsName2Apps(minorAppsName), importEntryOpts);
})();
} else {
Expand All @@ -124,7 +121,7 @@ export function prefetchApps(apps: RegistrableApp[], prefetchAction: Prefetch, i
break;

case 'all':
prefetchAll(apps, importEntryOpts);
prefetchImmediately(apps, importEntryOpts);
break;

default:
Expand Down

0 comments on commit 8c07a7e

Please sign in to comment.