@micro-zoe/micro-app 1.0.0-alpha.4 → 1.0.0-alpha.7
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 +98 -29
- package/lib/index.esm.js +1316 -521
- 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 +120 -84
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,14 +4,14 @@
|
|
|
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 } 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
|
/**
|
|
@@ -19,11 +19,12 @@ declare module '@micro-zoe/micro-app/micro_app' {
|
|
|
19
19
|
* @param excludeHiddenApp exclude hidden keep-alive app, default is false
|
|
20
20
|
* @returns active apps
|
|
21
21
|
*/
|
|
22
|
-
export function getActiveApps(excludeHiddenApp?: boolean):
|
|
22
|
+
export function getActiveApps(excludeHiddenApp?: boolean): AppName[];
|
|
23
23
|
export function getAllApps(): string[];
|
|
24
24
|
type unmountAppOptions = {
|
|
25
25
|
destroy?: boolean;
|
|
26
26
|
clearAliveState?: boolean;
|
|
27
|
+
clearData?: boolean;
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* unmount app by appName
|
|
@@ -31,30 +32,48 @@ declare module '@micro-zoe/micro-app/micro_app' {
|
|
|
31
32
|
* @param options unmountAppOptions
|
|
32
33
|
* @returns Promise<void>
|
|
33
34
|
*/
|
|
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
|
-
|
|
35
|
+
export function unmountApp(appName: string, options?: unmountAppOptions): Promise<boolean>;
|
|
36
|
+
export function unmountAllApps(options?: unmountAppOptions): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Re render app from the command line
|
|
39
|
+
* microApp.reload(destroy)
|
|
40
|
+
* @param appName app.name
|
|
41
|
+
* @param destroy unmount app with destroy mode
|
|
42
|
+
* @returns Promise<boolean>
|
|
43
|
+
*/
|
|
44
|
+
export function reload(appName: string, destroy?: boolean): Promise<boolean>;
|
|
45
|
+
interface RenderAppOptions extends MicroAppConfig {
|
|
46
|
+
name: string;
|
|
47
|
+
url: string;
|
|
48
|
+
container: string | Element;
|
|
49
|
+
baseroute?: string;
|
|
50
|
+
'default-page'?: string;
|
|
51
|
+
data?: Record<PropertyKey, unknown>;
|
|
52
|
+
onDataChange?: Func;
|
|
49
53
|
lifeCycles?: lifeCyclesType;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Manually render app
|
|
58
|
+
* @param options RenderAppOptions
|
|
59
|
+
* @returns Promise<boolean>
|
|
60
|
+
*/
|
|
61
|
+
export function renderApp(options: RenderAppOptions): Promise<boolean>;
|
|
62
|
+
export class MicroApp extends EventCenterForBaseApp implements MicroAppBaseType {
|
|
63
|
+
tagName: string;
|
|
64
|
+
options: OptionsType;
|
|
53
65
|
router: Router;
|
|
66
|
+
preFetch: typeof preFetch;
|
|
67
|
+
unmountApp: typeof unmountApp;
|
|
68
|
+
unmountAllApps: typeof unmountAllApps;
|
|
69
|
+
getActiveApps: typeof getActiveApps;
|
|
70
|
+
getAllApps: typeof getAllApps;
|
|
71
|
+
reload: typeof reload;
|
|
72
|
+
renderApp: typeof renderApp;
|
|
54
73
|
start(options?: OptionsType): void;
|
|
55
74
|
}
|
|
56
|
-
const
|
|
57
|
-
export default
|
|
75
|
+
const microApp: MicroApp;
|
|
76
|
+
export default microApp;
|
|
58
77
|
}
|
|
59
78
|
|
|
60
79
|
declare module '@micro-zoe/micro-app/prefetch' {
|
|
@@ -84,7 +103,7 @@ declare module '@micro-zoe/micro-app/prefetch' {
|
|
|
84
103
|
}
|
|
85
104
|
|
|
86
105
|
declare module '@micro-zoe/micro-app/libs/utils' {
|
|
87
|
-
import type { Func, LocationQueryObject, MicroLocation } from '@micro-app/types';
|
|
106
|
+
import type { Func, LocationQueryObject, MicroLocation, AttrsType, fiberTasks } from '@micro-app/types';
|
|
88
107
|
export const version = "__MICRO_APP_VERSION__";
|
|
89
108
|
export const isBrowser: boolean;
|
|
90
109
|
export const globalThis: any;
|
|
@@ -105,13 +124,15 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
105
124
|
export function isString(target: unknown): target is string;
|
|
106
125
|
export function isBoolean(target: unknown): target is boolean;
|
|
107
126
|
export function isFunction(target: unknown): target is Function;
|
|
108
|
-
export function isPlainObject(target: unknown): target is
|
|
127
|
+
export function isPlainObject<T = Record<PropertyKey, unknown>>(target: unknown): target is T;
|
|
109
128
|
export function isObject(target: unknown): target is Object;
|
|
110
129
|
export function isPromise(target: unknown): target is Promise<unknown>;
|
|
111
130
|
export function isBoundFunction(target: unknown): boolean;
|
|
112
131
|
export function isConstructor(target: unknown): boolean;
|
|
113
132
|
export function isShadowRoot(target: unknown): target is ShadowRoot;
|
|
114
133
|
export function isURL(target: unknown): target is URL;
|
|
134
|
+
export function isElement(target: unknown): target is Element;
|
|
135
|
+
export function isNode(target: unknown): target is Node;
|
|
115
136
|
export function isProxyDocument(target: unknown): target is Document;
|
|
116
137
|
/**
|
|
117
138
|
* format error log
|
|
@@ -187,6 +208,11 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
187
208
|
export function createNonceSrc(): string;
|
|
188
209
|
export function unique(array: any[]): any[];
|
|
189
210
|
export const requestIdleCallback: any;
|
|
211
|
+
/**
|
|
212
|
+
* Wrap requestIdleCallback with promise
|
|
213
|
+
* Exec callback when browser idle
|
|
214
|
+
*/
|
|
215
|
+
export function promiseRequestIdle(callback: CallableFunction): Promise<void>;
|
|
190
216
|
export function setCurrentAppName(appName: string | null): void;
|
|
191
217
|
export function throttleDeferForSetAppName(appName: string): void;
|
|
192
218
|
export function getCurrentAppName(): string | null;
|
|
@@ -242,6 +268,31 @@ declare module '@micro-zoe/micro-app/libs/utils' {
|
|
|
242
268
|
get: (key: PropertyKey) => T | undefined;
|
|
243
269
|
delete: (key: PropertyKey) => boolean;
|
|
244
270
|
};
|
|
271
|
+
export function getAttributes(element: Element): AttrsType;
|
|
272
|
+
/**
|
|
273
|
+
* if fiberTasks exist, wrap callback with promiseRequestIdle
|
|
274
|
+
* if not, execute callback
|
|
275
|
+
* @param fiberTasks fiber task list
|
|
276
|
+
* @param callback action callback
|
|
277
|
+
*/
|
|
278
|
+
export function injectFiberTask(fiberTasks: fiberTasks, callback: CallableFunction): void;
|
|
279
|
+
/**
|
|
280
|
+
* serial exec fiber task of link, style, script
|
|
281
|
+
* @param tasks task array or null
|
|
282
|
+
*/
|
|
283
|
+
export function serialExecFiberTasks(tasks: fiberTasks): Promise<void> | null;
|
|
284
|
+
/**
|
|
285
|
+
* inline script start with inline-xxx
|
|
286
|
+
* @param address source address
|
|
287
|
+
*/
|
|
288
|
+
export function isInlineScript(address: string): boolean;
|
|
289
|
+
/**
|
|
290
|
+
* call function with try catch
|
|
291
|
+
* @param fn target function
|
|
292
|
+
* @param appName app.name
|
|
293
|
+
* @param args arguments
|
|
294
|
+
*/
|
|
295
|
+
export function callFnWithTryCatch(fn: Func | null, appName: string, msgSuffix: string, ...args: unknown[]): void;
|
|
245
296
|
}
|
|
246
297
|
|
|
247
298
|
declare module '@micro-zoe/micro-app/interact' {
|
|
@@ -262,11 +313,16 @@ declare module '@micro-zoe/micro-app/interact' {
|
|
|
262
313
|
* dispatch global data
|
|
263
314
|
* @param data data
|
|
264
315
|
*/
|
|
265
|
-
setGlobalData(data: Record<PropertyKey, unknown
|
|
316
|
+
setGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
|
|
317
|
+
forceSetGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
|
|
266
318
|
/**
|
|
267
319
|
* get global data
|
|
268
320
|
*/
|
|
269
321
|
getGlobalData(): Record<PropertyKey, unknown> | null;
|
|
322
|
+
/**
|
|
323
|
+
* clear global data
|
|
324
|
+
*/
|
|
325
|
+
clearGlobalData(): void;
|
|
270
326
|
/**
|
|
271
327
|
* clear all listener of global data
|
|
272
328
|
* if appName exists, only the specified functions is cleared
|
|
@@ -299,7 +355,14 @@ declare module '@micro-zoe/micro-app/interact' {
|
|
|
299
355
|
* @param appName app.name
|
|
300
356
|
* @param data data
|
|
301
357
|
*/
|
|
302
|
-
setData(appName: string, data: Record<PropertyKey, unknown
|
|
358
|
+
setData(appName: string, data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
|
|
359
|
+
forceSetData(appName: string, data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
|
|
360
|
+
/**
|
|
361
|
+
* clear data from base app
|
|
362
|
+
* @param appName app.name
|
|
363
|
+
* @param fromBaseApp whether clear data from child app, default is true
|
|
364
|
+
*/
|
|
365
|
+
clearData(appName: string, fromBaseApp?: boolean): void;
|
|
303
366
|
/**
|
|
304
367
|
* clear all listener for specified micro app
|
|
305
368
|
* @param appName app.name
|
|
@@ -327,12 +390,18 @@ declare module '@micro-zoe/micro-app/interact' {
|
|
|
327
390
|
/**
|
|
328
391
|
* get data from base app
|
|
329
392
|
*/
|
|
330
|
-
getData(): Record<PropertyKey, unknown> | null;
|
|
393
|
+
getData(fromBaseApp?: boolean): Record<PropertyKey, unknown> | null;
|
|
331
394
|
/**
|
|
332
395
|
* dispatch data to base app
|
|
333
396
|
* @param data data
|
|
334
397
|
*/
|
|
335
|
-
dispatch(data: Record<PropertyKey, unknown
|
|
398
|
+
dispatch(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
|
|
399
|
+
forceDispatch(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
|
|
400
|
+
/**
|
|
401
|
+
* clear data from child app
|
|
402
|
+
* @param fromBaseApp whether clear data from base app, default is false
|
|
403
|
+
*/
|
|
404
|
+
clearData(fromBaseApp?: boolean): void;
|
|
336
405
|
/**
|
|
337
406
|
* clear all listeners
|
|
338
407
|
*/
|