@micro-zoe/micro-app 1.0.0-alpha.6 → 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/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, MicroAppConfigType, Router, appName } from '@micro-app/types';
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): appName[];
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,17 +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<void>;
35
- export function unmountAllApps(options?: unmountAppOptions): Promise<void>;
36
- export class MicroApp extends EventCenterForBaseApp implements MicroAppConfigType {
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;
53
+ lifeCycles?: lifeCyclesType;
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 {
37
63
  tagName: string;
38
64
  options: OptionsType;
39
- preFetch: typeof preFetch;
40
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;
41
73
  start(options?: OptionsType): void;
42
74
  }
43
- const _default: MicroApp;
44
- export default _default;
75
+ const microApp: MicroApp;
76
+ export default microApp;
45
77
  }
46
78
 
47
79
  declare module '@micro-zoe/micro-app/prefetch' {
@@ -92,13 +124,15 @@ declare module '@micro-zoe/micro-app/libs/utils' {
92
124
  export function isString(target: unknown): target is string;
93
125
  export function isBoolean(target: unknown): target is boolean;
94
126
  export function isFunction(target: unknown): target is Function;
95
- export function isPlainObject(target: unknown): target is Record<PropertyKey, unknown>;
127
+ export function isPlainObject<T = Record<PropertyKey, unknown>>(target: unknown): target is T;
96
128
  export function isObject(target: unknown): target is Object;
97
129
  export function isPromise(target: unknown): target is Promise<unknown>;
98
130
  export function isBoundFunction(target: unknown): boolean;
99
131
  export function isConstructor(target: unknown): boolean;
100
132
  export function isShadowRoot(target: unknown): target is ShadowRoot;
101
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;
102
136
  export function isProxyDocument(target: unknown): target is Document;
103
137
  /**
104
138
  * format error log
@@ -252,6 +286,13 @@ declare module '@micro-zoe/micro-app/libs/utils' {
252
286
  * @param address source address
253
287
  */
254
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;
255
296
  }
256
297
 
257
298
  declare module '@micro-zoe/micro-app/interact' {
@@ -272,11 +313,16 @@ declare module '@micro-zoe/micro-app/interact' {
272
313
  * dispatch global data
273
314
  * @param data data
274
315
  */
275
- setGlobalData(data: Record<PropertyKey, unknown>): void;
316
+ setGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction, force?: boolean): void;
317
+ forceSetGlobalData(data: Record<PropertyKey, unknown>, nextStep?: CallableFunction): void;
276
318
  /**
277
319
  * get global data
278
320
  */
279
321
  getGlobalData(): Record<PropertyKey, unknown> | null;
322
+ /**
323
+ * clear global data
324
+ */
325
+ clearGlobalData(): void;
280
326
  /**
281
327
  * clear all listener of global data
282
328
  * if appName exists, only the specified functions is cleared
@@ -309,7 +355,14 @@ declare module '@micro-zoe/micro-app/interact' {
309
355
  * @param appName app.name
310
356
  * @param data data
311
357
  */
312
- setData(appName: string, data: Record<PropertyKey, unknown>): void;
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;
313
366
  /**
314
367
  * clear all listener for specified micro app
315
368
  * @param appName app.name
@@ -337,12 +390,18 @@ declare module '@micro-zoe/micro-app/interact' {
337
390
  /**
338
391
  * get data from base app
339
392
  */
340
- getData(): Record<PropertyKey, unknown> | null;
393
+ getData(fromBaseApp?: boolean): Record<PropertyKey, unknown> | null;
341
394
  /**
342
395
  * dispatch data to base app
343
396
  * @param data data
344
397
  */
345
- dispatch(data: Record<PropertyKey, unknown>): void;
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;
346
405
  /**
347
406
  * clear all listeners
348
407
  */