@micro-zoe/micro-app 1.0.0-alpha.6 → 1.0.0-alpha.9

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/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, MicroAppConfigType, Router, appName } from '@micro-app/types';
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?: boolean): appName[];
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,17 +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<void>;
35
- export function unmountAllApps(options?: unmountAppOptions): Promise<void>;
36
- export class MicroApp extends EventCenterForBaseApp implements MicroAppConfigType {
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;
54
+ lifeCycles?: lifeCyclesType;
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 {
37
64
  tagName: string;
38
65
  options: OptionsType;
39
- preFetch: typeof preFetch;
40
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;
41
74
  start(options?: OptionsType): void;
42
75
  }
43
- const _default: MicroApp;
44
- export default _default;
76
+ const microApp: MicroApp;
77
+ export default microApp;
45
78
  }
46
79
 
47
80
  declare module '@micro-zoe/micro-app/prefetch' {
@@ -51,18 +84,23 @@ declare module '@micro-zoe/micro-app/prefetch' {
51
84
  * {
52
85
  * name: string,
53
86
  * url: string,
54
- * disableScopecss?: boolean,
55
- * disableSandbox?: boolean,
56
- * disableMemoryRouter?: boolean,
87
+ * esmodule: boolean,
88
+ * inline: boolean,
89
+ * 'disable-scopecss': boolean,
90
+ * 'disable-sandbox': boolean,
91
+ * level: number,
92
+ * 'default-page': string,
93
+ * 'disable-patch-request': boolean,
57
94
  * },
58
95
  * ...
59
96
  * ])
60
97
  * Note:
61
- * 1: preFetch is asynchronous and is performed only when the browser is idle
62
- * 2: disableScopecss, disableSandbox, disableMemoryRouter must be same with micro-app element, if conflict, the one who executes first shall prevail
63
- * @param apps micro apps
98
+ * 1: preFetch is async and is performed only when the browser is idle
99
+ * 2: options of prefetch preferably match the config of the micro-app element, although this is not required
100
+ * @param apps micro app options
101
+ * @param delay delay time
64
102
  */
65
- export default function preFetch(apps: prefetchParamList): void;
103
+ export default function preFetch(apps: prefetchParamList, delay?: number): void;
66
104
  /**
67
105
  * load global assets into cache
68
106
  * @param assets global assets of js, css
@@ -91,14 +129,17 @@ declare module '@micro-zoe/micro-app/libs/utils' {
91
129
  export function isNull(target: unknown): target is null;
92
130
  export function isString(target: unknown): target is string;
93
131
  export function isBoolean(target: unknown): target is boolean;
132
+ export function isNumber(target: unknown): target is Number;
94
133
  export function isFunction(target: unknown): target is Function;
95
- export function isPlainObject(target: unknown): target is Record<PropertyKey, unknown>;
134
+ export function isPlainObject<T = Record<PropertyKey, unknown>>(target: unknown): target is T;
96
135
  export function isObject(target: unknown): target is Object;
97
136
  export function isPromise(target: unknown): target is Promise<unknown>;
98
137
  export function isBoundFunction(target: unknown): boolean;
99
138
  export function isConstructor(target: unknown): boolean;
100
139
  export function isShadowRoot(target: unknown): target is ShadowRoot;
101
140
  export function isURL(target: unknown): target is URL;
141
+ export function isElement(target: unknown): target is Element;
142
+ export function isNode(target: unknown): target is Node;
102
143
  export function isProxyDocument(target: unknown): target is Document;
103
144
  /**
104
145
  * format error log
@@ -252,6 +293,13 @@ declare module '@micro-zoe/micro-app/libs/utils' {
252
293
  * @param address source address
253
294
  */
254
295
  export function isInlineScript(address: string): boolean;
296
+ /**
297
+ * call function with try catch
298
+ * @param fn target function
299
+ * @param appName app.name
300
+ * @param args arguments
301
+ */
302
+ export function callFnWithTryCatch(fn: Func | null, appName: string, msgSuffix: string, ...args: unknown[]): void;
255
303
  }
256
304
 
257
305
  declare module '@micro-zoe/micro-app/interact' {
@@ -272,11 +320,16 @@ declare module '@micro-zoe/micro-app/interact' {
272
320
  * dispatch global data
273
321
  * @param data data
274
322
  */
275
- setGlobalData(data: Record<PropertyKey, unknown>): void;
323
+ setGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
324
+ forceSetGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
276
325
  /**
277
326
  * get global data
278
327
  */
279
328
  getGlobalData(): Record<PropertyKey, unknown> | null;
329
+ /**
330
+ * clear global data
331
+ */
332
+ clearGlobalData(): void;
280
333
  /**
281
334
  * clear all listener of global data
282
335
  * if appName exists, only the specified functions is cleared
@@ -309,7 +362,14 @@ declare module '@micro-zoe/micro-app/interact' {
309
362
  * @param appName app.name
310
363
  * @param data data
311
364
  */
312
- setData(appName: string, data: Record<PropertyKey, unknown>): void;
365
+ setData(appName: string, data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
366
+ forceSetData(appName: string, data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
367
+ /**
368
+ * clear data from base app
369
+ * @param appName app.name
370
+ * @param fromBaseApp whether clear data from child app, default is true
371
+ */
372
+ clearData(appName: string, fromBaseApp?: boolean): void;
313
373
  /**
314
374
  * clear all listener for specified micro app
315
375
  * @param appName app.name
@@ -337,12 +397,18 @@ declare module '@micro-zoe/micro-app/interact' {
337
397
  /**
338
398
  * get data from base app
339
399
  */
340
- getData(): Record<PropertyKey, unknown> | null;
400
+ getData(fromBaseApp?: boolean): Record<PropertyKey, unknown> | null;
341
401
  /**
342
402
  * dispatch data to base app
343
403
  * @param data data
344
404
  */
345
- dispatch(data: Record<PropertyKey, unknown>): void;
405
+ dispatch(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
406
+ forceDispatch(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
407
+ /**
408
+ * clear data from child app
409
+ * @param fromBaseApp whether clear data from base app, default is false
410
+ */
411
+ clearData(fromBaseApp?: boolean): void;
346
412
  /**
347
413
  * clear all listeners
348
414
  */