@micro-zoe/micro-app 1.0.0-alpha.5 → 1.0.0-alpha.8
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/README.md +0 -4
- package/README.zh-cn.md +1 -1
- package/lib/index.d.ts +101 -30
- package/lib/index.esm.js +1672 -639
- 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 +158 -90
package/README.md
CHANGED
|
@@ -35,10 +35,6 @@ It is the lowest cost framework for accessing micro front-end, and provides a se
|
|
|
35
35
|
micro-app has no restrictions on the front-end framework, and any framework can be used as a base application to embed any type of micro application of the framework.
|
|
36
36
|
|
|
37
37
|
# How to use
|
|
38
|
-
The micro front end is divided into a base application (also called main application) and a micro application.
|
|
39
|
-
|
|
40
|
-
Here is a common example: the base application uses the Vue framework, uses history routing, the micro application uses the react framework, and uses hash routing. We list the modifications that need to be made by the base application and the micro application, and introduce the use of micro-app in detail.
|
|
41
|
-
|
|
42
38
|
## base application
|
|
43
39
|
**1、Install**
|
|
44
40
|
```bash
|
package/README.zh-cn.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
[English](https://github.com/micro-zoe/micro-app)|简体中文|[官网文档](https://micro-zoe.github.io/micro-app/)|[讨论组](https://github.com/micro-zoe/micro-app/discussions)|[聊天室](https://gitter.im/microzoe/micro-app)
|
|
29
29
|
|
|
30
30
|
# 📖简介
|
|
31
|
-
micro-app是京东零售推出的一款微前端框架,它基于类WebComponent进行渲染,从组件化的思维实现微前端,旨在降低上手难度、提升工作效率。它是目前接入微前端成本最低的框架,并且提供了JS
|
|
31
|
+
micro-app是京东零售推出的一款微前端框架,它基于类WebComponent进行渲染,从组件化的思维实现微前端,旨在降低上手难度、提升工作效率。它是目前接入微前端成本最低的框架,并且提供了JS沙箱、样式隔离、元素隔离、预加载、虚拟路由系统、插件系统、数据通信等一系列完善的功能。
|
|
32
32
|
|
|
33
33
|
micro-app与技术栈无关,对前端框架没有限制,任何框架都可以作为基座应用嵌入任何类型的子应用。
|
|
34
34
|
|
package/lib/index.d.ts
CHANGED
|
@@ -4,26 +4,28 @@
|
|
|
4
4
|
// ../../@micro-app/types
|
|
5
5
|
|
|
6
6
|
declare module '@micro-zoe/micro-app' {
|
|
7
|
-
export { default, MicroApp, getActiveApps, getAllApps, unmountApp, unmountAllApps, } from '@micro-zoe/micro-app/micro_app';
|
|
7
|
+
export { default, MicroApp, getActiveApps, getAllApps, unmountApp, unmountAllApps, reload, renderApp, } from '@micro-zoe/micro-app/micro_app';
|
|
8
8
|
export { default as preFetch, } from '@micro-zoe/micro-app/prefetch';
|
|
9
9
|
export { removeDomScope, pureCreateElement, version, } from '@micro-zoe/micro-app/libs/utils';
|
|
10
10
|
export { EventCenterForMicroApp, } from '@micro-zoe/micro-app/interact';
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
declare module '@micro-zoe/micro-app/micro_app' {
|
|
14
|
-
import type { OptionsType,
|
|
14
|
+
import type { OptionsType, MicroAppBaseType, Router, AppName, Func, lifeCyclesType, MicroAppConfig, GetActiveAppsParam } from '@micro-app/types';
|
|
15
15
|
import preFetch from '@micro-zoe/micro-app/prefetch';
|
|
16
16
|
import { EventCenterForBaseApp } from '@micro-zoe/micro-app/interact';
|
|
17
17
|
/**
|
|
18
18
|
* if app not prefetch & not unmount, then app is active
|
|
19
19
|
* @param excludeHiddenApp exclude hidden keep-alive app, default is false
|
|
20
|
+
* @param excludePreRender exclude pre render app
|
|
20
21
|
* @returns active apps
|
|
21
22
|
*/
|
|
22
|
-
export function getActiveApps(excludeHiddenApp?:
|
|
23
|
+
export function getActiveApps({ excludeHiddenApp, excludePreRender, }?: GetActiveAppsParam): AppName[];
|
|
23
24
|
export function getAllApps(): string[];
|
|
24
25
|
type unmountAppOptions = {
|
|
25
26
|
destroy?: boolean;
|
|
26
27
|
clearAliveState?: boolean;
|
|
28
|
+
clearData?: boolean;
|
|
27
29
|
};
|
|
28
30
|
/**
|
|
29
31
|
* unmount app by appName
|
|
@@ -31,30 +33,48 @@ declare module '@micro-zoe/micro-app/micro_app' {
|
|
|
31
33
|
* @param options unmountAppOptions
|
|
32
34
|
* @returns Promise<void>
|
|
33
35
|
*/
|
|
34
|
-
export function unmountApp(appName: string, options?: unmountAppOptions): Promise<
|
|
35
|
-
export function unmountAllApps(options?: unmountAppOptions): Promise<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
export function unmountApp(appName: string, options?: unmountAppOptions): Promise<boolean>;
|
|
37
|
+
export function unmountAllApps(options?: unmountAppOptions): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Re render app from the command line
|
|
40
|
+
* microApp.reload(destroy)
|
|
41
|
+
* @param appName app.name
|
|
42
|
+
* @param destroy unmount app with destroy mode
|
|
43
|
+
* @returns Promise<boolean>
|
|
44
|
+
*/
|
|
45
|
+
export function reload(appName: string, destroy?: boolean): Promise<boolean>;
|
|
46
|
+
interface RenderAppOptions extends MicroAppConfig {
|
|
47
|
+
name: string;
|
|
48
|
+
url: string;
|
|
49
|
+
container: string | Element;
|
|
50
|
+
baseroute?: string;
|
|
51
|
+
'default-page'?: string;
|
|
52
|
+
data?: Record<PropertyKey, unknown>;
|
|
53
|
+
onDataChange?: Func;
|
|
49
54
|
lifeCycles?: lifeCyclesType;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Manually render app
|
|
59
|
+
* @param options RenderAppOptions
|
|
60
|
+
* @returns Promise<boolean>
|
|
61
|
+
*/
|
|
62
|
+
export function renderApp(options: RenderAppOptions): Promise<boolean>;
|
|
63
|
+
export class MicroApp extends EventCenterForBaseApp implements MicroAppBaseType {
|
|
64
|
+
tagName: string;
|
|
65
|
+
options: OptionsType;
|
|
53
66
|
router: Router;
|
|
67
|
+
preFetch: typeof preFetch;
|
|
68
|
+
unmountApp: typeof unmountApp;
|
|
69
|
+
unmountAllApps: typeof unmountAllApps;
|
|
70
|
+
getActiveApps: typeof getActiveApps;
|
|
71
|
+
getAllApps: typeof getAllApps;
|
|
72
|
+
reload: typeof reload;
|
|
73
|
+
renderApp: typeof renderApp;
|
|
54
74
|
start(options?: OptionsType): void;
|
|
55
75
|
}
|
|
56
|
-
const
|
|
57
|
-
export default
|
|
76
|
+
const microApp: MicroApp;
|
|
77
|
+
export default microApp;
|
|
58
78
|
}
|
|
59
79
|
|
|
60
80
|
declare module '@micro-zoe/micro-app/prefetch' {
|
|
@@ -75,7 +95,7 @@ declare module '@micro-zoe/micro-app/prefetch' {
|
|
|
75
95
|
* 2: disableScopecss, disableSandbox, disableMemoryRouter must be same with micro-app element, if conflict, the one who executes first shall prevail
|
|
76
96
|
* @param apps micro apps
|
|
77
97
|
*/
|
|
78
|
-
export default function preFetch(apps: prefetchParamList): void;
|
|
98
|
+
export default function preFetch(apps: prefetchParamList, delay?: number): void;
|
|
79
99
|
/**
|
|
80
100
|
* load global assets into cache
|
|
81
101
|
* @param assets global assets of js, css
|
|
@@ -84,7 +104,7 @@ declare module '@micro-zoe/micro-app/prefetch' {
|
|
|
84
104
|
}
|
|
85
105
|
|
|
86
106
|
declare module '@micro-zoe/micro-app/libs/utils' {
|
|
87
|
-
import type { Func, LocationQueryObject, MicroLocation } from '@micro-app/types';
|
|
107
|
+
import type { Func, LocationQueryObject, MicroLocation, AttrsType, fiberTasks } from '@micro-app/types';
|
|
88
108
|
export const version = "__MICRO_APP_VERSION__";
|
|
89
109
|
export const isBrowser: boolean;
|
|
90
110
|
export const globalThis: any;
|
|
@@ -104,14 +124,17 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
104
124
|
export function isNull(target: unknown): target is null;
|
|
105
125
|
export function isString(target: unknown): target is string;
|
|
106
126
|
export function isBoolean(target: unknown): target is boolean;
|
|
127
|
+
export function isNumber(target: unknown): target is Number;
|
|
107
128
|
export function isFunction(target: unknown): target is Function;
|
|
108
|
-
export function isPlainObject(target: unknown): target is
|
|
129
|
+
export function isPlainObject<T = Record<PropertyKey, unknown>>(target: unknown): target is T;
|
|
109
130
|
export function isObject(target: unknown): target is Object;
|
|
110
131
|
export function isPromise(target: unknown): target is Promise<unknown>;
|
|
111
132
|
export function isBoundFunction(target: unknown): boolean;
|
|
112
133
|
export function isConstructor(target: unknown): boolean;
|
|
113
134
|
export function isShadowRoot(target: unknown): target is ShadowRoot;
|
|
114
135
|
export function isURL(target: unknown): target is URL;
|
|
136
|
+
export function isElement(target: unknown): target is Element;
|
|
137
|
+
export function isNode(target: unknown): target is Node;
|
|
115
138
|
export function isProxyDocument(target: unknown): target is Document;
|
|
116
139
|
/**
|
|
117
140
|
* format error log
|
|
@@ -187,6 +210,11 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
187
210
|
export function createNonceSrc(): string;
|
|
188
211
|
export function unique(array: any[]): any[];
|
|
189
212
|
export const requestIdleCallback: any;
|
|
213
|
+
/**
|
|
214
|
+
* Wrap requestIdleCallback with promise
|
|
215
|
+
* Exec callback when browser idle
|
|
216
|
+
*/
|
|
217
|
+
export function promiseRequestIdle(callback: CallableFunction): Promise<void>;
|
|
190
218
|
export function setCurrentAppName(appName: string | null): void;
|
|
191
219
|
export function throttleDeferForSetAppName(appName: string): void;
|
|
192
220
|
export function getCurrentAppName(): string | null;
|
|
@@ -242,6 +270,31 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
242
270
|
get: (key: PropertyKey) => T | undefined;
|
|
243
271
|
delete: (key: PropertyKey) => boolean;
|
|
244
272
|
};
|
|
273
|
+
export function getAttributes(element: Element): AttrsType;
|
|
274
|
+
/**
|
|
275
|
+
* if fiberTasks exist, wrap callback with promiseRequestIdle
|
|
276
|
+
* if not, execute callback
|
|
277
|
+
* @param fiberTasks fiber task list
|
|
278
|
+
* @param callback action callback
|
|
279
|
+
*/
|
|
280
|
+
export function injectFiberTask(fiberTasks: fiberTasks, callback: CallableFunction): void;
|
|
281
|
+
/**
|
|
282
|
+
* serial exec fiber task of link, style, script
|
|
283
|
+
* @param tasks task array or null
|
|
284
|
+
*/
|
|
285
|
+
export function serialExecFiberTasks(tasks: fiberTasks): Promise<void> | null;
|
|
286
|
+
/**
|
|
287
|
+
* inline script start with inline-xxx
|
|
288
|
+
* @param address source address
|
|
289
|
+
*/
|
|
290
|
+
export function isInlineScript(address: string): boolean;
|
|
291
|
+
/**
|
|
292
|
+
* call function with try catch
|
|
293
|
+
* @param fn target function
|
|
294
|
+
* @param appName app.name
|
|
295
|
+
* @param args arguments
|
|
296
|
+
*/
|
|
297
|
+
export function callFnWithTryCatch(fn: Func | null, appName: string, msgSuffix: string, ...args: unknown[]): void;
|
|
245
298
|
}
|
|
246
299
|
|
|
247
300
|
declare module '@micro-zoe/micro-app/interact' {
|
|
@@ -262,11 +315,16 @@ declare module '@micro-zoe/micro-app/interact' {
|
|
|
262
315
|
* dispatch global data
|
|
263
316
|
* @param data data
|
|
264
317
|
*/
|
|
265
|
-
setGlobalData(data: Record<PropertyKey, unknown
|
|
318
|
+
setGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
|
|
319
|
+
forceSetGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
|
|
266
320
|
/**
|
|
267
321
|
* get global data
|
|
268
322
|
*/
|
|
269
323
|
getGlobalData(): Record<PropertyKey, unknown> | null;
|
|
324
|
+
/**
|
|
325
|
+
* clear global data
|
|
326
|
+
*/
|
|
327
|
+
clearGlobalData(): void;
|
|
270
328
|
/**
|
|
271
329
|
* clear all listener of global data
|
|
272
330
|
* if appName exists, only the specified functions is cleared
|
|
@@ -299,7 +357,14 @@ declare module '@micro-zoe/micro-app/interact' {
|
|
|
299
357
|
* @param appName app.name
|
|
300
358
|
* @param data data
|
|
301
359
|
*/
|
|
302
|
-
setData(appName: string, data: Record<PropertyKey, unknown
|
|
360
|
+
setData(appName: string, data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
|
|
361
|
+
forceSetData(appName: string, data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
|
|
362
|
+
/**
|
|
363
|
+
* clear data from base app
|
|
364
|
+
* @param appName app.name
|
|
365
|
+
* @param fromBaseApp whether clear data from child app, default is true
|
|
366
|
+
*/
|
|
367
|
+
clearData(appName: string, fromBaseApp?: boolean): void;
|
|
303
368
|
/**
|
|
304
369
|
* clear all listener for specified micro app
|
|
305
370
|
* @param appName app.name
|
|
@@ -327,12 +392,18 @@ declare module '@micro-zoe/micro-app/interact' {
|
|
|
327
392
|
/**
|
|
328
393
|
* get data from base app
|
|
329
394
|
*/
|
|
330
|
-
getData(): Record<PropertyKey, unknown> | null;
|
|
395
|
+
getData(fromBaseApp?: boolean): Record<PropertyKey, unknown> | null;
|
|
331
396
|
/**
|
|
332
397
|
* dispatch data to base app
|
|
333
398
|
* @param data data
|
|
334
399
|
*/
|
|
335
|
-
dispatch(data: Record<PropertyKey, unknown
|
|
400
|
+
dispatch(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
|
|
401
|
+
forceDispatch(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
|
|
402
|
+
/**
|
|
403
|
+
* clear data from child app
|
|
404
|
+
* @param fromBaseApp whether clear data from base app, default is false
|
|
405
|
+
*/
|
|
406
|
+
clearData(fromBaseApp?: boolean): void;
|
|
336
407
|
/**
|
|
337
408
|
* clear all listeners
|
|
338
409
|
*/
|