@vnejs/module.controller.preload 0.2.3 → 0.2.4

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/dist/index.d.ts CHANGED
@@ -6,12 +6,12 @@ export declare abstract class ModuleControllerPreload<TEvents extends ModuleCont
6
6
  abstract EVENT_SHOW: string;
7
7
  abstract EVENT_HIDE: string;
8
8
  abstract EVENT_PRELOAD: string;
9
+ abstract EVENT_UPDATE_STATE: string;
9
10
  PRELOAD_LABELS: string[];
10
11
  PRELOAD_EVENTS: string[];
11
12
  subscribe: () => void;
12
13
  getDefaultState: () => TState;
13
14
  onShow: () => Promise<import("@vnejs/shared").EmitResults<string>> | undefined;
14
- onHide: () => void;
15
15
  onPreload: () => Promise<(import("@vnejs/shared").EmitResults<string> | import("@vnejs/shared").EmitResults<"vne:scenario:label_get"> | undefined)[]>;
16
16
  onMemoryCleared: () => false | undefined;
17
17
  emitLabelGet: (label: string) => Promise<import("@vnejs/shared").EmitResults<"vne:scenario:label_get">> | undefined;
package/dist/index.js CHANGED
@@ -3,22 +3,14 @@ export class ModuleControllerPreload extends ModuleCore {
3
3
  PRELOAD_LABELS = [];
4
4
  PRELOAD_EVENTS = [];
5
5
  subscribe = () => {
6
- const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
6
+ const { SHOW } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
7
7
  this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.BEFORE });
8
- this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.MAIN });
9
8
  this.on(this.EVENT_PRELOAD, this.onPreload);
9
+ this.on(this.EVENT_UPDATE_STATE, this.updateState);
10
10
  this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
11
11
  };
12
12
  getDefaultState = () => ({ isShow: false });
13
- onShow = () => {
14
- this.updateState({ isShow: true });
15
- return this.emit(this.EVENT_PRELOAD);
16
- };
17
- onHide = () => {
18
- if (!this.state.isShow)
19
- return;
20
- this.updateState({ isShow: false });
21
- };
13
+ onShow = () => this.emit(this.EVENT_PRELOAD);
22
14
  onPreload = () => Promise.all([...this.PRELOAD_LABELS.map(this.emitLabelGet), ...this.PRELOAD_EVENTS.map(this.emitEvent)]);
23
15
  onMemoryCleared = () => this.state.isShow && void this.emit(this.EVENT_PRELOAD);
24
16
  emitLabelGet = (label) => this.emit(this.EVENTS.SCENARIO.LABEL_GET, { label });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/module.controller.preload",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -28,32 +28,24 @@ export abstract class ModuleControllerPreload<
28
28
  abstract EVENT_SHOW: string;
29
29
  abstract EVENT_HIDE: string;
30
30
  abstract EVENT_PRELOAD: string;
31
+ abstract EVENT_UPDATE_STATE: string;
31
32
 
32
33
  PRELOAD_LABELS: string[] = [];
33
34
  PRELOAD_EVENTS: string[] = [];
34
35
 
35
36
  subscribe = () => {
36
- const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
37
+ const { SHOW } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
37
38
 
38
39
  this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.BEFORE });
39
- this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.MAIN });
40
40
  this.on(this.EVENT_PRELOAD, this.onPreload);
41
+ this.on(this.EVENT_UPDATE_STATE, this.updateState);
41
42
 
42
43
  this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
43
44
  };
44
45
 
45
46
  getDefaultState = (): TState => ({ isShow: false }) as TState;
46
47
 
47
- onShow = () => {
48
- this.updateState({ isShow: true } as Partial<TState>);
49
-
50
- return this.emit(this.EVENT_PRELOAD);
51
- };
52
- onHide = () => {
53
- if (!this.state.isShow) return;
54
-
55
- this.updateState({ isShow: false } as Partial<TState>);
56
- };
48
+ onShow = () => this.emit(this.EVENT_PRELOAD);
57
49
 
58
50
  onPreload = () => Promise.all([...this.PRELOAD_LABELS.map(this.emitLabelGet), ...this.PRELOAD_EVENTS.map(this.emitEvent)]);
59
51
  onMemoryCleared = () => this.state.isShow && void this.emit(this.EVENT_PRELOAD);