zova-core 5.1.47 → 5.1.49
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/bean/beanControllerPageBase.d.ts.map +1 -1
- package/dist/core/component/module.d.ts +1 -0
- package/dist/core/component/module.d.ts.map +1 -1
- package/dist/core/context/component.d.ts +3 -0
- package/dist/core/context/component.d.ts.map +1 -1
- package/dist/core/context/util.d.ts.map +1 -1
- package/dist/core/sys/module.d.ts +3 -1
- package/dist/core/sys/module.d.ts.map +1 -1
- package/dist/core/sys/sys.d.ts.map +1 -1
- package/dist/index.js +133 -59
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/bean/beanContainer.ts +3 -3
- package/src/bean/beanControllerPageBase.ts +1 -0
- package/src/core/component/module.ts +40 -24
- package/src/core/context/component.ts +35 -3
- package/src/core/context/util.ts +15 -11
- package/src/core/sys/module.ts +41 -17
- package/src/core/sys/sys.ts +4 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zova-core",
|
|
3
|
-
"version": "5.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "5.1.49",
|
|
4
|
+
"gitHead": "7332ce2a4b44504a88c64da981b60336ebef7e9b",
|
|
5
5
|
"description": "A vue3 framework with ioc",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"ioc",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@cabloy/vue-compiler-sfc": "^3.5.14",
|
|
52
52
|
"@cabloy/vue-reactivity": "^3.5.16",
|
|
53
53
|
"@cabloy/vue-router": "^4.4.16",
|
|
54
|
-
"@cabloy/vue-runtime-core": "^3.5.
|
|
54
|
+
"@cabloy/vue-runtime-core": "^3.5.56",
|
|
55
55
|
"@cabloy/vue-runtime-dom": "^3.5.13",
|
|
56
56
|
"@cabloy/vue-server-renderer": "^3.5.18",
|
|
57
57
|
"@cabloy/word-utils": "^2.1.14",
|
|
@@ -103,7 +103,7 @@ export class BeanContainer {
|
|
|
103
103
|
beanInstance,
|
|
104
104
|
);
|
|
105
105
|
this.runWithInstanceScopeOrAppContext(() => {
|
|
106
|
-
beanInstance.__dispose__();
|
|
106
|
+
return beanInstance.__dispose__();
|
|
107
107
|
});
|
|
108
108
|
this.app.meta.module._monkeyModuleSync(
|
|
109
109
|
false,
|
|
@@ -630,8 +630,8 @@ export class BeanContainer {
|
|
|
630
630
|
await this.app?.meta.module._monkeyModule(true, 'beanInit', undefined, this, beanInstance);
|
|
631
631
|
}
|
|
632
632
|
if (!(beanInstance instanceof BeanAopBase) && beanInstance.__init__) {
|
|
633
|
-
await this.runWithInstanceScopeOrAppContext(
|
|
634
|
-
|
|
633
|
+
await this.runWithInstanceScopeOrAppContext(() => {
|
|
634
|
+
return beanInstance.__init__(...args);
|
|
635
635
|
});
|
|
636
636
|
}
|
|
637
637
|
if (this.containerType === 'sys') {
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
IMonkeyApp,
|
|
12
12
|
IMonkeyController,
|
|
13
13
|
IMonkeyModule,
|
|
14
|
+
PluginZovaModulesMeta,
|
|
14
15
|
TypeMonkeyName,
|
|
15
16
|
} from '../../types/index.ts';
|
|
16
17
|
|
|
@@ -23,6 +24,14 @@ export class AppModule extends BeanSimple {
|
|
|
23
24
|
private mainInstances: Record<string, IModuleMain> = {};
|
|
24
25
|
private monkeyInstances: Record<string, IMonkeyModule & IMonkeyApp & IMonkeyController> = {};
|
|
25
26
|
|
|
27
|
+
private _ensureModulesMeta(): PluginZovaModulesMeta {
|
|
28
|
+
const modulesMeta = this.sys.meta.module.getModulesMeta();
|
|
29
|
+
if (!modulesMeta) {
|
|
30
|
+
throw new Error('module registry has been disposed');
|
|
31
|
+
}
|
|
32
|
+
return modulesMeta;
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
/** @internal */
|
|
27
36
|
public async initialize() {
|
|
28
37
|
await this._requireAllSpecifics('preload');
|
|
@@ -34,6 +43,7 @@ export class AppModule extends BeanSimple {
|
|
|
34
43
|
get(moduleName: string, forceLoad?: boolean): IModule | undefined;
|
|
35
44
|
get(moduleName: IModuleInfo, forceLoad?: boolean): IModule | undefined;
|
|
36
45
|
get(moduleName: string | IModuleInfo, forceLoad?: boolean): IModule | undefined {
|
|
46
|
+
if (!this.sys.meta.module.getModulesMeta()) return undefined;
|
|
37
47
|
// module info
|
|
38
48
|
if (!moduleName) return undefined;
|
|
39
49
|
const moduleInfo =
|
|
@@ -67,8 +77,9 @@ export class AppModule extends BeanSimple {
|
|
|
67
77
|
// should not try check get directly
|
|
68
78
|
// const module = this.getOnly(relativeName);
|
|
69
79
|
// if (module) return module;
|
|
80
|
+
const modulesMeta = this._ensureModulesMeta();
|
|
70
81
|
// module
|
|
71
|
-
const moduleRepo =
|
|
82
|
+
const moduleRepo = modulesMeta.modules[relativeName];
|
|
72
83
|
if (!moduleRepo) throw new Error(`module not exists: ${relativeName}`);
|
|
73
84
|
// install
|
|
74
85
|
await this._install(relativeName, moduleRepo);
|
|
@@ -84,15 +95,16 @@ export class AppModule extends BeanSimple {
|
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
private async _requireAllSpecifics(capabilityName: 'preload' | 'monkey' | 'sync') {
|
|
87
|
-
const
|
|
88
|
-
|
|
98
|
+
const modulesMeta = this._ensureModulesMeta();
|
|
99
|
+
const moduleNames = modulesMeta.moduleNames.filter(moduleName => {
|
|
100
|
+
const module = modulesMeta.modules[moduleName];
|
|
89
101
|
return module.info.capabilities?.[capabilityName];
|
|
90
102
|
});
|
|
91
103
|
// if (moduleNames.length > 0) {
|
|
92
104
|
// this.sys.meta.logger.child('module', 'default').debug(`app modules: ${capabilityName}: ${moduleNames.join(',')}`);
|
|
93
105
|
// }
|
|
94
106
|
for (const moduleName of moduleNames) {
|
|
95
|
-
const module =
|
|
107
|
+
const module = modulesMeta.modules[moduleName];
|
|
96
108
|
await this._install(moduleName, module);
|
|
97
109
|
}
|
|
98
110
|
}
|
|
@@ -167,29 +179,31 @@ export class AppModule extends BeanSimple {
|
|
|
167
179
|
moduleTarget?: IModule,
|
|
168
180
|
...monkeyData: any[]
|
|
169
181
|
) {
|
|
182
|
+
const modulesMeta = this.sys.meta.module.getModulesMeta();
|
|
183
|
+
if (!modulesMeta) return;
|
|
170
184
|
// self: main
|
|
171
185
|
if (moduleTarget) {
|
|
172
186
|
const mainInstance = this.mainInstances[moduleTarget.info.relativeName];
|
|
173
187
|
if (mainInstance && mainInstance[monkeyName]) {
|
|
174
188
|
// @ts-ignore ignore
|
|
175
|
-
await this.app.vue.runWithContext(
|
|
176
|
-
|
|
189
|
+
await this.app.vue.runWithContext(() => {
|
|
190
|
+
return mainInstance[monkeyName](...monkeyData);
|
|
177
191
|
});
|
|
178
192
|
}
|
|
179
193
|
}
|
|
180
194
|
// module monkey
|
|
181
|
-
await forEach(
|
|
182
|
-
const moduleMonkey: IModule =
|
|
195
|
+
await forEach(modulesMeta.moduleNames, order, async key => {
|
|
196
|
+
const moduleMonkey: IModule = modulesMeta.modules[key];
|
|
183
197
|
if (moduleMonkey.info.capabilities?.monkey) {
|
|
184
198
|
const monkeyInstance = this.monkeyInstances[key];
|
|
185
199
|
if (monkeyInstance && monkeyInstance[monkeyName]) {
|
|
186
|
-
await this.app.vue.runWithContext(
|
|
200
|
+
await this.app.vue.runWithContext(() => {
|
|
187
201
|
if (moduleTarget === undefined) {
|
|
188
202
|
// @ts-ignore ignore
|
|
189
|
-
|
|
203
|
+
return monkeyInstance[monkeyName](...monkeyData);
|
|
190
204
|
} else {
|
|
191
205
|
// @ts-ignore ignore
|
|
192
|
-
|
|
206
|
+
return monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
|
|
193
207
|
}
|
|
194
208
|
});
|
|
195
209
|
}
|
|
@@ -198,13 +212,13 @@ export class AppModule extends BeanSimple {
|
|
|
198
212
|
// app monkey
|
|
199
213
|
const appMonkey = this.app.meta.appMonkey;
|
|
200
214
|
if (appMonkey && appMonkey[monkeyName]) {
|
|
201
|
-
await this.app.vue.runWithContext(
|
|
215
|
+
await this.app.vue.runWithContext(() => {
|
|
202
216
|
if (moduleTarget === undefined) {
|
|
203
217
|
// @ts-ignore ignore
|
|
204
|
-
|
|
218
|
+
return appMonkey[monkeyName](...monkeyData);
|
|
205
219
|
} else {
|
|
206
220
|
// @ts-ignore ignore
|
|
207
|
-
|
|
221
|
+
return appMonkey[monkeyName](moduleTarget, ...monkeyData);
|
|
208
222
|
}
|
|
209
223
|
});
|
|
210
224
|
}
|
|
@@ -217,29 +231,31 @@ export class AppModule extends BeanSimple {
|
|
|
217
231
|
moduleTarget?: IModule,
|
|
218
232
|
...monkeyData: any[]
|
|
219
233
|
) {
|
|
234
|
+
const modulesMeta = this.sys.meta.module.getModulesMeta();
|
|
235
|
+
if (!modulesMeta) return;
|
|
220
236
|
// self: main
|
|
221
237
|
if (moduleTarget) {
|
|
222
238
|
const mainInstance = this.mainInstances[moduleTarget.info.relativeName];
|
|
223
239
|
if (mainInstance && mainInstance[monkeyName]) {
|
|
224
240
|
// @ts-ignore ignore
|
|
225
|
-
this.app.vue.runWithContext(
|
|
226
|
-
mainInstance[monkeyName](...monkeyData);
|
|
241
|
+
this.app.vue.runWithContext(() => {
|
|
242
|
+
return mainInstance[monkeyName](...monkeyData);
|
|
227
243
|
});
|
|
228
244
|
}
|
|
229
245
|
}
|
|
230
246
|
// module monkey
|
|
231
|
-
forEachSync(
|
|
232
|
-
const moduleMonkey: IModule =
|
|
247
|
+
forEachSync(modulesMeta.moduleNames, order, key => {
|
|
248
|
+
const moduleMonkey: IModule = modulesMeta.modules[key];
|
|
233
249
|
if (moduleMonkey.info.capabilities?.monkey) {
|
|
234
250
|
const monkeyInstance = this.monkeyInstances[key];
|
|
235
251
|
if (monkeyInstance && monkeyInstance[monkeyName]) {
|
|
236
|
-
this.app.vue.runWithContext(
|
|
252
|
+
this.app.vue.runWithContext(() => {
|
|
237
253
|
if (moduleTarget === undefined) {
|
|
238
254
|
// @ts-ignore ignore
|
|
239
|
-
monkeyInstance[monkeyName](...monkeyData);
|
|
255
|
+
return monkeyInstance[monkeyName](...monkeyData);
|
|
240
256
|
} else {
|
|
241
257
|
// @ts-ignore ignore
|
|
242
|
-
monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
|
|
258
|
+
return monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
|
|
243
259
|
}
|
|
244
260
|
});
|
|
245
261
|
}
|
|
@@ -248,13 +264,13 @@ export class AppModule extends BeanSimple {
|
|
|
248
264
|
// app monkey
|
|
249
265
|
const appMonkey = this.app.meta.appMonkey;
|
|
250
266
|
if (appMonkey && appMonkey[monkeyName]) {
|
|
251
|
-
this.app.vue.runWithContext(
|
|
267
|
+
this.app.vue.runWithContext(() => {
|
|
252
268
|
if (moduleTarget === undefined) {
|
|
253
269
|
// @ts-ignore ignore
|
|
254
|
-
appMonkey[monkeyName](...monkeyData);
|
|
270
|
+
return appMonkey[monkeyName](...monkeyData);
|
|
255
271
|
} else {
|
|
256
272
|
// @ts-ignore ignore
|
|
257
|
-
appMonkey[monkeyName](moduleTarget, ...monkeyData);
|
|
273
|
+
return appMonkey[monkeyName](moduleTarget, ...monkeyData);
|
|
258
274
|
}
|
|
259
275
|
});
|
|
260
276
|
}
|
|
@@ -4,15 +4,21 @@ import { BeanSimple } from '../../bean/beanSimple.ts';
|
|
|
4
4
|
import { BeanControllerIdentifier, BeanRenderIdentifier } from '../../bean/type.ts';
|
|
5
5
|
import { cast } from '../../types/utils/cast.ts';
|
|
6
6
|
|
|
7
|
+
const SymbolTypeSSRRenderOriginal = Symbol('SymbolTypeSSRRenderOriginal');
|
|
8
|
+
const SymbolTypeSSRRenderResetCount = Symbol('SymbolTypeSSRRenderResetCount');
|
|
9
|
+
|
|
7
10
|
export class CtxComponent extends BeanSimple {
|
|
8
11
|
private _bean_render_original: any;
|
|
12
|
+
private _instance_ssrRender_original: any;
|
|
13
|
+
private _renderPatched = false;
|
|
14
|
+
private _ssrRenderReset = false;
|
|
9
15
|
|
|
10
16
|
activate() {
|
|
11
17
|
if (this.ctx.disposed) return;
|
|
12
18
|
const renderMethod = 'render';
|
|
13
|
-
const self = this;
|
|
14
19
|
const instance = cast(this.ctx.instance);
|
|
15
20
|
this._bean_render_original = instance[renderMethod];
|
|
21
|
+
const self = this;
|
|
16
22
|
instance[renderMethod] = function (this, ...args) {
|
|
17
23
|
if (instance.isUnmounted) return;
|
|
18
24
|
if (!self.ctx.meta.state.inited.state) {
|
|
@@ -33,16 +39,42 @@ export class CtxComponent extends BeanSimple {
|
|
|
33
39
|
// return render.render();
|
|
34
40
|
// }
|
|
35
41
|
};
|
|
36
|
-
|
|
42
|
+
this._renderPatched = true;
|
|
43
|
+
const componentType = cast(instance.type);
|
|
44
|
+
const ssrRenderResetCount = componentType[SymbolTypeSSRRenderResetCount] ?? 0;
|
|
45
|
+
if (ssrRenderResetCount === 0) {
|
|
46
|
+
componentType[SymbolTypeSSRRenderOriginal] = componentType.ssrRender;
|
|
47
|
+
componentType.ssrRender = null;
|
|
48
|
+
}
|
|
49
|
+
componentType[SymbolTypeSSRRenderResetCount] = ssrRenderResetCount + 1;
|
|
50
|
+
this._instance_ssrRender_original = instance.ssrRender;
|
|
37
51
|
instance.ssrRender = null;
|
|
52
|
+
this._ssrRenderReset = true;
|
|
38
53
|
}
|
|
39
54
|
|
|
40
55
|
/** @internal */
|
|
41
56
|
public dispose() {
|
|
42
57
|
const renderMethod = 'render';
|
|
43
58
|
const instance = cast(this.ctx.instance);
|
|
44
|
-
|
|
59
|
+
if (this._renderPatched) {
|
|
60
|
+
instance[renderMethod] = this._bean_render_original;
|
|
61
|
+
}
|
|
62
|
+
if (this._ssrRenderReset) {
|
|
63
|
+
instance.ssrRender = this._instance_ssrRender_original;
|
|
64
|
+
const componentType = cast(instance.type);
|
|
65
|
+
const ssrRenderResetCount = componentType[SymbolTypeSSRRenderResetCount] ?? 0;
|
|
66
|
+
if (ssrRenderResetCount <= 1) {
|
|
67
|
+
componentType.ssrRender = componentType[SymbolTypeSSRRenderOriginal];
|
|
68
|
+
componentType[SymbolTypeSSRRenderOriginal] = undefined;
|
|
69
|
+
componentType[SymbolTypeSSRRenderResetCount] = 0;
|
|
70
|
+
} else {
|
|
71
|
+
componentType[SymbolTypeSSRRenderResetCount] = ssrRenderResetCount - 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
45
74
|
this._bean_render_original = null;
|
|
75
|
+
this._instance_ssrRender_original = null;
|
|
76
|
+
this._renderPatched = false;
|
|
77
|
+
this._ssrRenderReset = false;
|
|
46
78
|
}
|
|
47
79
|
|
|
48
80
|
private _getRender(): any {
|
package/src/core/context/util.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { withCurrentInstanceScope, withCurrentInstanceScopeSSR } from '@cabloy/vue-runtime-core';
|
|
2
2
|
import { pauseTracking, resetTracking } from '@vue/reactivity';
|
|
3
3
|
|
|
4
4
|
import { BeanSimple } from '../../bean/beanSimple.ts';
|
|
@@ -9,17 +9,21 @@ export class CtxUtil extends BeanSimple {
|
|
|
9
9
|
if (this.ctx.disposed) {
|
|
10
10
|
throwErrorComponentUnmounted();
|
|
11
11
|
}
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
return fn();
|
|
18
|
-
} finally {
|
|
12
|
+
const instance = this.ctx.instance as any;
|
|
13
|
+
const runner = process.env.SERVER ? withCurrentInstanceScopeSSR : withCurrentInstanceScope;
|
|
14
|
+
const result = runner(instance, () => {
|
|
19
15
|
if (!tracking) {
|
|
20
|
-
|
|
16
|
+
pauseTracking();
|
|
21
17
|
}
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
try {
|
|
19
|
+
const result = fn();
|
|
20
|
+
return result;
|
|
21
|
+
} finally {
|
|
22
|
+
if (!tracking) {
|
|
23
|
+
resetTracking();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return result;
|
|
24
28
|
}
|
|
25
29
|
}
|
package/src/core/sys/module.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { StateLock } from '../../utils/stateLock.ts';
|
|
|
20
20
|
import { deepExtend } from '../sys/util.ts';
|
|
21
21
|
|
|
22
22
|
export class SysModule extends BeanSimple {
|
|
23
|
-
public modulesMeta: PluginZovaModulesMeta;
|
|
23
|
+
public modulesMeta: PluginZovaModulesMeta | undefined;
|
|
24
24
|
private modules: Record<string, IModule> = shallowReactive({});
|
|
25
25
|
private mainInstances: Record<string, IModuleMainSys> = {};
|
|
26
26
|
private monkeyInstances: Record<string, IMonkeyModuleSys & IMonkeySys> = {};
|
|
@@ -39,13 +39,26 @@ export class SysModule extends BeanSimple {
|
|
|
39
39
|
|
|
40
40
|
/** @internal */
|
|
41
41
|
public dispose() {
|
|
42
|
-
this.modulesMeta = undefined
|
|
42
|
+
this.modulesMeta = undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public getModulesMeta(): PluginZovaModulesMeta | undefined {
|
|
46
|
+
return this.modulesMeta;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private _ensureModulesMeta(): PluginZovaModulesMeta {
|
|
50
|
+
const modulesMeta = this.modulesMeta;
|
|
51
|
+
if (!modulesMeta) {
|
|
52
|
+
throw new Error('module registry has been disposed');
|
|
53
|
+
}
|
|
54
|
+
return modulesMeta;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
get<K extends TypeBeanScopeRecordKeys>(moduleName: K): IModule | undefined;
|
|
46
58
|
get(moduleName: string): IModule | undefined;
|
|
47
59
|
get(moduleName: IModuleInfo): IModule | undefined;
|
|
48
60
|
get(moduleName: string | IModuleInfo): IModule | undefined {
|
|
61
|
+
if (!this.modulesMeta) return undefined;
|
|
49
62
|
// module info
|
|
50
63
|
if (!moduleName) return undefined;
|
|
51
64
|
const moduleInfo =
|
|
@@ -75,8 +88,9 @@ export class SysModule extends BeanSimple {
|
|
|
75
88
|
// should not try check get directly
|
|
76
89
|
// const module = this.getOnly(relativeName);
|
|
77
90
|
// if (module) return module;
|
|
91
|
+
const modulesMeta = this._ensureModulesMeta();
|
|
78
92
|
// module
|
|
79
|
-
const moduleRepo =
|
|
93
|
+
const moduleRepo = modulesMeta.modules[relativeName];
|
|
80
94
|
if (!moduleRepo) throw new Error(`module not exists: ${relativeName}`);
|
|
81
95
|
// install
|
|
82
96
|
await this._install(relativeName, moduleRepo);
|
|
@@ -88,19 +102,22 @@ export class SysModule extends BeanSimple {
|
|
|
88
102
|
exists(moduleName: string): boolean;
|
|
89
103
|
exists(moduleName: IModuleInfo): boolean;
|
|
90
104
|
exists(moduleName: string | IModuleInfo): boolean {
|
|
105
|
+
const modulesMeta = this.modulesMeta;
|
|
106
|
+
if (!modulesMeta) return false;
|
|
91
107
|
// module info
|
|
92
108
|
if (!moduleName) return false;
|
|
93
109
|
const moduleInfo =
|
|
94
110
|
typeof moduleName === 'string' ? ModuleInfo.parseInfo(moduleName) : moduleName;
|
|
95
111
|
if (!moduleInfo) throw new Error(`invalid module name: ${moduleName}`);
|
|
96
|
-
const moduleRepo =
|
|
112
|
+
const moduleRepo = modulesMeta.modules[moduleInfo.relativeName];
|
|
97
113
|
return !!moduleRepo;
|
|
98
114
|
}
|
|
99
115
|
|
|
100
116
|
private async _loadAllMonkeysAndSyncsAndPreloads() {
|
|
117
|
+
const modulesMeta = this._ensureModulesMeta();
|
|
101
118
|
const moduleNames: string[] = [];
|
|
102
|
-
for (const moduleName of
|
|
103
|
-
const module =
|
|
119
|
+
for (const moduleName of modulesMeta.moduleNames) {
|
|
120
|
+
const module = modulesMeta.modules[moduleName];
|
|
104
121
|
const info = module.info;
|
|
105
122
|
const shouldLoad =
|
|
106
123
|
process.env.SERVER ||
|
|
@@ -119,10 +136,11 @@ export class SysModule extends BeanSimple {
|
|
|
119
136
|
|
|
120
137
|
public async loadModules(moduleNames: string[]) {
|
|
121
138
|
if (moduleNames.length === 0) return;
|
|
139
|
+
const modulesMeta = this._ensureModulesMeta();
|
|
122
140
|
const promises: Promise<IModuleResource>[] = [];
|
|
123
141
|
const moduleNamesLoading: string[] = [];
|
|
124
142
|
for (const moduleName of moduleNames) {
|
|
125
|
-
const module =
|
|
143
|
+
const module = modulesMeta.modules[moduleName];
|
|
126
144
|
if (!module) throw new Error(`module not found: ${moduleName}`);
|
|
127
145
|
const moduleResource = module.resource as any;
|
|
128
146
|
if (typeof moduleResource === 'function') {
|
|
@@ -137,13 +155,14 @@ export class SysModule extends BeanSimple {
|
|
|
137
155
|
const modulesResource = await Promise.all(promises);
|
|
138
156
|
for (let i = 0; i < modulesResource.length; i++) {
|
|
139
157
|
const moduleName = moduleNamesLoading[i];
|
|
140
|
-
|
|
158
|
+
modulesMeta.modules[moduleName].resource = modulesResource[i];
|
|
141
159
|
}
|
|
142
160
|
}
|
|
143
161
|
|
|
144
162
|
private async _requireAllSpecifics(capabilityName: 'preload' | 'monkey' | 'sync') {
|
|
145
|
-
const
|
|
146
|
-
|
|
163
|
+
const modulesMeta = this._ensureModulesMeta();
|
|
164
|
+
const moduleNames = modulesMeta.moduleNames.filter(moduleName => {
|
|
165
|
+
const module = modulesMeta.modules[moduleName];
|
|
147
166
|
return module.info.capabilities?.[capabilityName];
|
|
148
167
|
});
|
|
149
168
|
if (moduleNames.length > 0) {
|
|
@@ -152,14 +171,15 @@ export class SysModule extends BeanSimple {
|
|
|
152
171
|
.debug(`modules ${capabilityName}: ${moduleNames.join(',')}`);
|
|
153
172
|
}
|
|
154
173
|
for (const moduleName of moduleNames) {
|
|
155
|
-
const module =
|
|
174
|
+
const module = modulesMeta.modules[moduleName];
|
|
156
175
|
await this._install(moduleName, module);
|
|
157
176
|
}
|
|
158
177
|
}
|
|
159
178
|
|
|
160
179
|
private async _requireAllOthers() {
|
|
161
|
-
|
|
162
|
-
|
|
180
|
+
const modulesMeta = this._ensureModulesMeta();
|
|
181
|
+
for (const moduleName of modulesMeta.moduleNames) {
|
|
182
|
+
const module = modulesMeta.modules[moduleName];
|
|
163
183
|
const info = module.info;
|
|
164
184
|
const shouldInstall =
|
|
165
185
|
!info.capabilities?.monkey && !info.capabilities?.sync && !info.capabilities?.preload;
|
|
@@ -273,6 +293,8 @@ export class SysModule extends BeanSimple {
|
|
|
273
293
|
moduleTarget?: IModule,
|
|
274
294
|
...monkeyData: any[]
|
|
275
295
|
) {
|
|
296
|
+
const modulesMeta = this.modulesMeta;
|
|
297
|
+
if (!modulesMeta) return;
|
|
276
298
|
// self: main
|
|
277
299
|
if (moduleTarget) {
|
|
278
300
|
const mainInstance = this.mainInstances[moduleTarget.info.relativeName];
|
|
@@ -281,8 +303,8 @@ export class SysModule extends BeanSimple {
|
|
|
281
303
|
}
|
|
282
304
|
}
|
|
283
305
|
// module monkey
|
|
284
|
-
await forEach(
|
|
285
|
-
const moduleMonkey: IModule =
|
|
306
|
+
await forEach(modulesMeta.moduleNames, order, async key => {
|
|
307
|
+
const moduleMonkey: IModule = modulesMeta.modules[key];
|
|
286
308
|
if (moduleMonkey.info.capabilities?.monkey) {
|
|
287
309
|
const monkeyInstance = this.monkeyInstances[key];
|
|
288
310
|
if (monkeyInstance && monkeyInstance[monkeyName]) {
|
|
@@ -316,6 +338,8 @@ export class SysModule extends BeanSimple {
|
|
|
316
338
|
moduleTarget?: IModule,
|
|
317
339
|
...monkeyData: any[]
|
|
318
340
|
) {
|
|
341
|
+
const modulesMeta = this.modulesMeta;
|
|
342
|
+
if (!modulesMeta) return;
|
|
319
343
|
// self: main
|
|
320
344
|
if (moduleTarget) {
|
|
321
345
|
const mainInstance = this.mainInstances[moduleTarget.info.relativeName];
|
|
@@ -324,8 +348,8 @@ export class SysModule extends BeanSimple {
|
|
|
324
348
|
}
|
|
325
349
|
}
|
|
326
350
|
// module monkey
|
|
327
|
-
forEachSync(
|
|
328
|
-
const moduleMonkey: IModule =
|
|
351
|
+
forEachSync(modulesMeta.moduleNames, order, key => {
|
|
352
|
+
const moduleMonkey: IModule = modulesMeta.modules[key];
|
|
329
353
|
if (moduleMonkey.info.capabilities?.monkey) {
|
|
330
354
|
const monkeyInstance = this.monkeyInstances[key];
|
|
331
355
|
if (monkeyInstance && monkeyInstance[monkeyName]) {
|
package/src/core/sys/sys.ts
CHANGED
|
@@ -96,11 +96,12 @@ export class ZovaSys {
|
|
|
96
96
|
viteHot.on('vite:beforeFullReload', hook);
|
|
97
97
|
}
|
|
98
98
|
if (process.env.CLIENT && typeof window !== 'undefined') {
|
|
99
|
-
const hook = () => {
|
|
99
|
+
const hook = (event: PageTransitionEvent) => {
|
|
100
|
+
if (event.persisted) return;
|
|
100
101
|
this.close();
|
|
101
|
-
window.removeEventListener('
|
|
102
|
+
window.removeEventListener('pagehide', hook);
|
|
102
103
|
};
|
|
103
|
-
window.addEventListener('
|
|
104
|
+
window.addEventListener('pagehide', hook);
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|