♻️ refactor some variable name (#987)

This commit is contained in:
Kuitos 2020-10-10 21:53:05 +08:00 committed by GitHub
parent 0b8027236f
commit f127251884

View File

@ -4,7 +4,7 @@
*/ */
import { importEntry } from 'import-html-entry'; 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 { LifeCycles, ParcelConfigObject } from 'single-spa';
import getAddOns from './addons'; import getAddOns from './addons';
import { getMicroAppStateActions } from './globalState'; import { getMicroAppStateActions } from './globalState';
@ -14,11 +14,11 @@ import {
Deferred, Deferred,
getDefaultTplWrapper, getDefaultTplWrapper,
getWrapperId, getWrapperId,
isEnableScopedCSS,
performanceMark, performanceMark,
performanceMeasure, performanceMeasure,
toArray, toArray,
validateExportLifecycle, validateExportLifecycle,
isEnableScopedCSS,
} from './utils'; } from './utils';
function assertElementExist(element: Element | null | undefined, msg?: string) { function assertElementExist(element: Element | null | undefined, msg?: string) {
@ -246,11 +246,11 @@ export async function loadApp<T extends object>(
const enableScopedCSS = isEnableScopedCSS(configuration); const enableScopedCSS = isEnableScopedCSS(configuration);
const appContent = getDefaultTplWrapper(appInstanceId, appName)(template); const appContent = getDefaultTplWrapper(appInstanceId, appName)(template);
let element: HTMLElement | null = createElement(appContent, strictStyleIsolation); let appWrapperElement: HTMLElement | null = createElement(appContent, strictStyleIsolation);
if (element && isEnableScopedCSS(configuration)) { if (appWrapperElement && isEnableScopedCSS(configuration)) {
const styleNodes = element.querySelectorAll('style') || []; const styleNodes = appWrapperElement.querySelectorAll('style') || [];
forEach(styleNodes, (stylesheetElement: HTMLStyleElement) => { forEach(styleNodes, (stylesheetElement: HTMLStyleElement) => {
css.process(element!, stylesheetElement, appName); css.process(appWrapperElement!, stylesheetElement, appName);
}); });
} }
@ -261,15 +261,15 @@ export async function loadApp<T extends object>(
// 第一次加载设置应用可见区域 dom 结构 // 第一次加载设置应用可见区域 dom 结构
// 确保每次应用加载前容器 dom 结构已经设置完毕 // 确保每次应用加载前容器 dom 结构已经设置完毕
render({ element, loading: true }, 'loading'); render({ element: appWrapperElement, loading: true }, 'loading');
const containerGetter = getAppWrapperGetter( const appWrapperGetter = getAppWrapperGetter(
appName, appName,
appInstanceId, appInstanceId,
!!legacyRender, !!legacyRender,
strictStyleIsolation, strictStyleIsolation,
enableScopedCSS, enableScopedCSS,
() => element, () => appWrapperElement,
); );
let global = window; let global = window;
@ -278,7 +278,7 @@ export async function loadApp<T extends object>(
if (sandbox) { if (sandbox) {
const sandboxInstance = createSandbox( const sandboxInstance = createSandbox(
appName, appName,
containerGetter, appWrapperGetter,
Boolean(singular), Boolean(singular),
enableScopedCSS, enableScopedCSS,
excludeAssetFilter, excludeAssetFilter,
@ -331,15 +331,15 @@ export async function loadApp<T extends object>(
// 添加 mount hook, 确保每次应用加载前容器 dom 结构已经设置完毕 // 添加 mount hook, 确保每次应用加载前容器 dom 结构已经设置完毕
async () => { async () => {
// element would be destroyed after unmounted, we need to recreate it if it not exist // element would be destroyed after unmounted, we need to recreate it if it not exist
element = element || createElement(appContent, strictStyleIsolation); appWrapperElement = appWrapperElement || createElement(appContent, strictStyleIsolation);
render({ element, loading: true }, 'mounting'); render({ element: appWrapperElement, loading: true }, 'mounting');
}, },
mountSandbox, mountSandbox,
// exec the chain after rendering to keep the behavior with beforeLoad // exec the chain after rendering to keep the behavior with beforeLoad
async () => execHooksChain(toArray(beforeMount), app, global), async () => execHooksChain(toArray(beforeMount), app, global),
async props => mount({ ...props, container: containerGetter(), setGlobalState, onGlobalStateChange }), async props => mount({ ...props, container: appWrapperGetter(), setGlobalState, onGlobalStateChange }),
// 应用 mount 完成后结束 loading // finish loading after app mounted
async () => render({ element, loading: false }, 'mounted'), async () => render({ element: appWrapperElement, loading: false }, 'mounted'),
async () => execHooksChain(toArray(afterMount), app, global), async () => execHooksChain(toArray(afterMount), app, global),
// initialize the unmount defer after app mounted and resolve the defer after it unmounted // initialize the unmount defer after app mounted and resolve the defer after it unmounted
async () => { async () => {
@ -356,14 +356,14 @@ export async function loadApp<T extends object>(
], ],
unmount: [ unmount: [
async () => execHooksChain(toArray(beforeUnmount), app, global), async () => execHooksChain(toArray(beforeUnmount), app, global),
async props => unmount({ ...props, container: containerGetter() }), async props => unmount({ ...props, container: appWrapperGetter() }),
unmountSandbox, unmountSandbox,
async () => execHooksChain(toArray(afterUnmount), app, global), async () => execHooksChain(toArray(afterUnmount), app, global),
async () => { async () => {
render({ element: null, loading: false }, 'unmounted'); render({ element: null, loading: false }, 'unmounted');
offGlobalStateChange(appInstanceId); offGlobalStateChange(appInstanceId);
// for gc // for gc
element = null; appWrapperElement = null;
}, },
async () => { async () => {
if ((await validateSingularMode(singular, app)) && prevAppUnmountedDeferred) { if ((await validateSingularMode(singular, app)) && prevAppUnmountedDeferred) {