Skip to content

Commit

Permalink
♻️ refactor some variable name (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos committed Oct 10, 2020
1 parent 0a6b7ee commit 9ab4607
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/loader.ts
Expand Up @@ -4,7 +4,7 @@
*/

import { importEntry } from 'import-html-entry';
import { concat, mergeWith, forEach } from 'lodash';
import { concat, forEach, mergeWith } from 'lodash';
import { LifeCycles, ParcelConfigObject } from 'single-spa';
import getAddOns from './addons';
import { getMicroAppStateActions } from './globalState';
Expand All @@ -14,11 +14,11 @@ import {
Deferred,
getDefaultTplWrapper,
getWrapperId,
isEnableScopedCSS,
performanceMark,
performanceMeasure,
toArray,
validateExportLifecycle,
isEnableScopedCSS,
} from './utils';

function assertElementExist(element: Element | null | undefined, msg?: string) {
Expand Down Expand Up @@ -246,11 +246,11 @@ export async function loadApp<T extends object>(
const enableScopedCSS = isEnableScopedCSS(configuration);

const appContent = getDefaultTplWrapper(appInstanceId, appName)(template);
let element: HTMLElement | null = createElement(appContent, strictStyleIsolation);
if (element && isEnableScopedCSS(configuration)) {
const styleNodes = element.querySelectorAll('style') || [];
let appWrapperElement: HTMLElement | null = createElement(appContent, strictStyleIsolation);
if (appWrapperElement && isEnableScopedCSS(configuration)) {
const styleNodes = appWrapperElement.querySelectorAll('style') || [];
forEach(styleNodes, (stylesheetElement: HTMLStyleElement) => {
css.process(element!, stylesheetElement, appName);
css.process(appWrapperElement!, stylesheetElement, appName);
});
}

Expand All @@ -261,15 +261,15 @@ export async function loadApp<T extends object>(

// 第一次加载设置应用可见区域 dom 结构
// 确保每次应用加载前容器 dom 结构已经设置完毕
render({ element, loading: true }, 'loading');
render({ element: appWrapperElement, loading: true }, 'loading');

const containerGetter = getAppWrapperGetter(
const appWrapperGetter = getAppWrapperGetter(
appName,
appInstanceId,
!!legacyRender,
strictStyleIsolation,
enableScopedCSS,
() => element,
() => appWrapperElement,
);

let global = window;
Expand All @@ -278,7 +278,7 @@ export async function loadApp<T extends object>(
if (sandbox) {
const sandboxInstance = createSandbox(
appName,
containerGetter,
appWrapperGetter,
Boolean(singular),
enableScopedCSS,
excludeAssetFilter,
Expand Down Expand Up @@ -331,15 +331,15 @@ export async function loadApp<T extends object>(
// 添加 mount hook, 确保每次应用加载前容器 dom 结构已经设置完毕
async () => {
// element would be destroyed after unmounted, we need to recreate it if it not exist
element = element || createElement(appContent, strictStyleIsolation);
render({ element, loading: true }, 'mounting');
appWrapperElement = appWrapperElement || createElement(appContent, strictStyleIsolation);
render({ element: appWrapperElement, loading: true }, 'mounting');
},
mountSandbox,
// exec the chain after rendering to keep the behavior with beforeLoad
async () => execHooksChain(toArray(beforeMount), app, global),
async props => mount({ ...props, container: containerGetter(), setGlobalState, onGlobalStateChange }),
// 应用 mount 完成后结束 loading
async () => render({ element, loading: false }, 'mounted'),
async props => mount({ ...props, container: appWrapperGetter(), setGlobalState, onGlobalStateChange }),
// finish loading after app mounted
async () => render({ element: appWrapperElement, loading: false }, 'mounted'),
async () => execHooksChain(toArray(afterMount), app, global),
// initialize the unmount defer after app mounted and resolve the defer after it unmounted
async () => {
Expand All @@ -356,14 +356,14 @@ export async function loadApp<T extends object>(
],
unmount: [
async () => execHooksChain(toArray(beforeUnmount), app, global),
async props => unmount({ ...props, container: containerGetter() }),
async props => unmount({ ...props, container: appWrapperGetter() }),
unmountSandbox,
async () => execHooksChain(toArray(afterUnmount), app, global),
async () => {
render({ element: null, loading: false }, 'unmounted');
offGlobalStateChange(appInstanceId);
// for gc
element = null;
appWrapperElement = null;
},
async () => {
if ((await validateSingularMode(singular, app)) && prevAppUnmountedDeferred) {
Expand Down

1 comment on commit 9ab4607

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for qiankun ready!

✅ Preview
https://qiankun-m3d1m9lnm.vercel.app

Built with commit 9ab4607.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.