@vnejs/module.controller.bg 0.2.2 → 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 +4 -5
- package/dist/index.js +13 -10
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.ts +24 -15
- package/src/types.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
-
import type { ModuleControllerBgConstants, ModuleControllerBgEvents, ModuleControllerBgParams, ModuleControllerBgSettings } from "./types.js";
|
|
2
|
+
import type { ModuleControllerBgConstants, ModuleControllerBgEvents, ModuleControllerBgParams, ModuleControllerBgSettings, ModuleControllerBgState } from "./types.js";
|
|
3
3
|
export type { ModuleControllerBgConstants, ModuleControllerBgEvents, ModuleControllerBgParams, ModuleControllerBgSettings, ModuleControllerBgState, } from "./types.js";
|
|
4
|
-
export declare abstract class ModuleControllerBg<TEvents extends ModuleControllerBgEvents = ModuleControllerBgEvents, TConstants extends ModuleControllerBgConstants = ModuleControllerBgConstants, TSettings extends ModuleControllerBgSettings = ModuleControllerBgSettings, TParams extends ModuleControllerBgParams = ModuleControllerBgParams, TState =
|
|
4
|
+
export declare abstract class ModuleControllerBg<TEvents extends ModuleControllerBgEvents = ModuleControllerBgEvents, TConstants extends ModuleControllerBgConstants = ModuleControllerBgConstants, TSettings extends ModuleControllerBgSettings = ModuleControllerBgSettings, TParams extends ModuleControllerBgParams = ModuleControllerBgParams, TState extends ModuleControllerBgState = ModuleControllerBgState> extends ModuleCore<TEvents, TConstants, TSettings, TParams, TState> {
|
|
5
5
|
abstract name: string;
|
|
6
6
|
abstract EVENT_SHOW: string;
|
|
7
7
|
abstract EVENT_HIDE: string;
|
|
8
|
-
abstract
|
|
9
|
-
abstract EVENT_STATE_UPDATE: string;
|
|
8
|
+
abstract EVENT_UPDATE_STATE: string;
|
|
10
9
|
abstract EVENT_UPDATE_FAST: string;
|
|
11
10
|
EVENT_PRELOAD?: string;
|
|
12
11
|
abstract BGNAME: string;
|
|
@@ -17,9 +16,9 @@ export declare abstract class ModuleControllerBg<TEvents extends ModuleControlle
|
|
|
17
16
|
IS_STATE_CLEAR_PRELOAD_ENABLED: boolean;
|
|
18
17
|
IS_MEMORY_CLEARED_PRELOAD_ENABLED: boolean;
|
|
19
18
|
IS_MEMORY_CLEARED_UPDATE_ENABLED: boolean;
|
|
20
|
-
isShow: boolean;
|
|
21
19
|
subscribe: () => void;
|
|
22
20
|
start: () => Promise<HTMLImageElement> | undefined;
|
|
21
|
+
getDefaultState: () => TState;
|
|
23
22
|
onShow: () => void;
|
|
24
23
|
onHide: () => void;
|
|
25
24
|
onShowBefore: () => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -7,11 +7,11 @@ export class ModuleControllerBg extends ModuleCore {
|
|
|
7
7
|
IS_STATE_CLEAR_PRELOAD_ENABLED = false;
|
|
8
8
|
IS_MEMORY_CLEARED_PRELOAD_ENABLED = false;
|
|
9
9
|
IS_MEMORY_CLEARED_UPDATE_ENABLED = false;
|
|
10
|
-
isShow = false;
|
|
11
10
|
subscribe = () => {
|
|
12
|
-
|
|
13
|
-
this.on(this.
|
|
14
|
-
this.on(this.
|
|
11
|
+
const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
12
|
+
this.on(this.EVENT_SHOW, this.onShowBefore, { priority: SHOW.BEFORE });
|
|
13
|
+
this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.MAIN });
|
|
14
|
+
this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.MAIN });
|
|
15
15
|
if (this.EVENT_PRELOAD)
|
|
16
16
|
this.on(this.EVENT_PRELOAD, this.loadBg);
|
|
17
17
|
this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
|
|
@@ -22,22 +22,25 @@ export class ModuleControllerBg extends ModuleCore {
|
|
|
22
22
|
if (this.IS_START_PRELOAD_ENABLED)
|
|
23
23
|
return this.loadBg();
|
|
24
24
|
};
|
|
25
|
+
getDefaultState = () => ({ isShow: false });
|
|
25
26
|
onShow = () => {
|
|
26
|
-
this.isShow
|
|
27
|
+
this.updateState({ isShow: true });
|
|
27
28
|
};
|
|
28
29
|
onHide = () => {
|
|
29
|
-
this.isShow
|
|
30
|
+
if (!this.state.isShow)
|
|
31
|
+
return;
|
|
32
|
+
this.updateState({ isShow: false });
|
|
30
33
|
};
|
|
31
34
|
onShowBefore = async () => {
|
|
32
35
|
const media = await this.loadBg();
|
|
33
|
-
await this.emit(this.
|
|
36
|
+
await this.emit(this.EVENT_UPDATE_STATE, { bgSrc: media.src });
|
|
34
37
|
};
|
|
35
38
|
onMemoryCleared = async () => {
|
|
36
|
-
if (this.IS_MEMORY_CLEARED_UPDATE_ENABLED && this.isShow) {
|
|
39
|
+
if (this.IS_MEMORY_CLEARED_UPDATE_ENABLED && this.state.isShow) {
|
|
37
40
|
const media = await this.loadBg();
|
|
38
|
-
if (!this.isShow)
|
|
41
|
+
if (!this.state.isShow)
|
|
39
42
|
return;
|
|
40
|
-
await this.emit(this.
|
|
43
|
+
await this.emit(this.EVENT_UPDATE_STATE, { bgSrc: media.src });
|
|
41
44
|
await this.emit(this.EVENT_UPDATE_FAST);
|
|
42
45
|
return;
|
|
43
46
|
}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ModuleCore } from "@vnejs/module.core";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
ModuleControllerBgConstants,
|
|
5
|
+
ModuleControllerBgEvents,
|
|
6
|
+
ModuleControllerBgParams,
|
|
7
|
+
ModuleControllerBgSettings,
|
|
8
|
+
ModuleControllerBgState,
|
|
9
|
+
} from "./types.js";
|
|
4
10
|
|
|
5
11
|
export type {
|
|
6
12
|
ModuleControllerBgConstants,
|
|
@@ -15,14 +21,13 @@ export abstract class ModuleControllerBg<
|
|
|
15
21
|
TConstants extends ModuleControllerBgConstants = ModuleControllerBgConstants,
|
|
16
22
|
TSettings extends ModuleControllerBgSettings = ModuleControllerBgSettings,
|
|
17
23
|
TParams extends ModuleControllerBgParams = ModuleControllerBgParams,
|
|
18
|
-
TState =
|
|
24
|
+
TState extends ModuleControllerBgState = ModuleControllerBgState,
|
|
19
25
|
> extends ModuleCore<TEvents, TConstants, TSettings, TParams, TState> {
|
|
20
26
|
abstract override name: string;
|
|
21
27
|
|
|
22
28
|
abstract EVENT_SHOW: string;
|
|
23
29
|
abstract EVENT_HIDE: string;
|
|
24
|
-
abstract
|
|
25
|
-
abstract EVENT_STATE_UPDATE: string;
|
|
30
|
+
abstract EVENT_UPDATE_STATE: string;
|
|
26
31
|
abstract EVENT_UPDATE_FAST: string;
|
|
27
32
|
EVENT_PRELOAD?: string;
|
|
28
33
|
|
|
@@ -37,12 +42,12 @@ export abstract class ModuleControllerBg<
|
|
|
37
42
|
IS_MEMORY_CLEARED_PRELOAD_ENABLED = false;
|
|
38
43
|
IS_MEMORY_CLEARED_UPDATE_ENABLED = false;
|
|
39
44
|
|
|
40
|
-
isShow = false;
|
|
41
|
-
|
|
42
45
|
subscribe = () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.on(this.
|
|
46
|
+
const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
47
|
+
|
|
48
|
+
this.on(this.EVENT_SHOW, this.onShowBefore, { priority: SHOW.BEFORE });
|
|
49
|
+
this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.MAIN });
|
|
50
|
+
this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.MAIN });
|
|
46
51
|
|
|
47
52
|
if (this.EVENT_PRELOAD) this.on(this.EVENT_PRELOAD, this.loadBg);
|
|
48
53
|
|
|
@@ -55,26 +60,30 @@ export abstract class ModuleControllerBg<
|
|
|
55
60
|
if (this.IS_START_PRELOAD_ENABLED) return this.loadBg();
|
|
56
61
|
};
|
|
57
62
|
|
|
63
|
+
getDefaultState = (): TState => ({ isShow: false }) as TState;
|
|
64
|
+
|
|
58
65
|
onShow = () => {
|
|
59
|
-
this.isShow
|
|
66
|
+
this.updateState({ isShow: true } as Partial<TState>);
|
|
60
67
|
};
|
|
61
68
|
|
|
62
69
|
onHide = () => {
|
|
63
|
-
this.isShow
|
|
70
|
+
if (!this.state.isShow) return;
|
|
71
|
+
|
|
72
|
+
this.updateState({ isShow: false } as Partial<TState>);
|
|
64
73
|
};
|
|
65
74
|
|
|
66
75
|
onShowBefore = async () => {
|
|
67
76
|
const media = await this.loadBg();
|
|
68
77
|
|
|
69
|
-
await this.emit(this.
|
|
78
|
+
await this.emit(this.EVENT_UPDATE_STATE, { bgSrc: media.src });
|
|
70
79
|
};
|
|
71
80
|
|
|
72
81
|
onMemoryCleared = async () => {
|
|
73
|
-
if (this.IS_MEMORY_CLEARED_UPDATE_ENABLED && this.isShow) {
|
|
82
|
+
if (this.IS_MEMORY_CLEARED_UPDATE_ENABLED && this.state.isShow) {
|
|
74
83
|
const media = await this.loadBg();
|
|
75
|
-
if (!this.isShow) return;
|
|
84
|
+
if (!this.state.isShow) return;
|
|
76
85
|
|
|
77
|
-
await this.emit(this.
|
|
86
|
+
await this.emit(this.EVENT_UPDATE_STATE, { bgSrc: media.src });
|
|
78
87
|
await this.emit(this.EVENT_UPDATE_FAST);
|
|
79
88
|
|
|
80
89
|
return;
|
package/src/types.ts
CHANGED