Skip to content

Commit

Permalink
✨ fallback to get exports from window[appName] while entry module exp…
Browse files Browse the repository at this point in the history
…orts not found (#131)
  • Loading branch information
kuitos authored and howel52 committed Nov 4, 2019
1 parent dd41251 commit 1c36acc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,14 @@ export function registerMicroApps<T extends object = {}>(

await execHooksChain(toArray(beforeLoad), app);

// 获取 模块/应用 导出的 lifecycle hooks
const { bootstrap: bootstrapApp, mount, unmount } = await execScripts(jsSandbox);
// get the lifecycle hooks from module exports
// fallback to global variable who named with ${appName} while module exports not found
const globalVariableExports = (window as any)[appName] || {};
const {
bootstrap: bootstrapApp = globalVariableExports.bootstrap,
mount = globalVariableExports.mount,
unmount = globalVariableExports.unmount,
} = await execScripts(jsSandbox);

if (!isFunction(bootstrapApp) || !isFunction(mount) || !isFunction(unmount)) {
throw new Error(`You need to export the functional lifecycles in ${appName} entry`);
Expand Down

0 comments on commit 1c36acc

Please sign in to comment.