mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix #1133
This commit is contained in:
2 files changed
+12
-3
No files matched your search
@@ -48,6 +48,7 @@ export class Loader extends Service {
|
|||||||
public state: Record<string, Fiber> = Object.create(null);
|
public state: Record<string, Fiber> = Object.create(null);
|
||||||
public suspend = false;
|
public suspend = false;
|
||||||
public cache: Record<string, string> = Object.create(null);
|
public cache: Record<string, string> = Object.create(null);
|
||||||
|
private schemaCache = new WeakMap<Schema<any>, Record<string, Schema<any>>>();
|
||||||
// public warnings: Record<string, string> = Object.create(null);
|
// public warnings: Record<string, string> = Object.create(null);
|
||||||
|
|
||||||
static inject = ['setting', 'timer', 'i18n', 'logger'];
|
static inject = ['setting', 'timer', 'i18n', 'logger'];
|
||||||
@@ -94,12 +95,18 @@ export class Loader extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildSchema(schema: Schema<any>, scope?: string) {
|
||||||
|
if (!scope) return schema;
|
||||||
|
const cache = this.schemaCache.get(schema) || {};
|
||||||
|
cache[scope] ||= Schema.object({ [scope]: schema });
|
||||||
|
this.schemaCache.set(schema, cache);
|
||||||
|
return cache[scope];
|
||||||
|
}
|
||||||
|
|
||||||
async resolveConfig(plugin: any, configScope: string, dynamic = true) {
|
async resolveConfig(plugin: any, configScope: string, dynamic = true) {
|
||||||
const schema = plugin['Config'] || plugin['schema'];
|
const schema = plugin['Config'] || plugin['schema'];
|
||||||
if (!schema) return Object.freeze({});
|
if (!schema) return Object.freeze({});
|
||||||
const schemaRequest = configScope ? Schema.object({
|
const schemaRequest = this.buildSchema(schema, configScope);
|
||||||
[configScope]: schema,
|
|
||||||
}) : schema;
|
|
||||||
await this.ctx.setting._tryMigrateConfig(schemaRequest);
|
await this.ctx.setting._tryMigrateConfig(schemaRequest);
|
||||||
const res = this.ctx.setting.requestConfig(schemaRequest, dynamic);
|
const res = this.ctx.setting.requestConfig(schemaRequest, dynamic);
|
||||||
return configScope ? res[configScope] : res;
|
return configScope ? res[configScope] : res;
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ export class SettingService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestConfig<T, S>(s: Schema<T, S>, dynamic = true): S {
|
requestConfig<T, S>(s: Schema<T, S>, dynamic = true): S {
|
||||||
|
if (!this.settings.includes(s)) {
|
||||||
this.ctx.effect(() => {
|
this.ctx.effect(() => {
|
||||||
logger.debug('Loading config', s);
|
logger.debug('Loading config', s);
|
||||||
this.settings.push(s);
|
this.settings.push(s);
|
||||||
@@ -160,6 +161,7 @@ export class SettingService extends Service {
|
|||||||
this._applySchema();
|
this._applySchema();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
let curValue = s(this.systemConfig);
|
let curValue = s(this.systemConfig);
|
||||||
if (!dynamic) return curValue;
|
if (!dynamic) return curValue;
|
||||||
this.ctx.on('system/setting', () => {
|
this.ctx.on('system/setting', () => {
|
||||||
|
|||||||
Reference in new issue
Block a user