@qiankunjs/single-spa 0.0.1-rc.0
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/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/cjs/applications/app-errors.d.ts +11 -0
- package/dist/cjs/applications/app-errors.js +57 -0
- package/dist/cjs/applications/app-errors.js.map +1 -0
- package/dist/cjs/applications/app.helpers.d.ts +52 -0
- package/dist/cjs/applications/app.helpers.js +47 -0
- package/dist/cjs/applications/app.helpers.js.map +1 -0
- package/dist/cjs/applications/apps.d.ts +23 -0
- package/dist/cjs/applications/apps.js +234 -0
- package/dist/cjs/applications/apps.js.map +1 -0
- package/dist/cjs/applications/timeouts.d.ts +19 -0
- package/dist/cjs/applications/timeouts.js +115 -0
- package/dist/cjs/applications/timeouts.js.map +1 -0
- package/dist/cjs/declarations.d.ts +4 -0
- package/dist/cjs/devtools/devtools.d.ts +16 -0
- package/dist/cjs/devtools/devtools.js +24 -0
- package/dist/cjs/devtools/devtools.js.map +1 -0
- package/dist/cjs/devtools/profiler.d.ts +11 -0
- package/dist/cjs/devtools/profiler.js +25 -0
- package/dist/cjs/devtools/profiler.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/jquery-support.d.ts +7 -0
- package/dist/cjs/jquery-support.js +34 -0
- package/dist/cjs/jquery-support.js.map +1 -0
- package/dist/cjs/lifecycles/bootstrap.d.ts +2 -0
- package/dist/cjs/lifecycles/bootstrap.js +27 -0
- package/dist/cjs/lifecycles/bootstrap.js.map +1 -0
- package/dist/cjs/lifecycles/lifecycle.helpers.d.ts +90 -0
- package/dist/cjs/lifecycles/lifecycle.helpers.js +33 -0
- package/dist/cjs/lifecycles/lifecycle.helpers.js.map +1 -0
- package/dist/cjs/lifecycles/load.d.ts +3 -0
- package/dist/cjs/lifecycles/load.js +73 -0
- package/dist/cjs/lifecycles/load.js.map +1 -0
- package/dist/cjs/lifecycles/mount.d.ts +2 -0
- package/dist/cjs/lifecycles/mount.js +40 -0
- package/dist/cjs/lifecycles/mount.js.map +1 -0
- package/dist/cjs/lifecycles/prop.helpers.d.ts +9 -0
- package/dist/cjs/lifecycles/prop.helpers.js +23 -0
- package/dist/cjs/lifecycles/prop.helpers.js.map +1 -0
- package/dist/cjs/lifecycles/unload.d.ts +12 -0
- package/dist/cjs/lifecycles/unload.js +63 -0
- package/dist/cjs/lifecycles/unload.js.map +1 -0
- package/dist/cjs/lifecycles/unmount.d.ts +2 -0
- package/dist/cjs/lifecycles/unmount.js +32 -0
- package/dist/cjs/lifecycles/unmount.js.map +1 -0
- package/dist/cjs/lifecycles/update.d.ts +2 -0
- package/dist/cjs/lifecycles/update.js +22 -0
- package/dist/cjs/lifecycles/update.js.map +1 -0
- package/dist/cjs/navigation/navigation-events.d.ts +8 -0
- package/dist/cjs/navigation/navigation-events.js +102 -0
- package/dist/cjs/navigation/navigation-events.js.map +1 -0
- package/dist/cjs/navigation/reroute.d.ts +9 -0
- package/dist/cjs/navigation/reroute.js +182 -0
- package/dist/cjs/navigation/reroute.js.map +1 -0
- package/dist/cjs/parcels/mount-parcel.d.ts +3 -0
- package/dist/cjs/parcels/mount-parcel.js +122 -0
- package/dist/cjs/parcels/mount-parcel.js.map +1 -0
- package/dist/cjs/single-spa.d.ts +19 -0
- package/dist/cjs/single-spa.js +39 -0
- package/dist/cjs/single-spa.js.map +1 -0
- package/dist/cjs/start.d.ts +5 -0
- package/dist/cjs/start.js +21 -0
- package/dist/cjs/start.js.map +1 -0
- package/dist/cjs/utils/runtime-environment.d.ts +1 -0
- package/dist/cjs/utils/runtime-environment.js +7 -0
- package/dist/cjs/utils/runtime-environment.js.map +1 -0
- package/dist/cjs/window-globals.d.ts +8 -0
- package/dist/esm/applications/app-errors.d.ts +11 -0
- package/dist/esm/applications/app-errors.js +52 -0
- package/dist/esm/applications/app-errors.js.map +1 -0
- package/dist/esm/applications/app.helpers.d.ts +52 -0
- package/dist/esm/applications/app.helpers.js +41 -0
- package/dist/esm/applications/app.helpers.js.map +1 -0
- package/dist/esm/applications/apps.d.ts +23 -0
- package/dist/esm/applications/apps.js +223 -0
- package/dist/esm/applications/apps.js.map +1 -0
- package/dist/esm/applications/timeouts.d.ts +19 -0
- package/dist/esm/applications/timeouts.js +109 -0
- package/dist/esm/applications/timeouts.js.map +1 -0
- package/dist/esm/declarations.d.ts +4 -0
- package/dist/esm/devtools/devtools.d.ts +16 -0
- package/dist/esm/devtools/devtools.js +20 -0
- package/dist/esm/devtools/devtools.js.map +1 -0
- package/dist/esm/devtools/profiler.d.ts +11 -0
- package/dist/esm/devtools/profiler.js +22 -0
- package/dist/esm/devtools/profiler.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/jquery-support.d.ts +7 -0
- package/dist/esm/jquery-support.js +33 -0
- package/dist/esm/jquery-support.js.map +1 -0
- package/dist/esm/lifecycles/bootstrap.d.ts +2 -0
- package/dist/esm/lifecycles/bootstrap.js +26 -0
- package/dist/esm/lifecycles/bootstrap.js.map +1 -0
- package/dist/esm/lifecycles/lifecycle.helpers.d.ts +90 -0
- package/dist/esm/lifecycles/lifecycle.helpers.js +30 -0
- package/dist/esm/lifecycles/lifecycle.helpers.js.map +1 -0
- package/dist/esm/lifecycles/load.d.ts +3 -0
- package/dist/esm/lifecycles/load.js +72 -0
- package/dist/esm/lifecycles/load.js.map +1 -0
- package/dist/esm/lifecycles/mount.d.ts +2 -0
- package/dist/esm/lifecycles/mount.js +39 -0
- package/dist/esm/lifecycles/mount.js.map +1 -0
- package/dist/esm/lifecycles/prop.helpers.d.ts +9 -0
- package/dist/esm/lifecycles/prop.helpers.js +22 -0
- package/dist/esm/lifecycles/prop.helpers.js.map +1 -0
- package/dist/esm/lifecycles/unload.d.ts +12 -0
- package/dist/esm/lifecycles/unload.js +60 -0
- package/dist/esm/lifecycles/unload.js.map +1 -0
- package/dist/esm/lifecycles/unmount.d.ts +2 -0
- package/dist/esm/lifecycles/unmount.js +31 -0
- package/dist/esm/lifecycles/unmount.js.map +1 -0
- package/dist/esm/lifecycles/update.d.ts +2 -0
- package/dist/esm/lifecycles/update.js +21 -0
- package/dist/esm/lifecycles/update.js.map +1 -0
- package/dist/esm/navigation/navigation-events.d.ts +8 -0
- package/dist/esm/navigation/navigation-events.js +92 -0
- package/dist/esm/navigation/navigation-events.js.map +1 -0
- package/dist/esm/navigation/reroute.d.ts +9 -0
- package/dist/esm/navigation/reroute.js +180 -0
- package/dist/esm/navigation/reroute.js.map +1 -0
- package/dist/esm/parcels/mount-parcel.d.ts +3 -0
- package/dist/esm/parcels/mount-parcel.js +120 -0
- package/dist/esm/parcels/mount-parcel.js.map +1 -0
- package/dist/esm/single-spa.d.ts +19 -0
- package/dist/esm/single-spa.js +17 -0
- package/dist/esm/single-spa.js.map +1 -0
- package/dist/esm/start.d.ts +5 -0
- package/dist/esm/start.js +19 -0
- package/dist/esm/start.js.map +1 -0
- package/dist/esm/utils/runtime-environment.d.ts +1 -0
- package/dist/esm/utils/runtime-environment.js +6 -0
- package/dist/esm/utils/runtime-environment.js.map +1 -0
- package/dist/esm/window-globals.d.ts +8 -0
- package/package.json +25 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_applications_app_helpers = require("../applications/app.helpers.js");
|
|
3
|
+
const require_applications_app_errors = require("../applications/app-errors.js");
|
|
4
|
+
require("../devtools/profiler.js");
|
|
5
|
+
const require_lifecycles_unmount = require("./unmount.js");
|
|
6
|
+
const require_applications_timeouts = require("../applications/timeouts.js");
|
|
7
|
+
//#region src/lifecycles/mount.ts
|
|
8
|
+
var beforeFirstMountFired = false;
|
|
9
|
+
var firstMountFired = false;
|
|
10
|
+
function toMountPromise(appOrParcel, hardFail) {
|
|
11
|
+
return Promise.resolve().then(() => {
|
|
12
|
+
if (appOrParcel.status !== require_applications_app_helpers.AppOrParcelStatus.NOT_MOUNTED) return appOrParcel;
|
|
13
|
+
if (!beforeFirstMountFired) {
|
|
14
|
+
window.dispatchEvent(new CustomEvent("single-spa:before-first-mount"));
|
|
15
|
+
beforeFirstMountFired = true;
|
|
16
|
+
}
|
|
17
|
+
appOrParcel.status = require_applications_app_helpers.AppOrParcelStatus.MOUNTING;
|
|
18
|
+
return require_applications_timeouts.reasonableTime(appOrParcel, "mount").then(() => {
|
|
19
|
+
appOrParcel.status = require_applications_app_helpers.AppOrParcelStatus.MOUNTED;
|
|
20
|
+
if (!firstMountFired) {
|
|
21
|
+
window.dispatchEvent(new CustomEvent("single-spa:first-mount"));
|
|
22
|
+
firstMountFired = true;
|
|
23
|
+
}
|
|
24
|
+
return appOrParcel;
|
|
25
|
+
}).catch((err) => {
|
|
26
|
+
appOrParcel.status = require_applications_app_helpers.AppOrParcelStatus.MOUNTED;
|
|
27
|
+
return require_lifecycles_unmount.toUnmountPromise(appOrParcel, true).then(setSkipBecauseBroken, setSkipBecauseBroken);
|
|
28
|
+
function setSkipBecauseBroken() {
|
|
29
|
+
if (!hardFail) {
|
|
30
|
+
require_applications_app_errors.handleAppError(err, appOrParcel, require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN);
|
|
31
|
+
return appOrParcel;
|
|
32
|
+
} else throw require_applications_app_errors.transformErr(err, appOrParcel, require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.toMountPromise = toMountPromise;
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=mount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount.js","names":[],"sources":["../../../src/lifecycles/mount.ts"],"sourcesContent":["import { toName, isParcel, AppOrParcelStatus } from '../applications/app.helpers';\nimport { handleAppError, transformErr } from '../applications/app-errors';\nimport { reasonableTime } from '../applications/timeouts';\nimport { toUnmountPromise } from './unmount';\nimport { ProfileEntry, addProfileEntry } from '../devtools/profiler';\nimport { LoadedAppOrParcel } from './lifecycle.helpers';\n\nlet beforeFirstMountFired: boolean = false;\nlet firstMountFired: boolean = false;\n\nexport function toMountPromise(appOrParcel: LoadedAppOrParcel, hardFail?: boolean): Promise<LoadedAppOrParcel> {\n return Promise.resolve().then(() => {\n if (appOrParcel.status !== AppOrParcelStatus.NOT_MOUNTED) {\n return appOrParcel;\n }\n\n let startTime: number, profileEventType: ProfileEntry['type'];\n\n if (__PROFILE__) {\n profileEventType = isParcel(appOrParcel) ? 'parcel' : 'application';\n startTime = performance.now();\n }\n\n if (!beforeFirstMountFired) {\n window.dispatchEvent(new CustomEvent('single-spa:before-first-mount'));\n beforeFirstMountFired = true;\n }\n\n appOrParcel.status = AppOrParcelStatus.MOUNTING;\n\n return reasonableTime(appOrParcel, 'mount')\n .then(() => {\n appOrParcel.status = AppOrParcelStatus.MOUNTED;\n\n if (!firstMountFired) {\n window.dispatchEvent(new CustomEvent('single-spa:first-mount'));\n firstMountFired = true;\n }\n\n if (__PROFILE__) {\n addProfileEntry(profileEventType, toName(appOrParcel), 'mount', startTime, performance.now(), true);\n }\n\n return appOrParcel;\n })\n .catch((err) => {\n // If we fail to mount the appOrParcel, we should attempt to unmount it before putting in SKIP_BECAUSE_BROKEN\n // We temporarily put the appOrParcel into MOUNTED status so that toUnmountPromise actually attempts to unmount it\n // instead of just doing a no-op.\n appOrParcel.status = AppOrParcelStatus.MOUNTED;\n return toUnmountPromise(appOrParcel, true).then(setSkipBecauseBroken, setSkipBecauseBroken);\n\n function setSkipBecauseBroken() {\n if (__PROFILE__) {\n addProfileEntry(profileEventType, toName(appOrParcel), 'mount', startTime, performance.now(), false);\n }\n\n if (!hardFail) {\n handleAppError(err, appOrParcel, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n return appOrParcel;\n } else {\n throw transformErr(err, appOrParcel, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n }\n }\n });\n });\n}\n"],"mappings":";;;;;;;AAOA,IAAI,wBAAiC;AACrC,IAAI,kBAA2B;AAE/B,SAAgB,eAAe,aAAgC,UAAgD;CAC7G,OAAO,QAAQ,QAAQ,CAAC,CAAC,WAAW;EAClC,IAAI,YAAY,WAAW,iCAAA,kBAAkB,aAC3C,OAAO;EAUT,IAAI,CAAC,uBAAuB;GAC1B,OAAO,cAAc,IAAI,YAAY,+BAA+B,CAAC;GACrE,wBAAwB;EAC1B;EAEA,YAAY,SAAS,iCAAA,kBAAkB;EAEvC,OAAO,8BAAA,eAAe,aAAa,OAAO,CAAC,CACxC,WAAW;GACV,YAAY,SAAS,iCAAA,kBAAkB;GAEvC,IAAI,CAAC,iBAAiB;IACpB,OAAO,cAAc,IAAI,YAAY,wBAAwB,CAAC;IAC9D,kBAAkB;GACpB;GAMA,OAAO;EACT,CAAC,CAAC,CACD,OAAO,QAAQ;GAId,YAAY,SAAS,iCAAA,kBAAkB;GACvC,OAAO,2BAAA,iBAAiB,aAAa,IAAI,CAAC,CAAC,KAAK,sBAAsB,oBAAoB;GAE1F,SAAS,uBAAuB;IAK9B,IAAI,CAAC,UAAU;KACb,gCAAA,eAAe,KAAK,aAAa,iCAAA,kBAAkB,mBAAmB;KACtE,OAAO;IACT,OACE,MAAM,gCAAA,aAAa,KAAK,aAAa,iCAAA,kBAAkB,mBAAmB;GAE9E;EACF,CAAC;CACL,CAAC;AACH"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { mountParcel } from '../parcels/mount-parcel';
|
|
2
|
+
import { AppOrParcel, CustomProps } from './lifecycle.helpers';
|
|
3
|
+
interface SingleSpaProps {
|
|
4
|
+
name: string;
|
|
5
|
+
mountParcel: typeof mountParcel;
|
|
6
|
+
unmountSelf(): Promise<AppOrParcel>;
|
|
7
|
+
}
|
|
8
|
+
export declare function getProps(appOrParcel: AppOrParcel): SingleSpaProps & CustomProps;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_applications_app_helpers = require("../applications/app.helpers.js");
|
|
3
|
+
const require_applications_app_errors = require("../applications/app-errors.js");
|
|
4
|
+
const require_parcels_mount_parcel = require("../parcels/mount-parcel.js");
|
|
5
|
+
//#region src/lifecycles/prop.helpers.ts
|
|
6
|
+
function getProps(appOrParcel) {
|
|
7
|
+
const name = require_applications_app_helpers.toName(appOrParcel);
|
|
8
|
+
let customProps = typeof appOrParcel.customProps === "function" ? appOrParcel.customProps(name, window.location) : appOrParcel.customProps;
|
|
9
|
+
if (typeof customProps !== "object" || customProps === null || Array.isArray(customProps)) {
|
|
10
|
+
customProps = {};
|
|
11
|
+
console.warn(require_applications_app_errors.formatErrorMessage(40, process.env.NODE_ENV !== "production" && `single-spa: ${name}'s customProps function must return an object. Received ${customProps}`), name, customProps);
|
|
12
|
+
}
|
|
13
|
+
const result = Object.assign({}, customProps, {
|
|
14
|
+
name,
|
|
15
|
+
mountParcel: require_parcels_mount_parcel.mountParcel.bind(appOrParcel)
|
|
16
|
+
});
|
|
17
|
+
if (require_applications_app_helpers.isParcel(appOrParcel)) result.unmountSelf = appOrParcel.unmountThisParcel;
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.getProps = getProps;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=prop.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prop.helpers.js","names":[],"sources":["../../../src/lifecycles/prop.helpers.ts"],"sourcesContent":["import { mountParcel } from '../parcels/mount-parcel';\nimport { isParcel, toName } from '../applications/app.helpers';\nimport { formatErrorMessage } from '../applications/app-errors';\nimport { AppOrParcel, CustomProps, InternalParcel } from './lifecycle.helpers';\n\ninterface SingleSpaProps {\n name: string;\n mountParcel: typeof mountParcel;\n unmountSelf(): Promise<AppOrParcel>;\n}\n\nexport function getProps(appOrParcel: AppOrParcel): SingleSpaProps & CustomProps {\n const name = toName(appOrParcel);\n let customProps =\n typeof appOrParcel.customProps === 'function'\n ? appOrParcel.customProps(name, window.location)\n : appOrParcel.customProps;\n if (typeof customProps !== 'object' || customProps === null || Array.isArray(customProps)) {\n customProps = {};\n console.warn(\n formatErrorMessage(\n 40,\n __DEV__ && `single-spa: ${name}'s customProps function must return an object. Received ${customProps}`,\n ),\n name,\n customProps,\n );\n }\n const result: SingleSpaProps = Object.assign({}, customProps, {\n name,\n mountParcel: mountParcel.bind(appOrParcel),\n });\n\n if (isParcel(appOrParcel)) {\n result.unmountSelf = appOrParcel.unmountThisParcel;\n }\n\n return result;\n}\n"],"mappings":";;;;;AAWA,SAAgB,SAAS,aAAwD;CAC/E,MAAM,OAAO,iCAAA,OAAO,WAAW;CAC/B,IAAI,cACF,OAAO,YAAY,gBAAgB,aAC/B,YAAY,YAAY,MAAM,OAAO,QAAQ,IAC7C,YAAY;CAClB,IAAI,OAAO,gBAAgB,YAAY,gBAAgB,QAAQ,MAAM,QAAQ,WAAW,GAAG;EACzF,cAAc,CAAC;EACf,QAAQ,KACN,gCAAA,mBACE,IAAA,QAAA,IAAA,aAAA,gBACW,eAAe,KAAK,0DAA0D,aAC3F,GACA,MACA,WACF;CACF;CACA,MAAM,SAAyB,OAAO,OAAO,CAAC,GAAG,aAAa;EAC5D;EACA,aAAa,6BAAA,YAAY,KAAK,WAAW;CAC3C,CAAC;CAED,IAAI,iCAAA,SAAS,WAAW,GACtB,OAAO,cAAc,YAAY;CAGnC,OAAO;AACT"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InternalApplication } from '../applications/app.helpers';
|
|
2
|
+
import { LoadedApp } from './lifecycle.helpers';
|
|
3
|
+
interface UnloadInfo {
|
|
4
|
+
app: InternalApplication;
|
|
5
|
+
promise?: Promise<any>;
|
|
6
|
+
resolve: (val?: any) => void;
|
|
7
|
+
reject: (val?: any) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function toUnloadPromise(app: LoadedApp): Promise<LoadedApp>;
|
|
10
|
+
export declare function addAppToUnload(app: InternalApplication, promiseGetter: () => Promise<any>, resolve: (val?: any) => any, reject: (val?: any) => any): void;
|
|
11
|
+
export declare function getAppUnloadInfo(appName: string): UnloadInfo;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_applications_app_helpers = require("../applications/app.helpers.js");
|
|
3
|
+
const require_applications_app_errors = require("../applications/app-errors.js");
|
|
4
|
+
require("../devtools/profiler.js");
|
|
5
|
+
const require_applications_timeouts = require("../applications/timeouts.js");
|
|
6
|
+
//#region src/lifecycles/unload.ts
|
|
7
|
+
var appsToUnload = {};
|
|
8
|
+
function toUnloadPromise(app) {
|
|
9
|
+
return Promise.resolve().then(() => {
|
|
10
|
+
const unloadInfo = appsToUnload[require_applications_app_helpers.toName(app)];
|
|
11
|
+
if (!unloadInfo) return app;
|
|
12
|
+
if (app.status === require_applications_app_helpers.AppOrParcelStatus.NOT_LOADED) {
|
|
13
|
+
finishUnloadingApp(app, unloadInfo);
|
|
14
|
+
return app;
|
|
15
|
+
}
|
|
16
|
+
if (app.status === require_applications_app_helpers.AppOrParcelStatus.UNLOADING) return unloadInfo.promise.then(() => app);
|
|
17
|
+
if (app.status !== require_applications_app_helpers.AppOrParcelStatus.NOT_MOUNTED && app.status !== require_applications_app_helpers.AppOrParcelStatus.LOAD_ERROR && app.status !== require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN) return app;
|
|
18
|
+
const unloadPromise = app.unload ? require_applications_timeouts.reasonableTime(app, "unload") : Promise.resolve();
|
|
19
|
+
app.status = require_applications_app_helpers.AppOrParcelStatus.UNLOADING;
|
|
20
|
+
return unloadPromise.then(() => {
|
|
21
|
+
finishUnloadingApp(app, unloadInfo);
|
|
22
|
+
return app;
|
|
23
|
+
}).catch((err) => {
|
|
24
|
+
errorUnloadingApp(app, unloadInfo, err);
|
|
25
|
+
return app;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function finishUnloadingApp(app, unloadInfo) {
|
|
30
|
+
delete appsToUnload[require_applications_app_helpers.toName(app)];
|
|
31
|
+
delete app.bootstrap;
|
|
32
|
+
delete app.mount;
|
|
33
|
+
delete app.unmount;
|
|
34
|
+
delete app.unload;
|
|
35
|
+
app.status = require_applications_app_helpers.AppOrParcelStatus.NOT_LOADED;
|
|
36
|
+
unloadInfo.resolve();
|
|
37
|
+
}
|
|
38
|
+
function errorUnloadingApp(app, unloadInfo, err) {
|
|
39
|
+
delete appsToUnload[require_applications_app_helpers.toName(app)];
|
|
40
|
+
delete app.bootstrap;
|
|
41
|
+
delete app.mount;
|
|
42
|
+
delete app.unmount;
|
|
43
|
+
delete app.unload;
|
|
44
|
+
require_applications_app_errors.handleAppError(err, app, require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN);
|
|
45
|
+
unloadInfo.reject(err);
|
|
46
|
+
}
|
|
47
|
+
function addAppToUnload(app, promiseGetter, resolve, reject) {
|
|
48
|
+
appsToUnload[require_applications_app_helpers.toName(app)] = {
|
|
49
|
+
app,
|
|
50
|
+
resolve,
|
|
51
|
+
reject
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(appsToUnload[require_applications_app_helpers.toName(app)], "promise", { get: promiseGetter });
|
|
54
|
+
}
|
|
55
|
+
function getAppUnloadInfo(appName) {
|
|
56
|
+
return appsToUnload[appName];
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.addAppToUnload = addAppToUnload;
|
|
60
|
+
exports.getAppUnloadInfo = getAppUnloadInfo;
|
|
61
|
+
exports.toUnloadPromise = toUnloadPromise;
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=unload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unload.js","names":[],"sources":["../../../src/lifecycles/unload.ts"],"sourcesContent":["import { toName, AppOrParcelStatus, InternalApplication } from '../applications/app.helpers';\nimport { handleAppError } from '../applications/app-errors';\nimport { reasonableTime } from '../applications/timeouts';\nimport { addProfileEntry } from '../devtools/profiler';\nimport { LoadedApp } from './lifecycle.helpers';\n\ninterface UnloadInfo {\n app: InternalApplication;\n promise?: Promise<any>;\n resolve: (val?) => void;\n reject: (val?) => void;\n}\n\nconst appsToUnload: Record<string, UnloadInfo> = {};\n\nexport function toUnloadPromise(app: LoadedApp): Promise<LoadedApp> {\n return Promise.resolve().then(() => {\n const unloadInfo = appsToUnload[toName(app)];\n\n if (!unloadInfo) {\n /* No one has called unloadApplication for this app,\n */\n return app;\n }\n\n if (app.status === AppOrParcelStatus.NOT_LOADED) {\n /* This app is already unloaded. We just need to clean up\n * anything that still thinks we need to unload the app.\n */\n finishUnloadingApp(app, unloadInfo);\n return app;\n }\n\n if (app.status === AppOrParcelStatus.UNLOADING) {\n /* Both unloadApplication and reroute want to unload this app.\n * It only needs to be done once, though.\n */\n return unloadInfo.promise!.then(() => app);\n }\n\n if (\n app.status !== AppOrParcelStatus.NOT_MOUNTED &&\n app.status !== AppOrParcelStatus.LOAD_ERROR &&\n app.status !== AppOrParcelStatus.SKIP_BECAUSE_BROKEN\n ) {\n /* The app cannot be unloaded unless in certain statuses\n */\n return app;\n }\n\n let startTime: number;\n\n if (__PROFILE__) {\n startTime = performance.now();\n }\n\n const unloadPromise = app.unload ? reasonableTime(app, 'unload') : Promise.resolve();\n\n app.status = AppOrParcelStatus.UNLOADING;\n\n return unloadPromise\n .then(() => {\n if (__PROFILE__) {\n addProfileEntry('application', toName(app), 'unload', startTime, performance.now(), true);\n }\n\n finishUnloadingApp(app, unloadInfo);\n\n return app;\n })\n .catch((err) => {\n if (__PROFILE__) {\n addProfileEntry('application', toName(app), 'unload', startTime, performance.now(), false);\n }\n\n errorUnloadingApp(app, unloadInfo, err);\n\n return app;\n });\n });\n}\n\nfunction finishUnloadingApp(app: LoadedApp, unloadInfo: UnloadInfo) {\n delete appsToUnload[toName(app)];\n\n // Unloaded apps don't have lifecycles\n delete app.bootstrap;\n delete app.mount;\n delete app.unmount;\n delete app.unload;\n\n app.status = AppOrParcelStatus.NOT_LOADED;\n\n /* resolve the promise of whoever called unloadApplication.\n * This should be done after all other cleanup/bookkeeping\n */\n unloadInfo.resolve();\n}\n\nfunction errorUnloadingApp(app: LoadedApp, unloadInfo: UnloadInfo, err: Error) {\n delete appsToUnload[toName(app)];\n\n // Unloaded apps don't have lifecycles\n delete app.bootstrap;\n delete app.mount;\n delete app.unmount;\n delete app.unload;\n\n handleAppError(err, app, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n unloadInfo.reject(err);\n}\n\nexport function addAppToUnload(\n app: InternalApplication,\n promiseGetter: () => Promise<any>,\n resolve: (val?) => any,\n reject: (val?) => any,\n) {\n appsToUnload[toName(app)] = { app, resolve, reject };\n Object.defineProperty(appsToUnload[toName(app)], 'promise', {\n get: promiseGetter,\n });\n}\n\nexport function getAppUnloadInfo(appName: string): UnloadInfo {\n return appsToUnload[appName];\n}\n"],"mappings":";;;;;;AAaA,IAAM,eAA2C,CAAC;AAElD,SAAgB,gBAAgB,KAAoC;CAClE,OAAO,QAAQ,QAAQ,CAAC,CAAC,WAAW;EAClC,MAAM,aAAa,aAAa,iCAAA,OAAO,GAAG;EAE1C,IAAI,CAAC,YAGH,OAAO;EAGT,IAAI,IAAI,WAAW,iCAAA,kBAAkB,YAAY;GAI/C,mBAAmB,KAAK,UAAU;GAClC,OAAO;EACT;EAEA,IAAI,IAAI,WAAW,iCAAA,kBAAkB,WAInC,OAAO,WAAW,QAAS,WAAW,GAAG;EAG3C,IACE,IAAI,WAAW,iCAAA,kBAAkB,eACjC,IAAI,WAAW,iCAAA,kBAAkB,cACjC,IAAI,WAAW,iCAAA,kBAAkB,qBAIjC,OAAO;EAST,MAAM,gBAAgB,IAAI,SAAS,8BAAA,eAAe,KAAK,QAAQ,IAAI,QAAQ,QAAQ;EAEnF,IAAI,SAAS,iCAAA,kBAAkB;EAE/B,OAAO,cACJ,WAAW;GAKV,mBAAmB,KAAK,UAAU;GAElC,OAAO;EACT,CAAC,CAAC,CACD,OAAO,QAAQ;GAKd,kBAAkB,KAAK,YAAY,GAAG;GAEtC,OAAO;EACT,CAAC;CACL,CAAC;AACH;AAEA,SAAS,mBAAmB,KAAgB,YAAwB;CAClE,OAAO,aAAa,iCAAA,OAAO,GAAG;CAG9B,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CAEX,IAAI,SAAS,iCAAA,kBAAkB;CAK/B,WAAW,QAAQ;AACrB;AAEA,SAAS,kBAAkB,KAAgB,YAAwB,KAAY;CAC7E,OAAO,aAAa,iCAAA,OAAO,GAAG;CAG9B,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CACX,OAAO,IAAI;CAEX,gCAAA,eAAe,KAAK,KAAK,iCAAA,kBAAkB,mBAAmB;CAC9D,WAAW,OAAO,GAAG;AACvB;AAEA,SAAgB,eACd,KACA,eACA,SACA,QACA;CACA,aAAa,iCAAA,OAAO,GAAG,KAAK;EAAE;EAAK;EAAS;CAAO;CACnD,OAAO,eAAe,aAAa,iCAAA,OAAO,GAAG,IAAI,WAAW,EAC1D,KAAK,cACP,CAAC;AACH;AAEA,SAAgB,iBAAiB,SAA6B;CAC5D,OAAO,aAAa;AACtB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_applications_app_helpers = require("../applications/app.helpers.js");
|
|
3
|
+
const require_applications_app_errors = require("../applications/app-errors.js");
|
|
4
|
+
require("../devtools/profiler.js");
|
|
5
|
+
const require_applications_timeouts = require("../applications/timeouts.js");
|
|
6
|
+
//#region src/lifecycles/unmount.ts
|
|
7
|
+
function toUnmountPromise(appOrParcel, hardFail) {
|
|
8
|
+
return Promise.resolve().then(() => {
|
|
9
|
+
if (appOrParcel.status !== require_applications_app_helpers.AppOrParcelStatus.MOUNTED) return appOrParcel;
|
|
10
|
+
appOrParcel.status = require_applications_app_helpers.AppOrParcelStatus.UNMOUNTING;
|
|
11
|
+
const unmountChildrenParcels = Object.keys(appOrParcel.parcels).map((parcelId) => appOrParcel.parcels[parcelId].unmountThisParcel());
|
|
12
|
+
return Promise.all(unmountChildrenParcels).then(unmountAppOrParcel, (parcelError) => {
|
|
13
|
+
return unmountAppOrParcel().then(() => {
|
|
14
|
+
const parentError = Error(parcelError.message);
|
|
15
|
+
if (hardFail) throw require_applications_app_errors.transformErr(parentError, appOrParcel, require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN);
|
|
16
|
+
else require_applications_app_errors.handleAppError(parentError, appOrParcel, require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN);
|
|
17
|
+
});
|
|
18
|
+
}).then(() => appOrParcel);
|
|
19
|
+
function unmountAppOrParcel() {
|
|
20
|
+
return require_applications_timeouts.reasonableTime(appOrParcel, "unmount").then(() => {
|
|
21
|
+
appOrParcel.status = require_applications_app_helpers.AppOrParcelStatus.NOT_MOUNTED;
|
|
22
|
+
}, (err) => {
|
|
23
|
+
if (hardFail) throw require_applications_app_errors.transformErr(err, appOrParcel, require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN);
|
|
24
|
+
else require_applications_app_errors.handleAppError(err, appOrParcel, require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.toUnmountPromise = toUnmountPromise;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=unmount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unmount.js","names":[],"sources":["../../../src/lifecycles/unmount.ts"],"sourcesContent":["import { AppOrParcelStatus, toName, isParcel } from '../applications/app.helpers';\nimport { handleAppError, transformErr } from '../applications/app-errors';\nimport { reasonableTime } from '../applications/timeouts';\nimport { ProfileEntry, addProfileEntry } from '../devtools/profiler';\nimport { LoadedAppOrParcel } from './lifecycle.helpers';\n\nexport function toUnmountPromise(appOrParcel: LoadedAppOrParcel, hardFail?: boolean): Promise<LoadedAppOrParcel> {\n return Promise.resolve().then(() => {\n if (appOrParcel.status !== AppOrParcelStatus.MOUNTED) {\n return appOrParcel;\n }\n\n let startTime: number, profileEventType: ProfileEntry['type'];\n\n if (__PROFILE__) {\n startTime = performance.now();\n profileEventType = isParcel(appOrParcel) ? 'parcel' : 'application';\n }\n\n appOrParcel.status = AppOrParcelStatus.UNMOUNTING;\n\n const unmountChildrenParcels = Object.keys(appOrParcel.parcels).map((parcelId) =>\n appOrParcel.parcels[parcelId].unmountThisParcel(),\n );\n\n let parcelError: Error;\n\n return Promise.all(unmountChildrenParcels)\n .then(unmountAppOrParcel, (parcelError) => {\n // There is a parcel unmount error\n return unmountAppOrParcel().then(() => {\n // Unmounting the app/parcel succeeded, but unmounting its children parcels did not\n const parentError = Error(parcelError.message);\n if (hardFail) {\n throw transformErr(parentError, appOrParcel, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n } else {\n handleAppError(parentError, appOrParcel, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n }\n });\n })\n .then(() => appOrParcel);\n\n function unmountAppOrParcel() {\n // We always try to unmount the appOrParcel, even if the children parcels failed to unmount.\n return reasonableTime(appOrParcel, 'unmount').then(\n () => {\n // The appOrParcel needs to stay in a broken status if its children parcels fail to unmount\n if (!parcelError) {\n appOrParcel.status = AppOrParcelStatus.NOT_MOUNTED;\n }\n\n if (__PROFILE__) {\n addProfileEntry(profileEventType, toName(appOrParcel), 'unmount', startTime, performance.now(), true);\n }\n },\n (err) => {\n if (__PROFILE__) {\n addProfileEntry(profileEventType, toName(appOrParcel), 'unmount', startTime, performance.now(), false);\n }\n\n if (hardFail) {\n throw transformErr(err, appOrParcel, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n } else {\n handleAppError(err, appOrParcel, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n }\n },\n );\n }\n });\n}\n"],"mappings":";;;;;;AAMA,SAAgB,iBAAiB,aAAgC,UAAgD;CAC/G,OAAO,QAAQ,QAAQ,CAAC,CAAC,WAAW;EAClC,IAAI,YAAY,WAAW,iCAAA,kBAAkB,SAC3C,OAAO;EAUT,YAAY,SAAS,iCAAA,kBAAkB;EAEvC,MAAM,yBAAyB,OAAO,KAAK,YAAY,OAAO,CAAC,CAAC,KAAK,aACnE,YAAY,QAAQ,SAAS,CAAC,kBAAkB,CAClD;EAIA,OAAO,QAAQ,IAAI,sBAAsB,CAAC,CACvC,KAAK,qBAAqB,gBAAgB;GAEzC,OAAO,mBAAmB,CAAC,CAAC,WAAW;IAErC,MAAM,cAAc,MAAM,YAAY,OAAO;IAC7C,IAAI,UACF,MAAM,gCAAA,aAAa,aAAa,aAAa,iCAAA,kBAAkB,mBAAmB;SAElF,gCAAA,eAAe,aAAa,aAAa,iCAAA,kBAAkB,mBAAmB;GAElF,CAAC;EACH,CAAC,CAAC,CACD,WAAW,WAAW;EAEzB,SAAS,qBAAqB;GAE5B,OAAO,8BAAA,eAAe,aAAa,SAAS,CAAC,CAAC,WACtC;IAGF,YAAY,SAAS,iCAAA,kBAAkB;GAM3C,IACC,QAAQ;IAKP,IAAI,UACF,MAAM,gCAAA,aAAa,KAAK,aAAa,iCAAA,kBAAkB,mBAAmB;SAE1E,gCAAA,eAAe,KAAK,aAAa,iCAAA,kBAAkB,mBAAmB;GAE1E,CACF;EACF;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_applications_app_helpers = require("../applications/app.helpers.js");
|
|
3
|
+
const require_applications_app_errors = require("../applications/app-errors.js");
|
|
4
|
+
require("../devtools/profiler.js");
|
|
5
|
+
const require_applications_timeouts = require("../applications/timeouts.js");
|
|
6
|
+
//#region src/lifecycles/update.ts
|
|
7
|
+
function toUpdatePromise(appOrParcel) {
|
|
8
|
+
return Promise.resolve().then(() => {
|
|
9
|
+
if (appOrParcel.status !== require_applications_app_helpers.AppOrParcelStatus.MOUNTED) throw Error(require_applications_app_errors.formatErrorMessage(32, process.env.NODE_ENV !== "production" && `Cannot update parcel '${require_applications_app_helpers.toName(appOrParcel)}' because it is not mounted`, require_applications_app_helpers.toName(appOrParcel)));
|
|
10
|
+
appOrParcel.status = require_applications_app_helpers.AppOrParcelStatus.UPDATING;
|
|
11
|
+
return require_applications_timeouts.reasonableTime(appOrParcel, "update").then(() => {
|
|
12
|
+
appOrParcel.status = require_applications_app_helpers.AppOrParcelStatus.MOUNTED;
|
|
13
|
+
return appOrParcel;
|
|
14
|
+
}).catch((err) => {
|
|
15
|
+
throw require_applications_app_errors.transformErr(err, appOrParcel, require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.toUpdatePromise = toUpdatePromise;
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","names":[],"sources":["../../../src/lifecycles/update.ts"],"sourcesContent":["import { AppOrParcelStatus, toName, isParcel } from '../applications/app.helpers';\nimport { transformErr, formatErrorMessage } from '../applications/app-errors';\nimport { reasonableTime } from '../applications/timeouts';\nimport { ProfileEntry, addProfileEntry } from '../devtools/profiler';\nimport { LoadedAppOrParcel } from './lifecycle.helpers';\n\nexport function toUpdatePromise(appOrParcel: LoadedAppOrParcel): Promise<LoadedAppOrParcel> {\n return Promise.resolve().then(() => {\n let startTime: number, profileEventType: ProfileEntry['type'];\n\n if (__PROFILE__) {\n profileEventType = isParcel(appOrParcel) ? 'parcel' : 'application';\n startTime = performance.now();\n }\n\n if (appOrParcel.status !== AppOrParcelStatus.MOUNTED) {\n throw Error(\n formatErrorMessage(\n 32,\n __DEV__ && `Cannot update parcel '${toName(appOrParcel)}' because it is not mounted`,\n toName(appOrParcel),\n ),\n );\n }\n\n appOrParcel.status = AppOrParcelStatus.UPDATING;\n\n return reasonableTime(appOrParcel, 'update')\n .then(() => {\n appOrParcel.status = AppOrParcelStatus.MOUNTED;\n\n if (__PROFILE__) {\n addProfileEntry(profileEventType, toName(appOrParcel), 'update', startTime, performance.now(), true);\n }\n\n return appOrParcel;\n })\n .catch((err) => {\n if (__PROFILE__) {\n addProfileEntry(profileEventType, toName(appOrParcel), 'update', startTime, performance.now(), false);\n }\n\n throw transformErr(err, appOrParcel, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n });\n });\n}\n"],"mappings":";;;;;;AAMA,SAAgB,gBAAgB,aAA4D;CAC1F,OAAO,QAAQ,QAAQ,CAAC,CAAC,WAAW;EAQlC,IAAI,YAAY,WAAW,iCAAA,kBAAkB,SAC3C,MAAM,MACJ,gCAAA,mBACE,IAAA,QAAA,IAAA,aAAA,gBACW,yBAAyB,iCAAA,OAAO,WAAW,EAAE,8BACxD,iCAAA,OAAO,WAAW,CACpB,CACF;EAGF,YAAY,SAAS,iCAAA,kBAAkB;EAEvC,OAAO,8BAAA,eAAe,aAAa,QAAQ,CAAC,CACzC,WAAW;GACV,YAAY,SAAS,iCAAA,kBAAkB;GAMvC,OAAO;EACT,CAAC,CAAC,CACD,OAAO,QAAQ;GAKd,MAAM,gCAAA,aAAa,KAAK,aAAa,iCAAA,kBAAkB,mBAAmB;EAC5E,CAAC;CACL,CAAC;AACH"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StartOpts } from '../start';
|
|
2
|
+
export declare const routingEventsListeningTo: string[];
|
|
3
|
+
type NavigateArg = string | HTMLAnchorElement | MouseEvent;
|
|
4
|
+
export declare function navigateToUrl(obj: NavigateArg): void;
|
|
5
|
+
export declare function callCapturedEventListeners(eventArguments: [HashChangeEvent | PopStateEvent]): void;
|
|
6
|
+
export declare let originalReplaceState: (data: any, unused: string, url?: string | URL) => void;
|
|
7
|
+
export declare function patchHistoryApi(opts?: StartOpts): void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_applications_app_errors = require("../applications/app-errors.js");
|
|
3
|
+
const require_utils_runtime_environment = require("../utils/runtime-environment.js");
|
|
4
|
+
const require_navigation_reroute = require("./reroute.js");
|
|
5
|
+
//#region src/navigation/navigation-events.ts
|
|
6
|
+
var capturedEventListeners = {
|
|
7
|
+
hashchange: [],
|
|
8
|
+
popstate: []
|
|
9
|
+
};
|
|
10
|
+
var routingEventsListeningTo = ["hashchange", "popstate"];
|
|
11
|
+
function navigateToUrl(obj) {
|
|
12
|
+
let url;
|
|
13
|
+
if (typeof obj === "string") url = obj;
|
|
14
|
+
else if (this && this.href) url = this.href;
|
|
15
|
+
else if (obj && "currentTarget" in obj && "href" in obj.currentTarget && "preventDefault" in obj) {
|
|
16
|
+
url = obj.currentTarget.href;
|
|
17
|
+
obj.preventDefault();
|
|
18
|
+
} else throw Error(require_applications_app_errors.formatErrorMessage(14, process.env.NODE_ENV !== "production" && `singleSpaNavigate/navigateToUrl must be either called with a string url, with an <a> tag as its context, or with an event whose currentTarget is an <a> tag`));
|
|
19
|
+
const current = new URL(window.location.href);
|
|
20
|
+
const destination = new URL(url, window.location.href);
|
|
21
|
+
if (url.indexOf("#") === 0) window.location.hash = destination.hash;
|
|
22
|
+
else if (current.host !== destination.host && destination.host) window.location.href = url;
|
|
23
|
+
else if (destination.pathname === current.pathname && destination.search === current.search) window.location.hash = destination.hash;
|
|
24
|
+
else window.history.pushState(null, null, url);
|
|
25
|
+
}
|
|
26
|
+
function callCapturedEventListeners(eventArguments) {
|
|
27
|
+
if (eventArguments) {
|
|
28
|
+
const eventType = eventArguments[0].type;
|
|
29
|
+
if (routingEventsListeningTo.indexOf(eventType) >= 0) capturedEventListeners[eventType].forEach((listener) => {
|
|
30
|
+
try {
|
|
31
|
+
listener.apply(this, eventArguments);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
throw e;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var urlRerouteOnly;
|
|
41
|
+
function urlReroute(evt) {
|
|
42
|
+
require_navigation_reroute.reroute([], [evt]);
|
|
43
|
+
}
|
|
44
|
+
function patchedUpdateState(updateState, methodName) {
|
|
45
|
+
return function() {
|
|
46
|
+
const urlBefore = window.location.href;
|
|
47
|
+
const result = updateState.apply(this, arguments);
|
|
48
|
+
const urlAfter = window.location.href;
|
|
49
|
+
if (!urlRerouteOnly || urlBefore !== urlAfter) window.dispatchEvent(createPopStateEvent(window.history.state, methodName));
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function createPopStateEvent(state, originalMethodName) {
|
|
54
|
+
let evt = new PopStateEvent("popstate", { state });
|
|
55
|
+
evt.singleSpa = true;
|
|
56
|
+
evt.singleSpaTrigger = originalMethodName;
|
|
57
|
+
return evt;
|
|
58
|
+
}
|
|
59
|
+
var originalReplaceState = null;
|
|
60
|
+
var historyApiIsPatched = false;
|
|
61
|
+
function patchHistoryApi(opts) {
|
|
62
|
+
if (historyApiIsPatched) throw Error(require_applications_app_errors.formatErrorMessage(43, process.env.NODE_ENV !== "production" && `single-spa: patchHistoryApi() was called after the history api was already patched.`));
|
|
63
|
+
urlRerouteOnly = (opts === null || opts === void 0 ? void 0 : opts.hasOwnProperty("urlRerouteOnly")) ? opts.urlRerouteOnly : true;
|
|
64
|
+
historyApiIsPatched = true;
|
|
65
|
+
originalReplaceState = window.history.replaceState;
|
|
66
|
+
window.addEventListener("hashchange", urlReroute);
|
|
67
|
+
window.addEventListener("popstate", urlReroute);
|
|
68
|
+
const originalAddEventListener = window.addEventListener;
|
|
69
|
+
const originalRemoveEventListener = window.removeEventListener;
|
|
70
|
+
window.addEventListener = function(eventName, fn) {
|
|
71
|
+
if (typeof fn === "function") {
|
|
72
|
+
if (routingEventsListeningTo.indexOf(eventName) >= 0 && !capturedEventListeners[eventName].find((listener) => listener === fn)) {
|
|
73
|
+
capturedEventListeners[eventName].push(fn);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return originalAddEventListener.apply(this, arguments);
|
|
78
|
+
};
|
|
79
|
+
window.removeEventListener = function(eventName, listenerFn) {
|
|
80
|
+
if (typeof listenerFn === "function") {
|
|
81
|
+
if (routingEventsListeningTo.includes(eventName)) capturedEventListeners[eventName] = capturedEventListeners[eventName].filter((fn) => fn !== listenerFn);
|
|
82
|
+
}
|
|
83
|
+
return originalRemoveEventListener.apply(this, arguments);
|
|
84
|
+
};
|
|
85
|
+
window.history.pushState = patchedUpdateState(window.history.pushState, "pushState");
|
|
86
|
+
window.history.replaceState = patchedUpdateState(originalReplaceState, "replaceState");
|
|
87
|
+
}
|
|
88
|
+
if (require_utils_runtime_environment.isInBrowser) if (window.singleSpaNavigate) console.warn(require_applications_app_errors.formatErrorMessage(41, process.env.NODE_ENV !== "production" && "single-spa has been loaded twice on the page. This can result in unexpected behavior."));
|
|
89
|
+
else window.singleSpaNavigate = navigateToUrl;
|
|
90
|
+
//#endregion
|
|
91
|
+
exports.callCapturedEventListeners = callCapturedEventListeners;
|
|
92
|
+
exports.navigateToUrl = navigateToUrl;
|
|
93
|
+
Object.defineProperty(exports, "originalReplaceState", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function() {
|
|
96
|
+
return originalReplaceState;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
exports.patchHistoryApi = patchHistoryApi;
|
|
100
|
+
exports.routingEventsListeningTo = routingEventsListeningTo;
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=navigation-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation-events.js","names":[],"sources":["../../../src/navigation/navigation-events.ts"],"sourcesContent":["import { reroute } from './reroute';\nimport { formatErrorMessage } from '../applications/app-errors';\nimport { isInBrowser } from '../utils/runtime-environment';\nimport { StartOpts } from '../start';\n\n/* We capture navigation event listeners so that we can make sure\n * that application navigation listeners are not called until\n * single-spa has ensured that the correct applications are\n * unmounted and mounted.\n */\nconst capturedEventListeners: CapturedEventListeners = {\n hashchange: [],\n popstate: [],\n};\n\ninterface CapturedEventListeners {\n hashchange: ((this: Window, ev: HashChangeEvent) => any)[];\n popstate: ((this: Window, ev: PopStateEvent) => any)[];\n}\n\nexport const routingEventsListeningTo = ['hashchange', 'popstate'];\n\ntype NavigateArg = string | HTMLAnchorElement | MouseEvent;\n\nexport function navigateToUrl(obj: NavigateArg): void {\n let url;\n if (typeof obj === 'string') {\n url = obj;\n } else if (this && this.href) {\n url = this.href;\n } else if (obj && 'currentTarget' in obj && 'href' in obj.currentTarget && 'preventDefault' in obj) {\n url = ((obj as MouseEvent).currentTarget as HTMLAnchorElement).href;\n (obj as MouseEvent).preventDefault();\n } else {\n throw Error(\n formatErrorMessage(\n 14,\n __DEV__ &&\n `singleSpaNavigate/navigateToUrl must be either called with a string url, with an <a> tag as its context, or with an event whose currentTarget is an <a> tag`,\n ),\n );\n }\n\n const current = new URL(window.location.href);\n const destination = new URL(url, window.location.href);\n\n if (url.indexOf('#') === 0) {\n window.location.hash = destination.hash;\n } else if (current.host !== destination.host && destination.host) {\n if (process.env.BABEL_ENV === 'test') {\n // @ts-expect-error test-only return value\n return { wouldHaveReloadedThePage: true };\n } else {\n window.location.href = url;\n }\n } else if (destination.pathname === current.pathname && destination.search === current.search) {\n window.location.hash = destination.hash;\n } else {\n // different path, host, or query params\n window.history.pushState(null, null, url);\n }\n}\n\nexport function callCapturedEventListeners(eventArguments: [HashChangeEvent | PopStateEvent]): void {\n if (eventArguments) {\n const eventType = eventArguments[0].type;\n if (routingEventsListeningTo.indexOf(eventType) >= 0) {\n capturedEventListeners[eventType].forEach((listener) => {\n try {\n // The error thrown by application event listener should not break single-spa down.\n // Just like https://github.com/single-spa/single-spa/blob/85f5042dff960e40936f3a5069d56fc9477fac04/src/navigation/reroute.js#L140-L146 did\n listener.apply(this, eventArguments);\n } catch (e) {\n setTimeout(() => {\n throw e;\n });\n }\n });\n }\n }\n}\n\nlet urlRerouteOnly: boolean;\n\nfunction urlReroute(evt: HashChangeEvent | PopStateEvent) {\n reroute([], [evt]);\n}\n\ntype UpdateState = (data: any, unused: string, url?: string | URL) => void;\n\nfunction patchedUpdateState(updateState: UpdateState, methodName: 'pushState' | 'replaceState') {\n return function () {\n const urlBefore = window.location.href;\n const result = updateState.apply(this, arguments);\n const urlAfter = window.location.href;\n\n if (!urlRerouteOnly || urlBefore !== urlAfter) {\n // fire an artificial popstate event so that\n // single-spa applications know about routing that\n // occurs in a different application\n window.dispatchEvent(createPopStateEvent(window.history.state, methodName));\n }\n\n return result;\n };\n}\n\ninterface SingleSpaPopStateEvent extends PopStateEvent {\n singleSpa: boolean;\n singleSpaTrigger: string;\n}\n\nfunction createPopStateEvent(state, originalMethodName): SingleSpaPopStateEvent {\n // https://github.com/single-spa/single-spa/issues/224 and https://github.com/single-spa/single-spa-angular/issues/49\n // We need a popstate event even though the browser doesn't fire one by default when you call replaceState, so that\n // all the applications can reroute. We explicitly identify this extraneous event by setting singleSpa=true and\n // singleSpaTrigger=<pushState|replaceState> on the event instance.\n let evt = new PopStateEvent('popstate', { state });\n (evt as SingleSpaPopStateEvent).singleSpa = true;\n (evt as SingleSpaPopStateEvent).singleSpaTrigger = originalMethodName;\n return evt as SingleSpaPopStateEvent;\n}\n\nexport let originalReplaceState: (data: any, unused: string, url?: string | URL) => void = null;\n\nlet historyApiIsPatched: boolean = false;\n\n// We patch the history API so single-spa is notified of all calls to pushState/replaceState.\n// We patch addEventListener/removeEventListener so we can capture all popstate/hashchange event listeners,\n// and delay calling them until single-spa has finished mounting/unmounting applications\nexport function patchHistoryApi(opts?: StartOpts) {\n if (historyApiIsPatched) {\n throw Error(\n formatErrorMessage(\n 43,\n __DEV__ && `single-spa: patchHistoryApi() was called after the history api was already patched.`,\n ),\n );\n }\n\n // True by default, as a performance optimization that reduces\n // the number of extraneous popstate events\n urlRerouteOnly = opts?.hasOwnProperty('urlRerouteOnly') ? opts.urlRerouteOnly : true;\n\n historyApiIsPatched = true;\n\n originalReplaceState = window.history.replaceState;\n\n // We will trigger an app change for any routing events.\n window.addEventListener('hashchange', urlReroute);\n window.addEventListener('popstate', urlReroute);\n\n // Patch addEventListener so that we can ensure correct timing\n const originalAddEventListener = window.addEventListener;\n const originalRemoveEventListener = window.removeEventListener;\n window.addEventListener = function (eventName, fn) {\n if (typeof fn === 'function') {\n if (\n routingEventsListeningTo.indexOf(eventName) >= 0 &&\n !capturedEventListeners[eventName].find((listener) => listener === fn)\n ) {\n capturedEventListeners[eventName].push(fn);\n return;\n }\n }\n\n return originalAddEventListener.apply(this, arguments);\n };\n\n window.removeEventListener = function (eventName, listenerFn) {\n if (typeof listenerFn === 'function') {\n if (routingEventsListeningTo.includes(eventName)) {\n capturedEventListeners[eventName] = capturedEventListeners[eventName].filter((fn) => fn !== listenerFn);\n }\n }\n\n return originalRemoveEventListener.apply(this, arguments);\n };\n\n window.history.pushState = patchedUpdateState(window.history.pushState, 'pushState');\n window.history.replaceState = patchedUpdateState(originalReplaceState, 'replaceState');\n}\n\n// Detect if single-spa has already been loaded on the page.\n// If so, warn because this can result in lots of problems, including\n// lots of extraneous popstate events and unexpected results for\n// apis like getAppNames().\nif (isInBrowser) {\n if (window.singleSpaNavigate) {\n console.warn(\n formatErrorMessage(\n 41,\n __DEV__ && 'single-spa has been loaded twice on the page. This can result in unexpected behavior.',\n ),\n );\n } else {\n /* For convenience in `onclick` attributes, we expose a global function for navigating to\n * whatever an <a> tag's href is.\n */\n window.singleSpaNavigate = navigateToUrl;\n }\n}\n"],"mappings":";;;;;AAUA,IAAM,yBAAiD;CACrD,YAAY,CAAC;CACb,UAAU,CAAC;AACb;AAOA,IAAa,2BAA2B,CAAC,cAAc,UAAU;AAIjE,SAAgB,cAAc,KAAwB;CACpD,IAAI;CACJ,IAAI,OAAO,QAAQ,UACjB,MAAM;MACD,IAAI,QAAQ,KAAK,MACtB,MAAM,KAAK;MACN,IAAI,OAAO,mBAAmB,OAAO,UAAU,IAAI,iBAAiB,oBAAoB,KAAK;EAClG,MAAQ,IAAmB,cAAoC;EAC/D,IAAoB,eAAe;CACrC,OACE,MAAM,MACJ,gCAAA,mBACE,IAAA,QAAA,IAAA,aAAA,gBAEE,6JACJ,CACF;CAGF,MAAM,UAAU,IAAI,IAAI,OAAO,SAAS,IAAI;CAC5C,MAAM,cAAc,IAAI,IAAI,KAAK,OAAO,SAAS,IAAI;CAErD,IAAI,IAAI,QAAQ,GAAG,MAAM,GACvB,OAAO,SAAS,OAAO,YAAY;MAC9B,IAAI,QAAQ,SAAS,YAAY,QAAQ,YAAY,MAKxD,OAAO,SAAS,OAAO;MAEpB,IAAI,YAAY,aAAa,QAAQ,YAAY,YAAY,WAAW,QAAQ,QACrF,OAAO,SAAS,OAAO,YAAY;MAGnC,OAAO,QAAQ,UAAU,MAAM,MAAM,GAAG;AAE5C;AAEA,SAAgB,2BAA2B,gBAAyD;CAClG,IAAI,gBAAgB;EAClB,MAAM,YAAY,eAAe,EAAE,CAAC;EACpC,IAAI,yBAAyB,QAAQ,SAAS,KAAK,GACjD,uBAAuB,UAAU,CAAC,SAAS,aAAa;GACtD,IAAI;IAGF,SAAS,MAAM,MAAM,cAAc;GACrC,SAAS,GAAG;IACV,iBAAiB;KACf,MAAM;IACR,CAAC;GACH;EACF,CAAC;CAEL;AACF;AAEA,IAAI;AAEJ,SAAS,WAAW,KAAsC;CACxD,2BAAA,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;AACnB;AAIA,SAAS,mBAAmB,aAA0B,YAA0C;CAC9F,OAAO,WAAY;EACjB,MAAM,YAAY,OAAO,SAAS;EAClC,MAAM,SAAS,YAAY,MAAM,MAAM,SAAS;EAChD,MAAM,WAAW,OAAO,SAAS;EAEjC,IAAI,CAAC,kBAAkB,cAAc,UAInC,OAAO,cAAc,oBAAoB,OAAO,QAAQ,OAAO,UAAU,CAAC;EAG5E,OAAO;CACT;AACF;AAOA,SAAS,oBAAoB,OAAO,oBAA4C;CAK9E,IAAI,MAAM,IAAI,cAAc,YAAY,EAAE,MAAM,CAAC;CACjD,IAAgC,YAAY;CAC5C,IAAgC,mBAAmB;CACnD,OAAO;AACT;AAEA,IAAW,uBAAgF;AAE3F,IAAI,sBAA+B;AAKnC,SAAgB,gBAAgB,MAAkB;CAChD,IAAI,qBACF,MAAM,MACJ,gCAAA,mBACE,IAAA,QAAA,IAAA,aAAA,gBACW,qFACb,CACF;CAKF,kBAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAiB,KAAM,eAAe,gBAAgB,KAAI,KAAK,iBAAiB;CAEhF,sBAAsB;CAEtB,uBAAuB,OAAO,QAAQ;CAGtC,OAAO,iBAAiB,cAAc,UAAU;CAChD,OAAO,iBAAiB,YAAY,UAAU;CAG9C,MAAM,2BAA2B,OAAO;CACxC,MAAM,8BAA8B,OAAO;CAC3C,OAAO,mBAAmB,SAAU,WAAW,IAAI;EACjD,IAAI,OAAO,OAAO,YAChB;OACE,yBAAyB,QAAQ,SAAS,KAAK,KAC/C,CAAC,uBAAuB,UAAU,CAAC,MAAM,aAAa,aAAa,EAAE,GACrE;IACA,uBAAuB,UAAU,CAAC,KAAK,EAAE;IACzC;GACF;;EAGF,OAAO,yBAAyB,MAAM,MAAM,SAAS;CACvD;CAEA,OAAO,sBAAsB,SAAU,WAAW,YAAY;EAC5D,IAAI,OAAO,eAAe,YACxB;OAAI,yBAAyB,SAAS,SAAS,GAC7C,uBAAuB,aAAa,uBAAuB,UAAU,CAAC,QAAQ,OAAO,OAAO,UAAU;EACxG;EAGF,OAAO,4BAA4B,MAAM,MAAM,SAAS;CAC1D;CAEA,OAAO,QAAQ,YAAY,mBAAmB,OAAO,QAAQ,WAAW,WAAW;CACnF,OAAO,QAAQ,eAAe,mBAAmB,sBAAsB,cAAc;AACvF;AAMA,IAAI,kCAAA,aACF,IAAI,OAAO,mBACT,QAAQ,KACN,gCAAA,mBACE,IAAA,QAAA,IAAA,aAAA,gBACW,uFACb,CACF;KAKA,OAAO,oBAAoB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type EventArguments = [HashChangeEvent | PopStateEvent];
|
|
2
|
+
interface WaitingPromises {
|
|
3
|
+
resolve(value: unknown): void;
|
|
4
|
+
reject(value: unknown): void;
|
|
5
|
+
eventArguments?: [HashChangeEvent | PopStateEvent];
|
|
6
|
+
}
|
|
7
|
+
export declare function triggerAppChange(): Promise<string[]>;
|
|
8
|
+
export declare function reroute(pendingPromises?: WaitingPromises[], eventArguments?: EventArguments, silentNavigation?: boolean): Promise<string[]>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_applications_app_helpers = require("../applications/app.helpers.js");
|
|
3
|
+
const require_applications_app_errors = require("../applications/app-errors.js");
|
|
4
|
+
const require_utils_runtime_environment = require("../utils/runtime-environment.js");
|
|
5
|
+
const require_start = require("../start.js");
|
|
6
|
+
require("../devtools/profiler.js");
|
|
7
|
+
const require_lifecycles_bootstrap = require("../lifecycles/bootstrap.js");
|
|
8
|
+
const require_lifecycles_unmount = require("../lifecycles/unmount.js");
|
|
9
|
+
const require_lifecycles_mount = require("../lifecycles/mount.js");
|
|
10
|
+
const require_lifecycles_load = require("../lifecycles/load.js");
|
|
11
|
+
const require_lifecycles_unload = require("../lifecycles/unload.js");
|
|
12
|
+
const require_navigation_navigation_events = require("./navigation-events.js");
|
|
13
|
+
const require_applications_apps = require("../applications/apps.js");
|
|
14
|
+
//#region src/navigation/reroute.ts
|
|
15
|
+
var appChangeUnderway = false;
|
|
16
|
+
var promisesWaitingOnAppChange = [];
|
|
17
|
+
var currentUrl = require_utils_runtime_environment.isInBrowser && window.location.href;
|
|
18
|
+
function triggerAppChange() {
|
|
19
|
+
return reroute();
|
|
20
|
+
}
|
|
21
|
+
function reroute(pendingPromises = [], eventArguments = void 0, silentNavigation = false) {
|
|
22
|
+
if (appChangeUnderway) return new Promise((resolve, reject) => {
|
|
23
|
+
promisesWaitingOnAppChange.push({
|
|
24
|
+
resolve,
|
|
25
|
+
reject,
|
|
26
|
+
eventArguments
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
const { appsToUnload, appsToUnmount, appsToLoad, appsToMount } = require_applications_apps.getAppChanges();
|
|
30
|
+
let appsThatChanged, cancelPromises = [], oldUrl = currentUrl, newUrl = currentUrl = window.location.href;
|
|
31
|
+
if (require_start.isStarted()) {
|
|
32
|
+
appChangeUnderway = true;
|
|
33
|
+
appsThatChanged = appsToUnload.concat(appsToLoad, appsToUnmount, appsToMount);
|
|
34
|
+
return performAppChanges();
|
|
35
|
+
} else {
|
|
36
|
+
appsThatChanged = appsToLoad;
|
|
37
|
+
return loadApps();
|
|
38
|
+
}
|
|
39
|
+
function cancelNavigation(val = true) {
|
|
40
|
+
const promise = typeof (val === null || val === void 0 ? void 0 : val.then) === "function" ? val : Promise.resolve(val);
|
|
41
|
+
cancelPromises.push(promise.catch((err) => {
|
|
42
|
+
console.warn(Error(require_applications_app_errors.formatErrorMessage(42, process.env.NODE_ENV !== "production" && `single-spa: A cancelNavigation promise rejected with the following value: ${err}`)));
|
|
43
|
+
console.warn(err);
|
|
44
|
+
return false;
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
function loadApps() {
|
|
48
|
+
return Promise.resolve().then(() => {
|
|
49
|
+
const loadPromises = appsToLoad.map(require_lifecycles_load.toLoadPromise);
|
|
50
|
+
return Promise.all(loadPromises).then(callAllEventListeners).then(() => {
|
|
51
|
+
return [];
|
|
52
|
+
}).catch((err) => {
|
|
53
|
+
callAllEventListeners();
|
|
54
|
+
throw err;
|
|
55
|
+
}).finally(() => {});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function performAppChanges() {
|
|
59
|
+
return Promise.resolve().then(() => {
|
|
60
|
+
fireSingleSpaEvent(appsThatChanged.length === 0 ? "before-no-app-change" : "before-app-change", getCustomEventDetail(true));
|
|
61
|
+
fireSingleSpaEvent("before-routing-event", getCustomEventDetail(true, { cancelNavigation }));
|
|
62
|
+
return Promise.all(cancelPromises).then((cancelValues) => {
|
|
63
|
+
if (cancelValues.some((v) => v)) {
|
|
64
|
+
require_navigation_navigation_events.originalReplaceState.call(window.history, history.state, "", oldUrl.substring(location.origin.length));
|
|
65
|
+
currentUrl = location.href;
|
|
66
|
+
appChangeUnderway = false;
|
|
67
|
+
return reroute(pendingPromises, eventArguments, true);
|
|
68
|
+
}
|
|
69
|
+
const unloadPromises = appsToUnload.map(require_lifecycles_unload.toUnloadPromise);
|
|
70
|
+
const allUnmountPromises = [...appsToUnmount.map((app) => require_lifecycles_unmount.toUnmountPromise(app)).map((unmountPromise) => unmountPromise.then(require_lifecycles_unload.toUnloadPromise)), ...unloadPromises];
|
|
71
|
+
const unmountAllPromise = Promise.all(allUnmountPromises);
|
|
72
|
+
unmountAllPromise.then(() => {
|
|
73
|
+
fireSingleSpaEvent("before-mount-routing-event", getCustomEventDetail(true));
|
|
74
|
+
}, (err) => {
|
|
75
|
+
throw err;
|
|
76
|
+
});
|
|
77
|
+
const loadThenMountPromises = appsToLoad.map((app) => {
|
|
78
|
+
return require_lifecycles_load.toLoadPromise(app).then((app) => tryToInitAndMount(app, unmountAllPromise));
|
|
79
|
+
});
|
|
80
|
+
const mountPromises = appsToMount.filter((appToMount) => !appsToLoad.includes(appToMount)).map((appToMount) => {
|
|
81
|
+
return tryToInitAndMount(appToMount, unmountAllPromise);
|
|
82
|
+
});
|
|
83
|
+
return unmountAllPromise.catch((err) => {
|
|
84
|
+
callAllEventListeners();
|
|
85
|
+
throw err;
|
|
86
|
+
}).then(() => {
|
|
87
|
+
callAllEventListeners();
|
|
88
|
+
return Promise.all(loadThenMountPromises.concat(mountPromises)).catch((err) => {
|
|
89
|
+
pendingPromises.forEach((promise) => promise.reject(err));
|
|
90
|
+
throw err;
|
|
91
|
+
}).then(() => {}, (err) => {
|
|
92
|
+
throw err;
|
|
93
|
+
}).then(finishUpAndReturn);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function finishUpAndReturn() {
|
|
99
|
+
const returnValue = require_applications_apps.getMountedApps();
|
|
100
|
+
pendingPromises.forEach((promise) => promise.resolve(returnValue));
|
|
101
|
+
try {
|
|
102
|
+
fireSingleSpaEvent(appsThatChanged.length === 0 ? "no-app-change" : "app-change", getCustomEventDetail());
|
|
103
|
+
fireSingleSpaEvent("routing-event", getCustomEventDetail());
|
|
104
|
+
} catch (err) {
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
throw err;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
appChangeUnderway = false;
|
|
110
|
+
if (promisesWaitingOnAppChange.length > 0) {
|
|
111
|
+
const nextPendingPromises = promisesWaitingOnAppChange;
|
|
112
|
+
promisesWaitingOnAppChange = [];
|
|
113
|
+
reroute(nextPendingPromises);
|
|
114
|
+
}
|
|
115
|
+
return returnValue;
|
|
116
|
+
}
|
|
117
|
+
function callAllEventListeners() {
|
|
118
|
+
if (!silentNavigation) {
|
|
119
|
+
pendingPromises.forEach((pendingPromise) => {
|
|
120
|
+
require_navigation_navigation_events.callCapturedEventListeners(pendingPromise.eventArguments);
|
|
121
|
+
});
|
|
122
|
+
require_navigation_navigation_events.callCapturedEventListeners(eventArguments);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function getCustomEventDetail(isBeforeChanges = false, extraProperties) {
|
|
126
|
+
const newAppStatuses = {};
|
|
127
|
+
const appsByNewStatus = {
|
|
128
|
+
[require_applications_app_helpers.AppOrParcelStatus.MOUNTED]: [],
|
|
129
|
+
[require_applications_app_helpers.AppOrParcelStatus.NOT_MOUNTED]: [],
|
|
130
|
+
[require_applications_app_helpers.AppOrParcelStatus.NOT_LOADED]: [],
|
|
131
|
+
[require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN]: []
|
|
132
|
+
};
|
|
133
|
+
if (isBeforeChanges) {
|
|
134
|
+
appsToLoad.concat(appsToMount).forEach((app, index) => {
|
|
135
|
+
addApp(app, require_applications_app_helpers.AppOrParcelStatus.MOUNTED);
|
|
136
|
+
});
|
|
137
|
+
appsToUnload.forEach((app) => {
|
|
138
|
+
addApp(app, require_applications_app_helpers.AppOrParcelStatus.NOT_LOADED);
|
|
139
|
+
});
|
|
140
|
+
appsToUnmount.forEach((app) => {
|
|
141
|
+
addApp(app, require_applications_app_helpers.AppOrParcelStatus.NOT_MOUNTED);
|
|
142
|
+
});
|
|
143
|
+
} else appsThatChanged.forEach((app) => {
|
|
144
|
+
addApp(app);
|
|
145
|
+
});
|
|
146
|
+
const result = { detail: {
|
|
147
|
+
newAppStatuses,
|
|
148
|
+
appsByNewStatus,
|
|
149
|
+
totalAppChanges: appsThatChanged.length,
|
|
150
|
+
originalEvent: eventArguments === null || eventArguments === void 0 ? void 0 : eventArguments[0],
|
|
151
|
+
oldUrl,
|
|
152
|
+
newUrl
|
|
153
|
+
} };
|
|
154
|
+
if (extraProperties) Object.assign(result.detail, extraProperties);
|
|
155
|
+
return result;
|
|
156
|
+
function addApp(app, status) {
|
|
157
|
+
const appName = require_applications_app_helpers.toName(app);
|
|
158
|
+
status = status || require_applications_apps.getAppStatus(appName);
|
|
159
|
+
newAppStatuses[appName] = status;
|
|
160
|
+
(appsByNewStatus[status] = appsByNewStatus[status] || []).push(appName);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function fireSingleSpaEvent(name, eventProperties) {
|
|
164
|
+
if (!silentNavigation) window.dispatchEvent(new CustomEvent(`single-spa:${name}`, eventProperties));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Let's imagine that some kind of delay occurred during application loading.
|
|
169
|
+
* The user without waiting for the application to load switched to another route,
|
|
170
|
+
* this means that we shouldn't initialize and mount that application, thus we check
|
|
171
|
+
* twice if that application should be active before initialize and mounting.
|
|
172
|
+
* https://github.com/single-spa/single-spa/issues/524
|
|
173
|
+
*/
|
|
174
|
+
function tryToInitAndMount(app, unmountAllPromise) {
|
|
175
|
+
if (require_applications_app_helpers.shouldBeActive(app)) return require_lifecycles_bootstrap.toBootstrapPromise(app).then((app) => unmountAllPromise.then(() => require_applications_app_helpers.shouldBeActive(app) ? require_lifecycles_mount.toMountPromise(app) : app));
|
|
176
|
+
else return unmountAllPromise.then(() => app);
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
exports.reroute = reroute;
|
|
180
|
+
exports.triggerAppChange = triggerAppChange;
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=reroute.js.map
|