This commit is contained in:
undefined committed 2026-02-19 17:38:10 +08:00
1 parent 1360c280b9
commit 6d639f76f2
2 files changed
+21 -12

No files matched your search

+10 -3
View File
@@ -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;
+11 -9
View File
@@ -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', () => {