-
Notifications
You must be signed in to change notification settings - Fork 2k
/
interfaces.ts
147 lines (129 loc) · 4.39 KB
/
interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* @author kuitos
* @since 2019-05-16
*/
import type { ImportEntryOpts } from 'import-html-entry';
import type { RegisterApplicationConfig, StartOpts, Parcel } from 'single-spa';
declare global {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Window {
__POWERED_BY_QIANKUN__?: boolean;
__INJECTED_PUBLIC_PATH_BY_QIANKUN__?: string;
__QIANKUN_DEVELOPMENT__?: boolean;
Zone?: CallableFunction;
__zone_symbol__setTimeout?: Window['setTimeout'];
}
}
export type ObjectType = Record<string, any>;
export type Entry =
| string
| {
scripts?: string[];
styles?: string[];
html?: string;
};
export type HTMLContentRender = (props: { appContent: string; loading: boolean }) => any;
export type AppMetadata = {
// app name
name: string;
// app entry
entry: Entry;
};
// just for manual loaded apps, in single-spa it called parcel
export type LoadableApp<T extends ObjectType> = AppMetadata & {
/* props pass through to app */ props?: T;
} & (
| {
// legacy mode, the render function all handled by user
render: HTMLContentRender;
}
| {
// where the app mount to, mutual exclusive with the legacy custom render function
container: string | HTMLElement;
}
);
// for the route-based apps
export type RegistrableApp<T extends ObjectType> = LoadableApp<T> & {
loader?: (loading: boolean) => void;
activeRule: RegisterApplicationConfig['activeWhen'];
};
export type PrefetchStrategy =
| boolean
| 'all'
| string[]
| ((apps: AppMetadata[]) => { criticalAppNames: string[]; minorAppsName: string[] });
type QiankunSpecialOpts = {
/**
* @deprecated internal api, don't used it as normal, might be removed after next version
*/
$$cacheLifecycleByAppName?: boolean;
prefetch?: PrefetchStrategy;
sandbox?:
| boolean
| {
strictStyleIsolation?: boolean;
experimentalStyleIsolation?: boolean;
/**
* @deprecated We use strict mode by default
*/
loose?: boolean;
/**
* use speed sandbox mode, enabled by default from 2.9.0
*/
speedy?: boolean;
patchers?: Patcher[];
};
/*
with singular mode, any app will wait to load until other apps are unmouting
it is useful for the scenario that only one sub app shown at one time
*/
singular?: boolean | ((app: LoadableApp<any>) => Promise<boolean>);
/**
* skip some scripts or links intercept, like JSONP
*/
excludeAssetFilter?: (url: string) => boolean;
globalContext?: typeof window;
};
export type FrameworkConfiguration = QiankunSpecialOpts & ImportEntryOpts & StartOpts;
export type LifeCycleFn<T extends ObjectType> = (app: LoadableApp<T>, global: typeof window) => Promise<any>;
export type FrameworkLifeCycles<T extends ObjectType> = {
beforeLoad?: LifeCycleFn<T> | Array<LifeCycleFn<T>>; // function before app load
beforeMount?: LifeCycleFn<T> | Array<LifeCycleFn<T>>; // function before app mount
afterMount?: LifeCycleFn<T> | Array<LifeCycleFn<T>>; // function after app mount
beforeUnmount?: LifeCycleFn<T> | Array<LifeCycleFn<T>>; // function before app unmount
afterUnmount?: LifeCycleFn<T> | Array<LifeCycleFn<T>>; // function after app unmount
};
export type MicroApp = Parcel;
export type Rebuilder = () => void;
export type Freer = () => Rebuilder;
export type Patcher = () => Freer;
export enum SandBoxType {
Proxy = 'Proxy',
Snapshot = 'Snapshot',
// for legacy sandbox
// https://github.com/umijs/qiankun/blob/0d1d3f0c5ed1642f01854f96c3fabf0a2148bd26/src/sandbox/legacy/sandbox.ts#L22...L25
LegacyProxy = 'LegacyProxy',
}
export type SandBox = {
/** 沙箱的名字 */
name: string;
/** 沙箱的类型 */
type: SandBoxType;
/** 沙箱导出的代理实体 */
proxy: WindowProxy;
/** 沙箱是否在运行中 */
sandboxRunning: boolean;
/** latest set property */
latestSetProp?: PropertyKey | null;
patchDocument: (doc: Document) => void;
/** 启动沙箱 */
active: () => void;
/** 关闭沙箱 */
inactive: () => void;
};
export type OnGlobalStateChangeCallback = (state: Record<string, any>, prevState: Record<string, any>) => void;
export type MicroAppStateActions = {
onGlobalStateChange: (callback: OnGlobalStateChangeCallback, fireImmediately?: boolean) => void;
setGlobalState: (state: Record<string, any>) => boolean;
offGlobalStateChange: () => boolean;
};