@vnejs/module 0.0.5 → 0.0.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/index.d.ts +69 -0
- package/index.js +1 -62
- package/modules/module.js +57 -0
- package/package.json +1 -2
- package/module.ts +0 -11
package/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
declare type GlobalState = {};
|
|
2
|
+
|
|
3
|
+
declare type SHARED = {};
|
|
4
|
+
|
|
5
|
+
type OnFunc = (event: string, func: (arg: any) => Promise<any>) => void;
|
|
6
|
+
type EmitFunc = (event: string, arg: any) => Promise<any[]>;
|
|
7
|
+
type EmitOneFunc = (event: string, arg: any) => Promise<any>;
|
|
8
|
+
|
|
9
|
+
type InjectArg = {
|
|
10
|
+
on: OnFunc;
|
|
11
|
+
emit: EmitFunc;
|
|
12
|
+
emitOne: EmitOneFunc;
|
|
13
|
+
|
|
14
|
+
state: GlobalState;
|
|
15
|
+
|
|
16
|
+
shared: SHARED;
|
|
17
|
+
media: Record<string, Record<string, string>>;
|
|
18
|
+
options: any;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
declare type StateType = {};
|
|
22
|
+
|
|
23
|
+
export class Module {
|
|
24
|
+
isReady: Boolean;
|
|
25
|
+
|
|
26
|
+
CONST: CONST;
|
|
27
|
+
EVENTS: EVENTS;
|
|
28
|
+
PARAMS: PARAMS;
|
|
29
|
+
SETTINGS: SETTINGS;
|
|
30
|
+
|
|
31
|
+
on: OnFunc;
|
|
32
|
+
emit: EmitFunc;
|
|
33
|
+
emitOne: EmitOneFunc;
|
|
34
|
+
|
|
35
|
+
globalState: GlobalState;
|
|
36
|
+
state: StateType;
|
|
37
|
+
|
|
38
|
+
shared: SHARED;
|
|
39
|
+
media: Record<string, Record<string, string>>;
|
|
40
|
+
options: any;
|
|
41
|
+
|
|
42
|
+
inject: (arg: InjectArg) => void; // abstract
|
|
43
|
+
|
|
44
|
+
subscribe: () => void;
|
|
45
|
+
init: () => Promise<void>; // implement
|
|
46
|
+
|
|
47
|
+
setState: (state: StateType) => void; // abstract
|
|
48
|
+
updateState: (state: Partial<StateType>) => void; // abstract
|
|
49
|
+
setDefaultState: () => void;
|
|
50
|
+
setStateFromGlobalState: (state: GlobalState) => void;
|
|
51
|
+
getState: () => StateType;
|
|
52
|
+
getDefaultState: () => StateType; // implement
|
|
53
|
+
|
|
54
|
+
waitCheck: (checkFunc: () => Boolean) => Promise<void>;
|
|
55
|
+
waitRerenderCheck: (checkFunc: () => Boolean) => Promise<void>;
|
|
56
|
+
waitIsReady: () => Promise<void>;
|
|
57
|
+
waitTimeout: (time: number) => Promise<void>;
|
|
58
|
+
waitImmediate: () => Promise<void>;
|
|
59
|
+
waitRender: () => Promise<void>;
|
|
60
|
+
waitRerender: () => Promise<void>;
|
|
61
|
+
|
|
62
|
+
getIsReady: () => Boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare module "@vnejs/shared" {
|
|
66
|
+
export const VNE_MODULES: Module[];
|
|
67
|
+
|
|
68
|
+
export const regModule: (m: Module) => void;
|
|
69
|
+
}
|
package/index.js
CHANGED
|
@@ -1,62 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export class Module {
|
|
4
|
-
isReady = false;
|
|
5
|
-
|
|
6
|
-
EVENTS = VNE_EVENTS;
|
|
7
|
-
CONST = VNE_CONST;
|
|
8
|
-
SETTINGS = VNE_SETTINGS;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
Object.keys(VNE_MODULE_EXTENSIONS).forEach((funcName) => {
|
|
12
|
-
this[funcName] = VNE_MODULE_EXTENSIONS[funcName].bind(this, this);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
inject = ({ on, emit, emitOne, state, shared, media, options } = {}) => {
|
|
17
|
-
// observer
|
|
18
|
-
this.on = on;
|
|
19
|
-
this.emit = emit;
|
|
20
|
-
this.emitOne = emitOne;
|
|
21
|
-
|
|
22
|
-
// state
|
|
23
|
-
this.globalState = state;
|
|
24
|
-
this.state = this.globalState[this.name] = this.getDefaultState() || {};
|
|
25
|
-
|
|
26
|
-
this.shared = shared;
|
|
27
|
-
this.media = media;
|
|
28
|
-
this.options = options;
|
|
29
|
-
}; // abstract
|
|
30
|
-
subscribe = () => {}; // implement
|
|
31
|
-
|
|
32
|
-
init = async () => {}; // implement
|
|
33
|
-
|
|
34
|
-
setState = (state = {}) => {
|
|
35
|
-
this.globalState[this.name] = state;
|
|
36
|
-
this.state = this.globalState[this.name];
|
|
37
|
-
}; // abstract
|
|
38
|
-
|
|
39
|
-
updateState = (state = {}) => this.setState({ ...this.state, ...state });
|
|
40
|
-
|
|
41
|
-
setDefaultState = () => this.setState(this.getDefaultState());
|
|
42
|
-
|
|
43
|
-
setStateFromGlobalState = ({ [this.name]: state }) => this.setState(state);
|
|
44
|
-
|
|
45
|
-
getState = () => this.state;
|
|
46
|
-
|
|
47
|
-
getDefaultState = () => ({}); // implement
|
|
48
|
-
|
|
49
|
-
waitCheck = async (checkFunc) => {
|
|
50
|
-
while (!checkFunc()) await this.waitTimeout(0);
|
|
51
|
-
};
|
|
52
|
-
waitRerenderCheck = async (checkFunc) => {
|
|
53
|
-
while (!checkFunc()) await this.waitRerender();
|
|
54
|
-
};
|
|
55
|
-
waitIsReady = () => this.waitCheck(this.getIsReady);
|
|
56
|
-
waitTimeout = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
57
|
-
waitImmediate = () => new Promise(setImmediate);
|
|
58
|
-
waitRender = () => new Promise(requestAnimationFrame);
|
|
59
|
-
waitRerender = () => new Promise((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0)));
|
|
60
|
-
|
|
61
|
-
getIsReady = () => this.isReady;
|
|
62
|
-
}
|
|
1
|
+
export * from "./modules/module";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { VNE } from "@vnejs/shared";
|
|
2
|
+
|
|
3
|
+
export class Module {
|
|
4
|
+
isReady = false;
|
|
5
|
+
|
|
6
|
+
EVENTS = VNE.EVENTS;
|
|
7
|
+
CONST = VNE.CONST;
|
|
8
|
+
SETTINGS = VNE.SETTINGS;
|
|
9
|
+
PARAMS = VNE.PARAMS;
|
|
10
|
+
|
|
11
|
+
inject = ({ on, emit, emitOne, state, shared, media, options } = {}) => {
|
|
12
|
+
// observer
|
|
13
|
+
this.on = on;
|
|
14
|
+
this.emit = emit;
|
|
15
|
+
this.emitOne = emitOne;
|
|
16
|
+
|
|
17
|
+
// state
|
|
18
|
+
this.globalState = state;
|
|
19
|
+
this.state = this.globalState[this.name] = this.getDefaultState() || {};
|
|
20
|
+
|
|
21
|
+
this.shared = shared;
|
|
22
|
+
this.media = media;
|
|
23
|
+
this.options = options;
|
|
24
|
+
}; // abstract
|
|
25
|
+
subscribe = () => {}; // implement
|
|
26
|
+
|
|
27
|
+
init = async () => {}; // implement
|
|
28
|
+
|
|
29
|
+
setState = (state = {}) => {
|
|
30
|
+
this.globalState[this.name] = state;
|
|
31
|
+
this.state = this.globalState[this.name];
|
|
32
|
+
}; // abstract
|
|
33
|
+
|
|
34
|
+
updateState = (state = {}) => this.setState({ ...this.state, ...state });
|
|
35
|
+
|
|
36
|
+
setDefaultState = () => this.setState(this.getDefaultState());
|
|
37
|
+
|
|
38
|
+
setStateFromGlobalState = ({ [this.name]: state }) => this.setState(state);
|
|
39
|
+
|
|
40
|
+
getState = () => this.state;
|
|
41
|
+
|
|
42
|
+
getDefaultState = () => ({}); // implement
|
|
43
|
+
|
|
44
|
+
waitCheck = async (checkFunc) => {
|
|
45
|
+
while (!checkFunc()) await this.waitTimeout(0);
|
|
46
|
+
};
|
|
47
|
+
waitRerenderCheck = async (checkFunc) => {
|
|
48
|
+
while (!checkFunc()) await this.waitRerender();
|
|
49
|
+
};
|
|
50
|
+
waitIsReady = () => this.waitCheck(this.getIsReady);
|
|
51
|
+
waitTimeout = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
52
|
+
waitImmediate = () => new Promise(setImmediate);
|
|
53
|
+
waitRender = () => new Promise(requestAnimationFrame);
|
|
54
|
+
waitRerender = () => new Promise((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0)));
|
|
55
|
+
|
|
56
|
+
getIsReady = () => this.isReady;
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/module",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"types": "module.d.ts",
|
|
7
6
|
"scripts": {
|
|
8
7
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
8
|
"publish:major": "npm version major && npm publish --access public",
|
package/module.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { VNE_CONST } from "@vnejs/shared";
|
|
2
|
-
import { VNE_EVENTS } from "@vnejs/shared";
|
|
3
|
-
import { VNE_SETTINGS } from "@vnejs/shared";
|
|
4
|
-
|
|
5
|
-
import { Module as _Module } from "./index";
|
|
6
|
-
|
|
7
|
-
export interface Module extends _Module {
|
|
8
|
-
CONST: VNE_CONST;
|
|
9
|
-
EVENTS: VNE_EVENTS;
|
|
10
|
-
SETTINGS: VNE_SETTINGS;
|
|
11
|
-
}
|