Commit f337c600 authored by nanahira's avatar nanahira

fix no register in map plugin

parent 4678eb38
...@@ -28,18 +28,17 @@ export class MapPluginBase<M extends Dict<PluginClass>> ...@@ -28,18 +28,17 @@ export class MapPluginBase<M extends Dict<PluginClass>>
onApply() { onApply() {
const dict = this._getDict(); const dict = this._getDict();
for (const [key, plugin] of Object.entries(dict)) { for (const [key, plugin] of Object.entries(dict)) {
if (this.config[key] != null) { if (this.config[key]?.[NoRegisterSym]) continue;
const ctx = const ctx =
typeof this.config[key] === 'object' typeof this.config[key] === 'object'
? this.ctx.select(this.config[key]) ? this.ctx.select(this.config[key])
: this.ctx; : this.ctx;
const clonedPlugin = ClonePlugin( const clonedPlugin = ClonePlugin(
plugin, plugin,
`${this.constructor.name}_${plugin.name}_dict_${key}`, `${this.constructor.name}_${plugin.name}_dict_${key}`,
(o) => this._instanceMap.set(key, o), (o) => this._instanceMap.set(key, o),
); );
ctx.plugin(clonedPlugin, this.config[key]); ctx.plugin(clonedPlugin, this.config[key]);
}
} }
} }
...@@ -49,6 +48,8 @@ export class MapPluginBase<M extends Dict<PluginClass>> ...@@ -49,6 +48,8 @@ export class MapPluginBase<M extends Dict<PluginClass>>
} }
} }
const NoRegisterSym = '__no_register' as const;
function MappedConfig<M extends Dict<PluginClass>>( function MappedConfig<M extends Dict<PluginClass>>(
dict: M, dict: M,
): ClassType<MapPluginToConfig<M>> { ): ClassType<MapPluginToConfig<M>> {
...@@ -60,10 +61,10 @@ function MappedConfig<M extends Dict<PluginClass>>( ...@@ -60,10 +61,10 @@ function MappedConfig<M extends Dict<PluginClass>>(
plugin['Config'] || plugin['Config'] ||
plugin['schema'] || plugin['schema'] ||
reflector.get('KoishiPredefineSchema', plugin); reflector.get('KoishiPredefineSchema', plugin);
SchemaProperty({ type: propertySchemaClass, default: undefined })( SchemaProperty({
PropertySchema.prototype, type: propertySchemaClass,
key, default: { [NoRegisterSym]: true },
); })(PropertySchema.prototype, key);
} }
return PropertySchema; return PropertySchema;
} }
......
...@@ -19,7 +19,7 @@ class DressPlugin extends StarterPlugin(DressConfig) { ...@@ -19,7 +19,7 @@ class DressPlugin extends StarterPlugin(DressConfig) {
} }
class SkirtConfig { class SkirtConfig {
@SchemaProperty() @SchemaProperty({ default: 'S' })
size: string; size: string;
} }
...@@ -60,4 +60,15 @@ describe('register map plugin instance', () => { ...@@ -60,4 +60,15 @@ describe('register map plugin instance', () => {
expect(await app.command('skirtSize').execute({})).toBe('XL'); expect(await app.command('skirtSize').execute({})).toBe('XL');
expect(await app.command('wearingStrip').execute({})).toBe('pink'); expect(await app.command('wearingStrip').execute({})).toBe('pink');
}); });
it('should partial register', async () => {
const app = new App();
app.plugin(WearingPlugin, {
dress: { color: 'red' },
strip: 'pink',
});
await app.start();
expect(await app.command('dressColor').execute({})).toBe('red');
expect(await app.command('wearingStrip').execute({})).toBe('pink');
expect(await app.command('skirtSize').execute({})).toBeFalsy();
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment