@vnejs/core 0.2.3 → 0.2.5
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 +0 -7
- package/index.js +7 -24
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -5,12 +5,5 @@ declare module "@vnejs/core" {
|
|
|
5
5
|
init: (options: any) => Promise<void>;
|
|
6
6
|
reset: () => Promise<void>;
|
|
7
7
|
addModule: (m: Module) => void;
|
|
8
|
-
|
|
9
|
-
getPlatform: () => string;
|
|
10
|
-
getSubPlatform: () => string;
|
|
11
|
-
|
|
12
|
-
isMobile: () => Boolean;
|
|
13
|
-
isDesktop: () => Boolean;
|
|
14
|
-
isWeb: () => Boolean;
|
|
15
8
|
}
|
|
16
9
|
}
|
package/index.js
CHANGED
|
@@ -24,18 +24,17 @@ export class VneCore {
|
|
|
24
24
|
VNE_MODULES.forEach(this.addModule);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
init = async (
|
|
28
|
-
const
|
|
29
|
-
const mods = await fetch(`/mods.json?ts=${ts}
|
|
30
|
-
const fetchResult = await Promise.all(mods.map((mod) => fetch(`/media.${mod}.json?ts=${ts}
|
|
27
|
+
init = async () => {
|
|
28
|
+
const ts = Math.round(new Date().getTime() / 1000 / 60 / 60);
|
|
29
|
+
const mods = await fetch(`/mods.json?ts=${ts}`).then(toJSON);
|
|
30
|
+
const fetchResult = await Promise.all(mods.map((mod) => fetch(`/media.${mod}.json?ts=${ts}`).then(toJSON)));
|
|
31
31
|
const media = fetchResult.reduce(mergeFetchResult, {});
|
|
32
32
|
const [on, emit, emitOne, emitReal] = [this.observer.subscribe, this.observer.emit, this.observer.emitOne, this.observer.emitReal];
|
|
33
|
-
const
|
|
34
|
-
const injectArg = { on, emit, emitOne, emitReal, state: this.state, shared: this.shared, media, options };
|
|
33
|
+
const injectArg = { on, emit, emitOne, emitReal, state: this.state, shared: this.shared, media };
|
|
35
34
|
|
|
36
35
|
Object.values(this.modules).forEach((module) => {
|
|
37
36
|
module?.inject(injectArg);
|
|
38
|
-
module?.subscribe(
|
|
37
|
+
module?.subscribe();
|
|
39
38
|
});
|
|
40
39
|
|
|
41
40
|
window.uninitedModules = [];
|
|
@@ -47,7 +46,7 @@ export class VneCore {
|
|
|
47
46
|
window.uninitedModules.push(module.name);
|
|
48
47
|
console.log("init module", module.name, "start");
|
|
49
48
|
module.isReady = false;
|
|
50
|
-
if (module.init) await module.init(
|
|
49
|
+
if (module.init) await module.init();
|
|
51
50
|
module.isReady = true;
|
|
52
51
|
console.log("init module", module.name, "finish");
|
|
53
52
|
window.uninitedModules = window.uninitedModules.filter((k) => k !== module.name);
|
|
@@ -68,20 +67,4 @@ export class VneCore {
|
|
|
68
67
|
|
|
69
68
|
this.modules[module.name] = module;
|
|
70
69
|
};
|
|
71
|
-
|
|
72
|
-
getPlatform = () => {
|
|
73
|
-
if (this.isMobile()) return VNE.CONST.PLATFORMS.MOBILE;
|
|
74
|
-
if (this.isDesktop()) return VNE.CONST.PLATFORMS.ELECTRON;
|
|
75
|
-
return VNE.CONST.PLATFORMS.WEB;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
getSubPlatform = () => {
|
|
79
|
-
if (this.isMobile()) return VNE.CONST.PLATFORMS.ANDROID;
|
|
80
|
-
if (this.isDesktop()) return VNE.CONST.PLATFORMS.WINDOWS;
|
|
81
|
-
return VNE.CONST.PLATFORMS.WEB;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
isMobile = () => Boolean(Capacitor.isNativePlatform());
|
|
85
|
-
isDesktop = () => navigator.userAgent.includes("Electron");
|
|
86
|
-
isWeb = () => !this.isMobile() && !this.isDesktop();
|
|
87
70
|
}
|