@micro-zoe/micro-app 1.0.0-beta.2 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +128 -80
- package/lib/index.esm.js.map +1 -1
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.map +1 -1
- package/lib/index.umd.js +1 -1
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/typings/global.d.ts +7 -0
package/lib/index.d.ts
CHANGED
|
@@ -243,7 +243,7 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
243
243
|
* @param target Accept cloned elements
|
|
244
244
|
* @param deep deep clone or transfer dom
|
|
245
245
|
*/
|
|
246
|
-
export function cloneContainer<T extends Element | ShadowRoot, Q extends Element | ShadowRoot>(
|
|
246
|
+
export function cloneContainer<T extends Element | ShadowRoot, Q extends Element | ShadowRoot>(target: Q, origin: T, deep: boolean): Q;
|
|
247
247
|
export function isInvalidQuerySelectorKey(key: string): boolean;
|
|
248
248
|
export function isUniqueElement(key: string): boolean;
|
|
249
249
|
/**
|
package/lib/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const version = '1.0.0-beta.
|
|
1
|
+
const version = '1.0.0-beta.3';
|
|
2
2
|
// do not use isUndefined
|
|
3
3
|
const isBrowser = typeof window !== 'undefined';
|
|
4
4
|
// do not use isUndefined
|
|
@@ -356,7 +356,7 @@ function pureCreateElement(tagName, options) {
|
|
|
356
356
|
* @param target Accept cloned elements
|
|
357
357
|
* @param deep deep clone or transfer dom
|
|
358
358
|
*/
|
|
359
|
-
function cloneContainer(
|
|
359
|
+
function cloneContainer(target, origin, deep) {
|
|
360
360
|
target.innerHTML = '';
|
|
361
361
|
if (deep) {
|
|
362
362
|
// TODO: ShadowRoot兼容,ShadowRoot不能直接使用cloneNode
|
|
@@ -562,7 +562,6 @@ var appStates;
|
|
|
562
562
|
(function (appStates) {
|
|
563
563
|
appStates["CREATED"] = "created";
|
|
564
564
|
appStates["LOADING"] = "loading";
|
|
565
|
-
appStates["LOADED"] = "loaded";
|
|
566
565
|
appStates["LOAD_FAILED"] = "load_failed";
|
|
567
566
|
appStates["MOUNTING"] = "mounting";
|
|
568
567
|
appStates["MOUNTED"] = "mounted";
|
|
@@ -1501,7 +1500,7 @@ function execScripts(app, initHook) {
|
|
|
1501
1500
|
// Notice the second render
|
|
1502
1501
|
if (appSpaceData.defer || appSpaceData.async) {
|
|
1503
1502
|
// TODO: defer和module彻底分开,不要混在一起
|
|
1504
|
-
if (scriptInfo.isExternal && !scriptInfo.code && !(app
|
|
1503
|
+
if (scriptInfo.isExternal && !scriptInfo.code && !isTypeModule(app, scriptInfo)) {
|
|
1505
1504
|
deferScriptPromise.push(fetchSource(address, app.name));
|
|
1506
1505
|
}
|
|
1507
1506
|
else {
|
|
@@ -1585,9 +1584,19 @@ function runScript(address, app, scriptInfo, callback, replaceElement) {
|
|
|
1585
1584
|
appSpaceData.sandboxType = sandboxType;
|
|
1586
1585
|
appSpaceData.parsedFunction = null;
|
|
1587
1586
|
}
|
|
1587
|
+
/**
|
|
1588
|
+
* TODO: 优化逻辑
|
|
1589
|
+
* 是否是内联模式应该由外部传入,这样自外而内更加统一,逻辑更加清晰
|
|
1590
|
+
*/
|
|
1588
1591
|
if (isInlineMode(app, scriptInfo)) {
|
|
1589
1592
|
const scriptElement = replaceElement || pureCreateElement('script');
|
|
1590
1593
|
runCode2InlineScript(address, appSpaceData.parsedCode, isTypeModule(app, scriptInfo), scriptElement, appSpaceData.attrs, callback);
|
|
1594
|
+
/**
|
|
1595
|
+
* TODO: 优化逻辑
|
|
1596
|
+
* replaceElement不存在说明是初始化执行,需要主动插入script
|
|
1597
|
+
* 但这里的逻辑不清晰,应该明确声明是什么环境下才需要主动插入,而不是用replaceElement间接判断
|
|
1598
|
+
* replaceElement还有可能是注释类型(一定是在后台执行),这里的判断都是间接判断,不够直观
|
|
1599
|
+
*/
|
|
1591
1600
|
if (!replaceElement) {
|
|
1592
1601
|
// TEST IGNORE
|
|
1593
1602
|
const parent = app.iframe ? app.sandBox.microBody : app.querySelector('micro-app-body');
|
|
@@ -1623,7 +1632,7 @@ function runDynamicRemoteScript(address, app, scriptInfo, originScript) {
|
|
|
1623
1632
|
runScript(address, app, scriptInfo, dispatchScriptOnLoadEvent, replaceElement);
|
|
1624
1633
|
!isTypeModule(app, scriptInfo) && dispatchScriptOnLoadEvent();
|
|
1625
1634
|
};
|
|
1626
|
-
if (scriptInfo.code || (app
|
|
1635
|
+
if (scriptInfo.code || isTypeModule(app, scriptInfo)) {
|
|
1627
1636
|
defer(runDynamicScript);
|
|
1628
1637
|
}
|
|
1629
1638
|
else {
|
|
@@ -2172,14 +2181,21 @@ function patchElementAndDocument() {
|
|
|
2172
2181
|
}
|
|
2173
2182
|
return globalEnv.rawRemoveChild.call(this, oldChild);
|
|
2174
2183
|
};
|
|
2184
|
+
/**
|
|
2185
|
+
* The insertAdjacentElement method of the Element interface inserts a given element node at a given position relative to the element it is invoked upon.
|
|
2186
|
+
* NOTE:
|
|
2187
|
+
* 1. parameter 2 of insertAdjacentElement must type 'Element'
|
|
2188
|
+
*/
|
|
2175
2189
|
rawRootElement.prototype.insertAdjacentElement = function (where, element) {
|
|
2176
2190
|
var _a;
|
|
2177
|
-
if (element === null || element === void 0 ? void 0 : element.__MICRO_APP_NAME__) {
|
|
2191
|
+
if ((element === null || element === void 0 ? void 0 : element.__MICRO_APP_NAME__) && isElement(element)) {
|
|
2178
2192
|
const app = appInstanceMap.get(element.__MICRO_APP_NAME__);
|
|
2179
2193
|
if (app === null || app === void 0 ? void 0 : app.container) {
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2194
|
+
const processedEle = handleNewNode(element, app);
|
|
2195
|
+
if (!isElement(processedEle))
|
|
2196
|
+
return element;
|
|
2197
|
+
const realParent = (_a = getHijackParent(this, processedEle, app)) !== null && _a !== void 0 ? _a : this;
|
|
2198
|
+
return globalEnv.rawInsertAdjacentElement.call(realParent, where, processedEle);
|
|
2183
2199
|
}
|
|
2184
2200
|
}
|
|
2185
2201
|
return globalEnv.rawInsertAdjacentElement.call(this, where, element);
|
|
@@ -3294,8 +3310,12 @@ class EventCenterForMicroApp extends EventCenterForGlobal {
|
|
|
3294
3310
|
* @param microAppEventCenter instance of EventCenterForMicroApp
|
|
3295
3311
|
*/
|
|
3296
3312
|
function recordDataCenterSnapshot(microAppEventCenter) {
|
|
3297
|
-
|
|
3298
|
-
|
|
3313
|
+
var _a, _b;
|
|
3314
|
+
if (microAppEventCenter) {
|
|
3315
|
+
microAppEventCenter.umdDataListeners = {
|
|
3316
|
+
global: new Set((_a = microAppEventCenter.umdDataListeners) === null || _a === void 0 ? void 0 : _a.global),
|
|
3317
|
+
normal: new Set((_b = microAppEventCenter.umdDataListeners) === null || _b === void 0 ? void 0 : _b.normal),
|
|
3318
|
+
};
|
|
3299
3319
|
const globalEventInfo = eventCenter.eventList.get('global');
|
|
3300
3320
|
if (globalEventInfo) {
|
|
3301
3321
|
for (const cb of globalEventInfo.callbacks) {
|
|
@@ -3306,7 +3326,9 @@ function recordDataCenterSnapshot(microAppEventCenter) {
|
|
|
3306
3326
|
}
|
|
3307
3327
|
const subAppEventInfo = eventCenter.eventList.get(createEventName(microAppEventCenter.appName, true));
|
|
3308
3328
|
if (subAppEventInfo) {
|
|
3309
|
-
|
|
3329
|
+
for (const cb of subAppEventInfo.callbacks) {
|
|
3330
|
+
microAppEventCenter.umdDataListeners.normal.add(cb);
|
|
3331
|
+
}
|
|
3310
3332
|
}
|
|
3311
3333
|
}
|
|
3312
3334
|
}
|
|
@@ -3331,7 +3353,7 @@ function rebuildDataCenterSnapshot(microAppEventCenter) {
|
|
|
3331
3353
|
* @param microAppEventCenter instance of EventCenterForMicroApp
|
|
3332
3354
|
*/
|
|
3333
3355
|
function resetDataCenterSnapshot(microAppEventCenter) {
|
|
3334
|
-
delete microAppEventCenter.umdDataListeners;
|
|
3356
|
+
microAppEventCenter === null || microAppEventCenter === void 0 ? true : delete microAppEventCenter.umdDataListeners;
|
|
3335
3357
|
}
|
|
3336
3358
|
|
|
3337
3359
|
// 管理 app 的单例
|
|
@@ -3473,19 +3495,23 @@ function createProxyDocument(appName, sandbox) {
|
|
|
3473
3495
|
* 3. prerender/keep-alive(default, umd): not clear timers, record & rebuild events
|
|
3474
3496
|
*/
|
|
3475
3497
|
const record = () => {
|
|
3476
|
-
|
|
3477
|
-
|
|
3498
|
+
/**
|
|
3499
|
+
* record onclick handler
|
|
3500
|
+
* onClickHandler maybe set again after prerender/keep-alive app hidden
|
|
3501
|
+
*/
|
|
3502
|
+
sstOnClickHandler = onClickHandler || sstOnClickHandler;
|
|
3478
3503
|
// record document event
|
|
3479
3504
|
eventListenerMap.forEach((listenerList, type) => {
|
|
3480
3505
|
if (listenerList.size) {
|
|
3481
|
-
sstEventListenerMap.
|
|
3506
|
+
const cacheList = sstEventListenerMap.get(type) || [];
|
|
3507
|
+
sstEventListenerMap.set(type, new Set([...cacheList, ...listenerList]));
|
|
3482
3508
|
}
|
|
3483
3509
|
});
|
|
3484
3510
|
};
|
|
3485
3511
|
// rebuild event and timer before remount app
|
|
3486
3512
|
const rebuild = () => {
|
|
3487
3513
|
// rebuild onclick event
|
|
3488
|
-
if (sstOnClickHandler)
|
|
3514
|
+
if (sstOnClickHandler && !onClickHandler)
|
|
3489
3515
|
proxyDocument.onclick = sstOnClickHandler;
|
|
3490
3516
|
// rebuild document event
|
|
3491
3517
|
sstEventListenerMap.forEach((listenerList, type) => {
|
|
@@ -3500,8 +3526,8 @@ function createProxyDocument(appName, sandbox) {
|
|
|
3500
3526
|
// Clear the function bound by micro app through document.onclick
|
|
3501
3527
|
if (isFunction(onClickHandler)) {
|
|
3502
3528
|
rawRemoveEventListener.call(rawDocument, 'click', onClickHandler);
|
|
3503
|
-
onClickHandler = null;
|
|
3504
3529
|
}
|
|
3530
|
+
onClickHandler = null;
|
|
3505
3531
|
// Clear document binding event
|
|
3506
3532
|
if (eventListenerMap.size) {
|
|
3507
3533
|
eventListenerMap.forEach((listenerList, type) => {
|
|
@@ -3631,7 +3657,8 @@ function patchWindowEffect(appName, microAppWindow) {
|
|
|
3631
3657
|
// record window event
|
|
3632
3658
|
eventListenerMap.forEach((listenerList, type) => {
|
|
3633
3659
|
if (listenerList.size) {
|
|
3634
|
-
sstEventListenerMap.
|
|
3660
|
+
const cacheList = sstEventListenerMap.get(type) || [];
|
|
3661
|
+
sstEventListenerMap.set(type, new Set([...cacheList, ...listenerList]));
|
|
3635
3662
|
}
|
|
3636
3663
|
});
|
|
3637
3664
|
};
|
|
@@ -3849,7 +3876,7 @@ function getNoHashMicroPathFromURL(appName, baseUrl) {
|
|
|
3849
3876
|
*/
|
|
3850
3877
|
function isEffectiveApp(appName) {
|
|
3851
3878
|
const app = appInstanceMap.get(appName);
|
|
3852
|
-
return !!(app && !app.isPrefetch);
|
|
3879
|
+
return !!(app && !app.isPrefetch && !app.isHidden());
|
|
3853
3880
|
}
|
|
3854
3881
|
|
|
3855
3882
|
/**
|
|
@@ -5551,7 +5578,8 @@ function patchWindowEffect$1(microAppWindow) {
|
|
|
5551
5578
|
// record window event
|
|
5552
5579
|
eventListenerMap.forEach((listenerList, type) => {
|
|
5553
5580
|
if (listenerList.size) {
|
|
5554
|
-
sstEventListenerMap.
|
|
5581
|
+
const cacheList = sstEventListenerMap.get(type) || [];
|
|
5582
|
+
sstEventListenerMap.set(type, new Set([...cacheList, ...listenerList]));
|
|
5555
5583
|
}
|
|
5556
5584
|
});
|
|
5557
5585
|
};
|
|
@@ -5839,19 +5867,23 @@ function patchDocumentEffect(appName, microAppWindow) {
|
|
|
5839
5867
|
* 3. after init prerender app
|
|
5840
5868
|
*/
|
|
5841
5869
|
const record = () => {
|
|
5842
|
-
|
|
5843
|
-
|
|
5870
|
+
/**
|
|
5871
|
+
* record onclick handler
|
|
5872
|
+
* onClickHandler maybe set again after prerender/keep-alive app hidden
|
|
5873
|
+
*/
|
|
5874
|
+
sstOnClickHandler = onClickHandler || sstOnClickHandler;
|
|
5844
5875
|
// record document event
|
|
5845
5876
|
eventListenerMap.forEach((listenerList, type) => {
|
|
5846
5877
|
if (listenerList.size) {
|
|
5847
|
-
sstEventListenerMap.
|
|
5878
|
+
const cacheList = sstEventListenerMap.get(type) || [];
|
|
5879
|
+
sstEventListenerMap.set(type, new Set([...cacheList, ...listenerList]));
|
|
5848
5880
|
}
|
|
5849
5881
|
});
|
|
5850
5882
|
};
|
|
5851
5883
|
// rebuild event and timer before remount app
|
|
5852
5884
|
const rebuild = () => {
|
|
5853
5885
|
// rebuild onclick event
|
|
5854
|
-
if (sstOnClickHandler)
|
|
5886
|
+
if (sstOnClickHandler && !onClickHandler)
|
|
5855
5887
|
microDocument.onclick = sstOnClickHandler;
|
|
5856
5888
|
sstEventListenerMap.forEach((listenerList, type) => {
|
|
5857
5889
|
for (const listener of listenerList) {
|
|
@@ -5864,8 +5896,8 @@ function patchDocumentEffect(appName, microAppWindow) {
|
|
|
5864
5896
|
// Clear the function bound by micro app through document.onclick
|
|
5865
5897
|
if (isFunction(onClickHandler)) {
|
|
5866
5898
|
rawRemoveEventListener.call(rawDocument, 'click', onClickHandler);
|
|
5867
|
-
onClickHandler = null;
|
|
5868
5899
|
}
|
|
5900
|
+
onClickHandler = null;
|
|
5869
5901
|
// Clear document binding event
|
|
5870
5902
|
if (eventListenerMap.size) {
|
|
5871
5903
|
eventListenerMap.forEach((listenerList, type) => {
|
|
@@ -6174,9 +6206,7 @@ class IframeSandbox {
|
|
|
6174
6206
|
if (this.active)
|
|
6175
6207
|
return;
|
|
6176
6208
|
this.active = true;
|
|
6177
|
-
|
|
6178
|
-
// eslint-disable-next-line
|
|
6179
|
-
if (useMemoryRouter || true) {
|
|
6209
|
+
if (useMemoryRouter) {
|
|
6180
6210
|
this.initRouteState(defaultPage);
|
|
6181
6211
|
// unique listener of popstate event for sub app
|
|
6182
6212
|
this.removeHistoryListener = addHistoryListener(this.microAppWindow.__MICRO_APP_NAME__);
|
|
@@ -6275,8 +6305,9 @@ class IframeSandbox {
|
|
|
6275
6305
|
* 2. unmount prerender app manually
|
|
6276
6306
|
*/
|
|
6277
6307
|
resetEffectSnapshot() {
|
|
6278
|
-
|
|
6279
|
-
this.
|
|
6308
|
+
var _a, _b;
|
|
6309
|
+
(_a = this.windowEffect) === null || _a === void 0 ? void 0 : _a.reset();
|
|
6310
|
+
(_b = this.documentEffect) === null || _b === void 0 ? void 0 : _b.reset();
|
|
6280
6311
|
resetDataCenterSnapshot(this.microAppWindow.microApp);
|
|
6281
6312
|
}
|
|
6282
6313
|
/**
|
|
@@ -6287,14 +6318,16 @@ class IframeSandbox {
|
|
|
6287
6318
|
* 3. after init prerender app
|
|
6288
6319
|
*/
|
|
6289
6320
|
recordEffectSnapshot() {
|
|
6290
|
-
|
|
6291
|
-
this.
|
|
6321
|
+
var _a, _b;
|
|
6322
|
+
(_a = this.windowEffect) === null || _a === void 0 ? void 0 : _a.record();
|
|
6323
|
+
(_b = this.documentEffect) === null || _b === void 0 ? void 0 : _b.record();
|
|
6292
6324
|
recordDataCenterSnapshot(this.microAppWindow.microApp);
|
|
6293
6325
|
}
|
|
6294
6326
|
// rebuild umd snapshot before remount umd app
|
|
6295
6327
|
rebuildEffectSnapshot() {
|
|
6296
|
-
|
|
6297
|
-
this.
|
|
6328
|
+
var _a, _b;
|
|
6329
|
+
(_a = this.windowEffect) === null || _a === void 0 ? void 0 : _a.rebuild();
|
|
6330
|
+
(_b = this.documentEffect) === null || _b === void 0 ? void 0 : _b.rebuild();
|
|
6298
6331
|
rebuildDataCenterSnapshot(this.microAppWindow.microApp);
|
|
6299
6332
|
}
|
|
6300
6333
|
/**
|
|
@@ -6308,14 +6341,14 @@ class IframeSandbox {
|
|
|
6308
6341
|
* @param keepAlive is keep-alive app
|
|
6309
6342
|
*/
|
|
6310
6343
|
releaseGlobalEffect({ clearData = false }) {
|
|
6311
|
-
var _a, _b, _c;
|
|
6312
|
-
this.windowEffect.release();
|
|
6313
|
-
this.documentEffect.release();
|
|
6314
|
-
(
|
|
6315
|
-
(
|
|
6344
|
+
var _a, _b, _c, _d, _e;
|
|
6345
|
+
(_a = this.windowEffect) === null || _a === void 0 ? void 0 : _a.release();
|
|
6346
|
+
(_b = this.documentEffect) === null || _b === void 0 ? void 0 : _b.release();
|
|
6347
|
+
(_c = this.microAppWindow.microApp) === null || _c === void 0 ? void 0 : _c.clearDataListener();
|
|
6348
|
+
(_d = this.microAppWindow.microApp) === null || _d === void 0 ? void 0 : _d.clearGlobalDataListener();
|
|
6316
6349
|
if (clearData) {
|
|
6317
6350
|
microApp.clearData(this.microAppWindow.__MICRO_APP_NAME__);
|
|
6318
|
-
(
|
|
6351
|
+
(_e = this.microAppWindow.microApp) === null || _e === void 0 ? void 0 : _e.clearData();
|
|
6319
6352
|
}
|
|
6320
6353
|
}
|
|
6321
6354
|
// set __MICRO_APP_PRE_RENDER__ state
|
|
@@ -6570,9 +6603,14 @@ class CreateApp {
|
|
|
6570
6603
|
var _a;
|
|
6571
6604
|
if (++this.loadSourceLevel === 2) {
|
|
6572
6605
|
this.source.html = html;
|
|
6573
|
-
this.
|
|
6574
|
-
if (!this.isPrefetch && appStates.UNMOUNT !== this.state) {
|
|
6606
|
+
if (!this.isPrefetch && !this.isUnmounted()) {
|
|
6575
6607
|
getRootContainer(this.container).mount(this);
|
|
6608
|
+
// Abandonment plan
|
|
6609
|
+
// if (this.isHidden()) {
|
|
6610
|
+
// getRootContainer(this.container!).unmount()
|
|
6611
|
+
// } else if (!this.isUnmounted()) {
|
|
6612
|
+
// getRootContainer(this.container!).mount(this)
|
|
6613
|
+
// }
|
|
6576
6614
|
}
|
|
6577
6615
|
else if (this.isPrerender) {
|
|
6578
6616
|
/**
|
|
@@ -6613,7 +6651,7 @@ class CreateApp {
|
|
|
6613
6651
|
*/
|
|
6614
6652
|
onLoadError(e) {
|
|
6615
6653
|
this.loadSourceLevel = -1;
|
|
6616
|
-
if (
|
|
6654
|
+
if (!this.isUnmounted()) {
|
|
6617
6655
|
this.onerror(e);
|
|
6618
6656
|
this.setAppState(appStates.LOAD_FAILED);
|
|
6619
6657
|
}
|
|
@@ -6667,7 +6705,7 @@ class CreateApp {
|
|
|
6667
6705
|
*/
|
|
6668
6706
|
(_a = this.sandBox) === null || _a === void 0 ? void 0 : _a.rebuildEffectSnapshot();
|
|
6669
6707
|
// current this.container is <div prerender='true'></div>
|
|
6670
|
-
cloneContainer(
|
|
6708
|
+
cloneContainer(container, this.container, false);
|
|
6671
6709
|
/**
|
|
6672
6710
|
* set this.container to <micro-app></micro-app>
|
|
6673
6711
|
* NOTE:
|
|
@@ -6698,7 +6736,7 @@ class CreateApp {
|
|
|
6698
6736
|
}
|
|
6699
6737
|
this.setAppState(appStates.MOUNTING);
|
|
6700
6738
|
// TODO: 将所有cloneContainer中的'as Element'去掉,兼容shadowRoot的场景
|
|
6701
|
-
cloneContainer(this.
|
|
6739
|
+
cloneContainer(this.container, this.source.html, !this.umdMode);
|
|
6702
6740
|
(_e = this.sandBox) === null || _e === void 0 ? void 0 : _e.start({
|
|
6703
6741
|
umdMode: this.umdMode,
|
|
6704
6742
|
baseroute,
|
|
@@ -6778,12 +6816,21 @@ class CreateApp {
|
|
|
6778
6816
|
* dispatch mounted event when app run finished
|
|
6779
6817
|
*/
|
|
6780
6818
|
dispatchMountedEvent() {
|
|
6781
|
-
|
|
6819
|
+
var _a;
|
|
6820
|
+
if (!this.isUnmounted()) {
|
|
6782
6821
|
this.setAppState(appStates.MOUNTED);
|
|
6783
6822
|
// call window.onmount of child app
|
|
6784
6823
|
execMicroAppGlobalHook(this.getMicroAppGlobalHook(microGlobalEvent.ONMOUNT), this.name, microGlobalEvent.ONMOUNT, microApp.getData(this.name, true));
|
|
6785
6824
|
// dispatch event mounted to parent
|
|
6786
6825
|
dispatchLifecyclesEvent(this.container, this.name, lifeCycles.MOUNTED);
|
|
6826
|
+
/**
|
|
6827
|
+
* Hidden Keep-alive app during resource loading, render normally to ensure their liveliness (running in the background) characteristics.
|
|
6828
|
+
* Actions:
|
|
6829
|
+
* 1. Record & release all global events after mount
|
|
6830
|
+
*/
|
|
6831
|
+
if (this.isHidden()) {
|
|
6832
|
+
(_a = this.sandBox) === null || _a === void 0 ? void 0 : _a.recordAndReleaseEffect({ keepAlive: true });
|
|
6833
|
+
}
|
|
6787
6834
|
}
|
|
6788
6835
|
}
|
|
6789
6836
|
/**
|
|
@@ -6853,7 +6900,7 @@ class CreateApp {
|
|
|
6853
6900
|
actionsForUnmount({ destroy, clearData, keepRouteState, unmountcb, }) {
|
|
6854
6901
|
var _a;
|
|
6855
6902
|
if (this.umdMode && this.container && !destroy) {
|
|
6856
|
-
cloneContainer(this.
|
|
6903
|
+
cloneContainer(this.source.html, this.container, false);
|
|
6857
6904
|
}
|
|
6858
6905
|
/**
|
|
6859
6906
|
* this.container maybe contains micro-app element, stop sandbox should exec after cloneContainer
|
|
@@ -6909,7 +6956,6 @@ class CreateApp {
|
|
|
6909
6956
|
// called after lifeCyclesEvent
|
|
6910
6957
|
(_a = this.sandBox) === null || _a === void 0 ? void 0 : _a.removeRouteInfoForKeepAliveApp();
|
|
6911
6958
|
}
|
|
6912
|
-
this.container = cloneContainer(this.container, pureCreateElement('div'), false);
|
|
6913
6959
|
(_b = this.sandBox) === null || _b === void 0 ? void 0 : _b.recordAndReleaseEffect({ keepAlive: true });
|
|
6914
6960
|
callback === null || callback === void 0 ? void 0 : callback();
|
|
6915
6961
|
}
|
|
@@ -6924,7 +6970,7 @@ class CreateApp {
|
|
|
6924
6970
|
// dispatch beforeShow event to base app
|
|
6925
6971
|
dispatchLifecyclesEvent(container, this.name, lifeCycles.BEFORESHOW);
|
|
6926
6972
|
this.setKeepAliveState(keepAliveStates.KEEP_ALIVE_SHOW);
|
|
6927
|
-
this.container = cloneContainer(
|
|
6973
|
+
this.container = cloneContainer(container, this.container, false);
|
|
6928
6974
|
if (this.useMemoryRouter) {
|
|
6929
6975
|
// called before lifeCyclesEvent
|
|
6930
6976
|
(_b = this.sandBox) === null || _b === void 0 ? void 0 : _b.setRouteInfoForKeepAliveApp();
|
|
@@ -6975,10 +7021,18 @@ class CreateApp {
|
|
|
6975
7021
|
getKeepAliveState() {
|
|
6976
7022
|
return this.keepAliveState;
|
|
6977
7023
|
}
|
|
7024
|
+
// is app unmounted
|
|
7025
|
+
isUnmounted() {
|
|
7026
|
+
return appStates.UNMOUNT === this.state;
|
|
7027
|
+
}
|
|
7028
|
+
// is app already hidden
|
|
7029
|
+
isHidden() {
|
|
7030
|
+
return keepAliveStates.KEEP_ALIVE_HIDDEN === this.keepAliveState;
|
|
7031
|
+
}
|
|
6978
7032
|
// get umd library, if it not exist, return empty object
|
|
6979
7033
|
getUmdLibraryHooks() {
|
|
6980
7034
|
// after execScripts, the app maybe unmounted
|
|
6981
|
-
if (
|
|
7035
|
+
if (!this.isUnmounted() && this.sandBox) {
|
|
6982
7036
|
const libraryName = getRootContainer(this.container).getAttribute('library') || `micro-app-${this.name}`;
|
|
6983
7037
|
const proxyWindow = this.sandBox.proxyWindow;
|
|
6984
7038
|
// compatible with pre versions
|
|
@@ -7041,16 +7095,14 @@ function defineElement(tagName) {
|
|
|
7041
7095
|
* If oldApp exist & appName is different, determine whether oldApp is running
|
|
7042
7096
|
*/
|
|
7043
7097
|
if (formatAttrName !== this.appName && oldApp) {
|
|
7044
|
-
if (oldApp.
|
|
7045
|
-
oldApp.getKeepAliveState() !== keepAliveStates.KEEP_ALIVE_HIDDEN &&
|
|
7046
|
-
!oldApp.isPrefetch) {
|
|
7098
|
+
if (!oldApp.isUnmounted() && !oldApp.isHidden() && !oldApp.isPrefetch) {
|
|
7047
7099
|
this.setAttribute('name', this.appName);
|
|
7048
7100
|
return logError(`app name conflict, an app named ${formatAttrName} is running`);
|
|
7049
7101
|
}
|
|
7050
7102
|
}
|
|
7051
7103
|
if (formatAttrName !== this.appName || formatAttrUrl !== this.appUrl) {
|
|
7052
7104
|
if (formatAttrName === this.appName) {
|
|
7053
|
-
this.
|
|
7105
|
+
this.unmount(true, () => {
|
|
7054
7106
|
this.actionsForAttributeChange(formatAttrName, formatAttrUrl, oldApp);
|
|
7055
7107
|
});
|
|
7056
7108
|
}
|
|
@@ -7059,7 +7111,7 @@ function defineElement(tagName) {
|
|
|
7059
7111
|
this.actionsForAttributeChange(formatAttrName, formatAttrUrl, oldApp);
|
|
7060
7112
|
}
|
|
7061
7113
|
else {
|
|
7062
|
-
this.
|
|
7114
|
+
this.unmount(false, () => {
|
|
7063
7115
|
this.actionsForAttributeChange(formatAttrName, formatAttrUrl, oldApp);
|
|
7064
7116
|
});
|
|
7065
7117
|
}
|
|
@@ -7131,15 +7183,13 @@ function defineElement(tagName) {
|
|
|
7131
7183
|
*/
|
|
7132
7184
|
handleDisconnected(destroy = false, callback) {
|
|
7133
7185
|
const app = appInstanceMap.get(this.appName);
|
|
7134
|
-
if (app &&
|
|
7135
|
-
app.getAppState() !== appStates.UNMOUNT &&
|
|
7136
|
-
app.getKeepAliveState() !== keepAliveStates.KEEP_ALIVE_HIDDEN) {
|
|
7186
|
+
if (app && !app.isUnmounted() && !app.isHidden()) {
|
|
7137
7187
|
// keep-alive
|
|
7138
7188
|
if (this.getKeepAliveModeResult() && !destroy) {
|
|
7139
7189
|
this.handleHiddenKeepAliveApp(callback);
|
|
7140
7190
|
}
|
|
7141
7191
|
else {
|
|
7142
|
-
this.
|
|
7192
|
+
this.unmount(destroy, callback);
|
|
7143
7193
|
}
|
|
7144
7194
|
}
|
|
7145
7195
|
}
|
|
@@ -7199,16 +7249,16 @@ function defineElement(tagName) {
|
|
|
7199
7249
|
* 2. Even if the keep-alive app is pushed into the background, it is still active and cannot be replaced. Otherwise, it is difficult for developers to troubleshoot in case of conflict and will leave developers at a loss
|
|
7200
7250
|
* 3. When scopecss, useSandbox of prefetch app different from target app, delete prefetch app and create new one
|
|
7201
7251
|
*/
|
|
7202
|
-
if (oldApp.
|
|
7252
|
+
if (oldApp.isHidden() &&
|
|
7203
7253
|
oldApp.url === this.appUrl) {
|
|
7204
7254
|
this.handleShowKeepAliveApp(oldApp);
|
|
7205
7255
|
}
|
|
7206
|
-
else if (oldAppUrl === targetUrl && (oldApp.
|
|
7256
|
+
else if (oldAppUrl === targetUrl && (oldApp.isUnmounted() ||
|
|
7207
7257
|
(oldApp.isPrefetch &&
|
|
7208
7258
|
this.sameCoreOptions(oldApp)))) {
|
|
7209
|
-
this.
|
|
7259
|
+
this.handleMount(oldApp);
|
|
7210
7260
|
}
|
|
7211
|
-
else if (oldApp.isPrefetch || oldApp.
|
|
7261
|
+
else if (oldApp.isPrefetch || oldApp.isUnmounted()) {
|
|
7212
7262
|
if ((process.env.NODE_ENV !== 'production') && this.sameCoreOptions(oldApp)) {
|
|
7213
7263
|
/**
|
|
7214
7264
|
* url is different & old app is unmounted or prefetch, create new app to replace old one
|
|
@@ -7247,7 +7297,7 @@ function defineElement(tagName) {
|
|
|
7247
7297
|
* scene5: if oldApp is KEEP_ALIVE_HIDDEN, name must different
|
|
7248
7298
|
*/
|
|
7249
7299
|
if (oldApp) {
|
|
7250
|
-
if (oldApp.
|
|
7300
|
+
if (oldApp.isHidden()) {
|
|
7251
7301
|
if (oldApp.url === this.appUrl) {
|
|
7252
7302
|
this.handleShowKeepAliveApp(oldApp);
|
|
7253
7303
|
}
|
|
@@ -7262,7 +7312,7 @@ function defineElement(tagName) {
|
|
|
7262
7312
|
* 推荐:if (
|
|
7263
7313
|
* oldApp.url === this.appUrl &&
|
|
7264
7314
|
* oldApp.ssrUrl === this.ssrUrl && (
|
|
7265
|
-
* oldApp.
|
|
7315
|
+
* oldApp.isUnmounted() ||
|
|
7266
7316
|
* (oldApp.isPrefetch && this.sameCoreOptions(oldApp))
|
|
7267
7317
|
* )
|
|
7268
7318
|
* )
|
|
@@ -7270,7 +7320,7 @@ function defineElement(tagName) {
|
|
|
7270
7320
|
}
|
|
7271
7321
|
else if (oldApp.url === this.appUrl && oldApp.ssrUrl === this.ssrUrl) {
|
|
7272
7322
|
// mount app
|
|
7273
|
-
this.
|
|
7323
|
+
this.handleMount(oldApp);
|
|
7274
7324
|
}
|
|
7275
7325
|
else {
|
|
7276
7326
|
this.handleCreateApp();
|
|
@@ -7317,7 +7367,7 @@ function defineElement(tagName) {
|
|
|
7317
7367
|
const oldApp = appInstanceMap.get(this.appName);
|
|
7318
7368
|
if (oldApp) {
|
|
7319
7369
|
if (oldApp.isPrerender) {
|
|
7320
|
-
this.
|
|
7370
|
+
this.unmount(true, createAppInstance);
|
|
7321
7371
|
}
|
|
7322
7372
|
else {
|
|
7323
7373
|
oldApp.actionsForCompletelyDestroy();
|
|
@@ -7335,7 +7385,7 @@ function defineElement(tagName) {
|
|
|
7335
7385
|
* 2. is remount in another container ?
|
|
7336
7386
|
* 3. is remount with change properties of the container ?
|
|
7337
7387
|
*/
|
|
7338
|
-
|
|
7388
|
+
handleMount(app) {
|
|
7339
7389
|
app.isPrefetch = false;
|
|
7340
7390
|
// TODO: Can defer be removed?
|
|
7341
7391
|
defer(() => this.mount(app));
|
|
@@ -7358,13 +7408,13 @@ function defineElement(tagName) {
|
|
|
7358
7408
|
/**
|
|
7359
7409
|
* unmount app
|
|
7360
7410
|
* @param destroy delete cache resources when unmount
|
|
7411
|
+
* @param unmountcb callback
|
|
7361
7412
|
*/
|
|
7362
|
-
|
|
7413
|
+
unmount(destroy, unmountcb) {
|
|
7363
7414
|
const app = appInstanceMap.get(this.appName);
|
|
7364
|
-
if (app &&
|
|
7365
|
-
app.getAppState() !== appStates.UNMOUNT) {
|
|
7415
|
+
if (app && !app.isUnmounted()) {
|
|
7366
7416
|
app.unmount({
|
|
7367
|
-
destroy,
|
|
7417
|
+
destroy: destroy || this.getDestroyCompatibleResult(),
|
|
7368
7418
|
clearData: this.getDisposeResult('clear-data'),
|
|
7369
7419
|
keepRouteState: this.getDisposeResult('keep-router-state'),
|
|
7370
7420
|
unmountcb,
|
|
@@ -7374,9 +7424,7 @@ function defineElement(tagName) {
|
|
|
7374
7424
|
// hidden app when disconnectedCallback called with keep-alive
|
|
7375
7425
|
handleHiddenKeepAliveApp(callback) {
|
|
7376
7426
|
const app = appInstanceMap.get(this.appName);
|
|
7377
|
-
if (app &&
|
|
7378
|
-
app.getAppState() !== appStates.UNMOUNT &&
|
|
7379
|
-
app.getKeepAliveState() !== keepAliveStates.KEEP_ALIVE_HIDDEN) {
|
|
7427
|
+
if (app && !app.isUnmounted() && !app.isHidden()) {
|
|
7380
7428
|
app.hiddenKeepAliveApp(callback);
|
|
7381
7429
|
}
|
|
7382
7430
|
}
|
|
@@ -7674,10 +7722,10 @@ function fetchGlobalResources(resources, suffix, sourceHandler) {
|
|
|
7674
7722
|
function getActiveApps({ excludeHiddenApp = false, excludePreRender = false, } = {}) {
|
|
7675
7723
|
const activeApps = [];
|
|
7676
7724
|
appInstanceMap.forEach((app, appName) => {
|
|
7677
|
-
if (
|
|
7725
|
+
if (!app.isUnmounted() &&
|
|
7678
7726
|
(!app.isPrefetch || (app.isPrerender && !excludePreRender)) &&
|
|
7679
7727
|
(!excludeHiddenApp ||
|
|
7680
|
-
|
|
7728
|
+
!app.isHidden())) {
|
|
7681
7729
|
activeApps.push(appName);
|
|
7682
7730
|
}
|
|
7683
7731
|
});
|
|
@@ -7697,7 +7745,7 @@ function unmountApp(appName, options) {
|
|
|
7697
7745
|
const app = appInstanceMap.get(formatAppName(appName));
|
|
7698
7746
|
return new Promise((resolve) => {
|
|
7699
7747
|
if (app) {
|
|
7700
|
-
if (app.
|
|
7748
|
+
if (app.isUnmounted() || app.isPrefetch) {
|
|
7701
7749
|
if (app.isPrerender) {
|
|
7702
7750
|
app.unmount({
|
|
7703
7751
|
destroy: !!(options === null || options === void 0 ? void 0 : options.destroy),
|
|
@@ -7712,7 +7760,7 @@ function unmountApp(appName, options) {
|
|
|
7712
7760
|
resolve(true);
|
|
7713
7761
|
}
|
|
7714
7762
|
}
|
|
7715
|
-
else if (app.
|
|
7763
|
+
else if (app.isHidden()) {
|
|
7716
7764
|
if (options === null || options === void 0 ? void 0 : options.destroy) {
|
|
7717
7765
|
app.unmount({
|
|
7718
7766
|
destroy: true,
|