@vnejs/core 0.2.7 → 0.2.9
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 +15 -0
- package/dist/index.js +52 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +9 -0
- package/package.json +15 -8
- package/index.d.ts +0 -9
- package/index.js +0 -68
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Observer } from "@vnejs/observer";
|
|
2
|
+
import { type ModuleGlobalStateRegistry } from "@vnejs/module";
|
|
3
|
+
import type { VneModuleClass } from "@vnejs/shared";
|
|
4
|
+
import type { ModuleShared, VneCoreModules } from "./types.js";
|
|
5
|
+
export type { ModuleMedia, ModuleShared, VneCoreModules } from "./types.js";
|
|
6
|
+
export declare class VneCore {
|
|
7
|
+
observer: Observer;
|
|
8
|
+
modules: VneCoreModules;
|
|
9
|
+
state: ModuleGlobalStateRegistry;
|
|
10
|
+
shared: ModuleShared;
|
|
11
|
+
constructor();
|
|
12
|
+
init: () => Promise<void>;
|
|
13
|
+
reset: () => Promise<void>;
|
|
14
|
+
addModule: (ModuleClass: VneModuleClass) => void;
|
|
15
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Observer } from "@vnejs/observer";
|
|
2
|
+
import { VNE, VNE_MODULES } from "@vnejs/shared";
|
|
3
|
+
import { mergeFetchResult, toJSON } from "./utils.js";
|
|
4
|
+
export class VneCore {
|
|
5
|
+
observer = new Observer();
|
|
6
|
+
modules = {};
|
|
7
|
+
state = {};
|
|
8
|
+
shared = {};
|
|
9
|
+
constructor() {
|
|
10
|
+
VNE_MODULES.forEach(this.addModule);
|
|
11
|
+
}
|
|
12
|
+
init = async () => {
|
|
13
|
+
const CONST = VNE.CONST;
|
|
14
|
+
const ts = Math.round(new Date().getTime() / 1000 / 60 / 60);
|
|
15
|
+
const mods = (await fetch(`${CONST.SYSTEM.HOST}/mods.json?ts=${ts}`).then(toJSON));
|
|
16
|
+
const fetchResult = await Promise.all(mods.map((mod) => fetch(`${CONST.SYSTEM.HOST}/media.${mod}.json?ts=${ts}`).then(toJSON)));
|
|
17
|
+
const media = fetchResult.reduce(mergeFetchResult, {});
|
|
18
|
+
const injectArg = { observer: this.observer, state: this.state, shared: this.shared, media };
|
|
19
|
+
Object.values(this.modules).forEach((module) => {
|
|
20
|
+
module?.inject(injectArg);
|
|
21
|
+
module?.subscribe();
|
|
22
|
+
});
|
|
23
|
+
console.log(8888888);
|
|
24
|
+
window.uninitedModules = [];
|
|
25
|
+
console.log("init modules start");
|
|
26
|
+
await Promise.all(Object.values(this.modules).map(async (module) => {
|
|
27
|
+
if (!module)
|
|
28
|
+
return;
|
|
29
|
+
window.uninitedModules.push(module.name);
|
|
30
|
+
console.log("init module", module.name, "start");
|
|
31
|
+
module.isReady = false;
|
|
32
|
+
if (module.init)
|
|
33
|
+
await module.init();
|
|
34
|
+
module.isReady = true;
|
|
35
|
+
console.log("init module", module.name, "finish");
|
|
36
|
+
window.uninitedModules = window.uninitedModules.filter((k) => k !== module.name);
|
|
37
|
+
}));
|
|
38
|
+
console.log("init modules finish");
|
|
39
|
+
const started = VNE.EVENTS.SYSTEM?.STARTED;
|
|
40
|
+
if (started)
|
|
41
|
+
await this.observer.emit(started);
|
|
42
|
+
};
|
|
43
|
+
reset = async () => {
|
|
44
|
+
const EVENTS = VNE.EVENTS;
|
|
45
|
+
await this.observer.emit(EVENTS.STORAGE.CLEAR);
|
|
46
|
+
await this.observer.emit(EVENTS.SYSTEM.RELOAD);
|
|
47
|
+
};
|
|
48
|
+
addModule = (ModuleClass) => {
|
|
49
|
+
const module = new ModuleClass();
|
|
50
|
+
this.modules[module.name] = module;
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Module, ModuleMedia, ModuleShared } from "@vnejs/module";
|
|
2
|
+
export type VneCoreModules = Record<string, Module | undefined>;
|
|
3
|
+
export type { ModuleMedia, ModuleShared };
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
uninitedModules: string[];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface CoreVnePluginEventsMap {
|
|
10
|
+
STORAGE: {
|
|
11
|
+
CLEAR: string;
|
|
12
|
+
};
|
|
13
|
+
SYSTEM: {
|
|
14
|
+
RELOAD: string;
|
|
15
|
+
STARTED: string;
|
|
16
|
+
HOST: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface CoreVnePluginConstantsMap {
|
|
20
|
+
SYSTEM: {
|
|
21
|
+
HOST: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/core",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.2.9",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
5
10
|
"scripts": {
|
|
6
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
-
"
|
|
8
|
-
"publish:
|
|
9
|
-
"publish:
|
|
12
|
+
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
13
|
+
"publish:major": "npm run build && npm version major && npm publish --access public",
|
|
14
|
+
"publish:minor": "npm run build && npm version minor && npm publish --access public",
|
|
15
|
+
"publish:patch": "npm run build && npm version patch && npm publish --access public"
|
|
10
16
|
},
|
|
11
17
|
"author": "",
|
|
12
18
|
"license": "ISC",
|
|
13
|
-
"description": "",
|
|
14
19
|
"dependencies": {
|
|
15
20
|
"@capacitor/core": "5.7.8",
|
|
16
21
|
"@capacitor/app": "5.0.8",
|
|
@@ -26,7 +31,9 @@
|
|
|
26
31
|
"@vnejs/module": "~0.0.1",
|
|
27
32
|
"@vnejs/module.components": "~0.0.1",
|
|
28
33
|
"@vnejs/observer": "~0.0.1",
|
|
29
|
-
"@vnejs/helpers": "~0.1.0"
|
|
30
|
-
|
|
34
|
+
"@vnejs/helpers": "~0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"typescript": "^6.0.3"
|
|
31
38
|
}
|
|
32
39
|
}
|
package/index.d.ts
DELETED
package/index.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Observer } from "@vnejs/observer";
|
|
2
|
-
import { VNE, VNE_MODULES } from "@vnejs/shared";
|
|
3
|
-
|
|
4
|
-
const toJSON = (i) => i.json();
|
|
5
|
-
|
|
6
|
-
const mergeFetchResult = (acc, media) => {
|
|
7
|
-
Object.keys(media).forEach((key) => {
|
|
8
|
-
if (!acc[key]) acc[key] = {};
|
|
9
|
-
Object.assign(acc[key], media[key]);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
return acc;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export class VneCore {
|
|
16
|
-
observer = new Observer();
|
|
17
|
-
modules = {};
|
|
18
|
-
state = {};
|
|
19
|
-
shared = {};
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
VNE_MODULES.forEach(this.addModule);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
init = async () => {
|
|
26
|
-
const ts = Math.round(new Date().getTime() / 1000 / 60 / 60);
|
|
27
|
-
const mods = await fetch(`${VNE.CONST.SYSTEM.HOST}/mods.json?ts=${ts}`).then(toJSON);
|
|
28
|
-
const fetchResult = await Promise.all(mods.map((mod) => fetch(`${VNE.CONST.SYSTEM.HOST}/media.${mod}.json?ts=${ts}`).then(toJSON)));
|
|
29
|
-
const media = fetchResult.reduce(mergeFetchResult, {});
|
|
30
|
-
const [on, emit, emitOne, emitReal] = [this.observer.subscribe, this.observer.emit, this.observer.emitOne, this.observer.emitReal];
|
|
31
|
-
const injectArg = { on, emit, emitOne, emitReal, state: this.state, shared: this.shared, media };
|
|
32
|
-
|
|
33
|
-
Object.values(this.modules).forEach((module) => {
|
|
34
|
-
module?.inject(injectArg);
|
|
35
|
-
module?.subscribe();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
window.uninitedModules = [];
|
|
39
|
-
|
|
40
|
-
console.log("init modules start");
|
|
41
|
-
await Promise.all(
|
|
42
|
-
Object.values(this.modules).map(async (module) => {
|
|
43
|
-
if (!module) return;
|
|
44
|
-
window.uninitedModules.push(module.name);
|
|
45
|
-
console.log("init module", module.name, "start");
|
|
46
|
-
module.isReady = false;
|
|
47
|
-
if (module.init) await module.init();
|
|
48
|
-
module.isReady = true;
|
|
49
|
-
console.log("init module", module.name, "finish");
|
|
50
|
-
window.uninitedModules = window.uninitedModules.filter((k) => k !== module.name);
|
|
51
|
-
}),
|
|
52
|
-
);
|
|
53
|
-
console.log("init modules finish");
|
|
54
|
-
|
|
55
|
-
emit(VNE.EVENTS.SYSTEM.STARTED);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
reset = async () => {
|
|
59
|
-
await this.observer.notify(VNE.EVENTS.STORAGE.CLEAR);
|
|
60
|
-
await this.observer.notify(VNE.EVENTS.SYSTEM.RELOAD);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
addModule = (Module) => {
|
|
64
|
-
const module = new Module();
|
|
65
|
-
|
|
66
|
-
this.modules[module.name] = module;
|
|
67
|
-
};
|
|
68
|
-
}
|