mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: fix #1133
This commit is contained in:
2 files changed
+21
-12
No files matched your search
@@ -48,6 +48,7 @@ export class Loader extends Service {
|
||||
public state: Record<string, Fiber> = Object.create(null);
|
||||
public suspend = false;
|
||||
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);
|
||||
|
||||
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) {
|
||||
const schema = plugin['Config'] || plugin['schema'];
|
||||
if (!schema) return Object.freeze({});
|
||||
const schemaRequest = configScope ? Schema.object({
|
||||
[configScope]: schema,
|
||||
}) : schema;
|
||||
const schemaRequest = this.buildSchema(schema, configScope);
|
||||
await this.ctx.setting._tryMigrateConfig(schemaRequest);
|
||||
const res = this.ctx.setting.requestConfig(schemaRequest, dynamic);
|
||||
return configScope ? res[configScope] : res;
|
||||
|
||||
@@ -150,16 +150,18 @@ export class SettingService extends Service {
|
||||
}
|
||||
|
||||
requestConfig<T, S>(s: Schema<T, S>, dynamic = true): S {
|
||||
this.ctx.effect(() => {
|
||||
logger.debug('Loading config', s);
|
||||
this.settings.push(s);
|
||||
this._applySchema();
|
||||
return () => {
|
||||
logger.debug('Unloading config', s);
|
||||
this.settings = this.settings.filter((v) => v !== s);
|
||||
if (!this.settings.includes(s)) {
|
||||
this.ctx.effect(() => {
|
||||
logger.debug('Loading config', s);
|
||||
this.settings.push(s);
|
||||
this._applySchema();
|
||||
};
|
||||
});
|
||||
return () => {
|
||||
logger.debug('Unloading config', s);
|
||||
this.settings = this.settings.filter((v) => v !== s);
|
||||
this._applySchema();
|
||||
};
|
||||
});
|
||||
}
|
||||
let curValue = s(this.systemConfig);
|
||||
if (!dynamic) return curValue;
|
||||
this.ctx.on('system/setting', () => {
|
||||
|
||||
Reference in new issue
Block a user