@vnejs/module.controller.preload 0.2.1

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.
@@ -0,0 +1,19 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { ModuleControllerPreloadConstants, ModuleControllerPreloadEvents, ModuleControllerPreloadParams, ModuleControllerPreloadSettings } from "./types.js";
3
+ export type { ModuleControllerPreloadConstants, ModuleControllerPreloadEvents, ModuleControllerPreloadParams, ModuleControllerPreloadSettings, } from "./types.js";
4
+ export declare abstract class ModuleControllerPreload<TEvents extends ModuleControllerPreloadEvents = ModuleControllerPreloadEvents, TConstants extends ModuleControllerPreloadConstants = ModuleControllerPreloadConstants, TSettings extends ModuleControllerPreloadSettings = ModuleControllerPreloadSettings, TParams extends ModuleControllerPreloadParams = ModuleControllerPreloadParams, TState = unknown> extends ModuleCore<TEvents, TConstants, TSettings, TParams, TState> {
5
+ abstract name: string;
6
+ abstract EVENT_SHOW: string;
7
+ abstract EVENT_HIDE: string;
8
+ abstract EVENT_PRELOAD: string;
9
+ isShow: boolean;
10
+ PRELOAD_LABELS: string[];
11
+ PRELOAD_EVENTS: string[];
12
+ subscribe: () => void;
13
+ onShow: () => Promise<unknown[]> | undefined;
14
+ onHide: () => void;
15
+ onPreload: () => Promise<(unknown[] | undefined)[]>;
16
+ onMemoryCleared: () => false | undefined;
17
+ emitLabelGet: (label: string) => Promise<unknown[]> | undefined;
18
+ emitEvent: (event: string) => Promise<unknown[]> | undefined;
19
+ }
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class ModuleControllerPreload extends ModuleCore {
3
+ isShow = false;
4
+ PRELOAD_LABELS = [];
5
+ PRELOAD_EVENTS = [];
6
+ subscribe = () => {
7
+ this.on(this.EVENT_SHOW, this.onShow);
8
+ this.on(this.EVENT_HIDE, this.onHide);
9
+ this.on(this.EVENT_PRELOAD, this.onPreload);
10
+ this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
11
+ };
12
+ onShow = () => {
13
+ this.isShow = true;
14
+ return this.emit(this.EVENT_PRELOAD);
15
+ };
16
+ onHide = () => {
17
+ this.isShow = false;
18
+ };
19
+ onPreload = () => Promise.all([...this.PRELOAD_LABELS.map(this.emitLabelGet), ...this.PRELOAD_EVENTS.map(this.emitEvent)]);
20
+ onMemoryCleared = () => this.isShow && void this.emit(this.EVENT_PRELOAD);
21
+ emitLabelGet = (label) => this.emit(this.EVENTS.SCENARIO.LABEL_GET, { label });
22
+ emitEvent = (event) => this.emit(event);
23
+ }
@@ -0,0 +1,5 @@
1
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
+ export type ModuleControllerPreloadEvents = ModuleCoreEvents;
3
+ export type ModuleControllerPreloadConstants = ModuleCoreConstants;
4
+ export type ModuleControllerPreloadSettings = ModuleCoreSettings;
5
+ export type ModuleControllerPreloadParams = ModuleCoreParams;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@vnejs/module.controller.preload",
3
+ "version": "0.2.1",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
24
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
25
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
26
+ },
27
+ "author": "",
28
+ "license": "ISC",
29
+ "peerDependencies": {
30
+ "@vnejs/module.core": "~0.2.0",
31
+ "@vnejs/shared": "~0.2.0"
32
+ },
33
+ "devDependencies": {
34
+ "@vnejs/configs.ts-common": "~0.2.0",
35
+ "@vnejs/module.core": "~0.2.0",
36
+ "@vnejs/shared": "~0.2.0"
37
+ }
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type {
4
+ ModuleControllerPreloadConstants,
5
+ ModuleControllerPreloadEvents,
6
+ ModuleControllerPreloadParams,
7
+ ModuleControllerPreloadSettings,
8
+ } from "./types.js";
9
+
10
+ export type {
11
+ ModuleControllerPreloadConstants,
12
+ ModuleControllerPreloadEvents,
13
+ ModuleControllerPreloadParams,
14
+ ModuleControllerPreloadSettings,
15
+ } from "./types.js";
16
+
17
+ export abstract class ModuleControllerPreload<
18
+ TEvents extends ModuleControllerPreloadEvents = ModuleControllerPreloadEvents,
19
+ TConstants extends ModuleControllerPreloadConstants = ModuleControllerPreloadConstants,
20
+ TSettings extends ModuleControllerPreloadSettings = ModuleControllerPreloadSettings,
21
+ TParams extends ModuleControllerPreloadParams = ModuleControllerPreloadParams,
22
+ TState = unknown,
23
+ > extends ModuleCore<TEvents, TConstants, TSettings, TParams, TState> {
24
+ abstract override name: string;
25
+
26
+ abstract EVENT_SHOW: string;
27
+ abstract EVENT_HIDE: string;
28
+ abstract EVENT_PRELOAD: string;
29
+
30
+ isShow = false;
31
+
32
+ PRELOAD_LABELS: string[] = [];
33
+ PRELOAD_EVENTS: string[] = [];
34
+
35
+ subscribe = () => {
36
+ this.on(this.EVENT_SHOW, this.onShow);
37
+ this.on(this.EVENT_HIDE, this.onHide);
38
+ this.on(this.EVENT_PRELOAD, this.onPreload);
39
+
40
+ this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
41
+ };
42
+
43
+ onShow = () => {
44
+ this.isShow = true;
45
+ return this.emit(this.EVENT_PRELOAD);
46
+ };
47
+ onHide = () => {
48
+ this.isShow = false;
49
+ };
50
+
51
+ onPreload = () => Promise.all([...this.PRELOAD_LABELS.map(this.emitLabelGet), ...this.PRELOAD_EVENTS.map(this.emitEvent)]);
52
+ onMemoryCleared = () => this.isShow && void this.emit(this.EVENT_PRELOAD);
53
+
54
+ emitLabelGet = (label: string) => this.emit(this.EVENTS.SCENARIO.LABEL_GET, { label });
55
+ emitEvent = (event: string) => this.emit(event);
56
+ }
package/src/types.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
2
+
3
+ export type ModuleControllerPreloadEvents = ModuleCoreEvents;
4
+
5
+ export type ModuleControllerPreloadConstants = ModuleCoreConstants;
6
+
7
+ export type ModuleControllerPreloadSettings = ModuleCoreSettings;
8
+
9
+ export type ModuleControllerPreloadParams = ModuleCoreParams;
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules"]
9
+ }