UNPKG

3.61 kBTypeScriptView Raw
1declare module "single-spa" {
2 type Splat<T> = {
3 [p in keyof T]: Array<T[p]>;
4 };
5
6 export type AppProps = {
7 name: string;
8 singleSpa: any;
9 mountParcel(parcelConfig: ParcelConfig, customProps: object): Parcel;
10 };
11
12 export type ParcelConfig =
13 | ParcelConfigObject
14 | (() => Promise<ParcelConfigObject>);
15
16 type ParcelConfigObject = {
17 name?: string;
18 customProps: object;
19 domElement: HTMLElement;
20 } & LifeCycles;
21
22 type Parcel = {
23 mount(): Promise<null>;
24 unmount(): Promise<null>;
25 getStatus():
26 | "NOT_LOADED"
27 | "LOADING_SOURCE_CODE"
28 | "NOT_BOOTSTRAPPED"
29 | "BOOTSTRAPPING"
30 | "NOT_MOUNTED"
31 | "MOUNTING"
32 | "MOUNTED"
33 | "UPDATING"
34 | "UNMOUNTING"
35 | "UNLOADING"
36 | "SKIP_BECAUSE_BROKEN"
37 | "LOAD_ERROR";
38 loadPromise: Promise<null>;
39 bootstrapPromise: Promise<null>;
40 mountPromise: Promise<null>;
41 unmountPromise: Promise<null>;
42 };
43
44 export type LifeCycles<T = {}> = {
45 bootstrap: (config: T & AppProps) => Promise<any>;
46 mount: (config: T & AppProps) => Promise<any>;
47 unmount: (config: T & AppProps) => Promise<any>;
48 update?: (config: T & AppProps) => Promise<any>;
49 };
50
51 // ./start.js
52 export function start(): void;
53 export function isStarted(): boolean;
54
55 // ./jquery-support.js
56 export function ensureJQuerySupport(jQuery?: any): void;
57
58 // ./applications/timeouts.js
59 export function setBootstrapMaxTime(
60 time: number,
61 dieOnTimeout?: boolean
62 ): void;
63 export function setMountMaxTime(time: number, dieOnTimeout?: boolean): void;
64 export function setUnmountMaxTime(time: number, dieOnTimeout?: boolean): void;
65 export function setUnloadMaxTime(time: number, dieOnTimeout?: boolean): void;
66
67 // ./applications/apps.js
68 export function registerApplication<T extends object = {}>(
69 appName: string,
70 applicationOrLoadingFn:
71 | LifeCycles<T>
72 | ((
73 config: T & AppProps
74 ) => Promise<LifeCycles<T> | Splat<LifeCycles<T>>>),
75 activityFn: (location: Location) => boolean,
76 customProps?: T
77 ): void;
78
79 export function getMountedApps(): string[];
80
81 export const {
82 NOT_LOADED = "NOT_LOADED",
83 LOADING_SOURCE_CODE = "LOADING_SOURCE_CODE",
84 NOT_BOOTSTRAPPED = "NOT_BOOTSTRAPPED",
85 BOOTSTRAPPING = "BOOTSTRAPPING",
86 NOT_MOUNTED = "NOT_MOUNTED",
87 MOUNTING = "MOUNTING",
88 MOUNTED = "MOUNTED",
89 UPDATING = "UPDATING",
90 UNMOUNTING = "UNMOUNTING",
91 UNLOADING = "UNLOADING",
92 SKIP_BECAUSE_BROKEN = "SKIP_BECAUSE_BROKEN",
93 LOAD_ERROR = "LOAD_ERROR"
94 };
95
96 export function getAppStatus(appName: string): string | null;
97
98 export function unloadApplication(
99 appName: string,
100 opts?: { waitForUnmount: boolean }
101 ): Promise<any>;
102
103 export function checkActivityFunctions(location: Location): string[];
104 export function getAppNames(): string[];
105
106 // ./navigation/navigation-events.js'
107 export function navigateToUrl(
108 obj:
109 | string
110 | {
111 currentTarget: {
112 href: string;
113 };
114 preventDefault: any;
115 },
116 opts?: Object
117 ): void;
118
119 // './navigation/reroute.js'
120 export function triggerAppChange(): Promise<any>;
121
122 // './applications/app-errors.js'
123 type AppError = Error & {
124 appOrParcelName: string;
125 };
126 export function addErrorHandler(handler: (error: AppError) => void): void;
127 export function removeErrorHandler(handler: (error: AppError) => void): void;
128
129 // './parcels/mount-parcel.js'
130 export function mountRootParcel(
131 parcelConfig: ParcelConfig,
132 parcelProps: object
133 ): Parcel;
134}