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>>
onApply() {
const dict = this._getDict();
for (const [key, plugin] of Object.entries(dict)) {
if (this.config[key] != null) {
const ctx =
typeof this.config[key] === 'object'
? this.ctx.select(this.config[key])
: this.ctx;
const clonedPlugin = ClonePlugin(
plugin,
`${this.constructor.name}_${plugin.name}_dict_${key}`,
(o) => this._instanceMap.set(key, o),
);
ctx.plugin(clonedPlugin, this.config[key]);
}
if (this.config[key]?.[NoRegisterSym]) continue;
const ctx =
typeof this.config[key] === 'object'
? this.ctx.select(this.config[key])
: this.ctx;
const clonedPlugin = ClonePlugin(
plugin,
`${this.constructor.name}_${plugin.name}_dict_${key}`,
(o) => this._instanceMap.set(key, o),
);
ctx.plugin(clonedPlugin, this.config[key]);
}
}
......@@ -49,6 +48,8 @@ export class MapPluginBase<M extends Dict<PluginClass>>
}
}
const NoRegisterSym = '__no_register' as const;
function MappedConfig<M extends Dict<PluginClass>>(
dict: M,
): ClassType<MapPluginToConfig<M>> {
......@@ -60,10 +61,10 @@ function MappedConfig<M extends Dict<PluginClass>>(
plugin['Config'] ||
plugin['schema'] ||
reflector.get('KoishiPredefineSchema', plugin);
SchemaProperty({ type: propertySchemaClass, default: undefined })(
PropertySchema.prototype,
key,
);
SchemaProperty({
type: propertySchemaClass,
default: { [NoRegisterSym]: true },
})(PropertySchema.prototype, key);
}
return PropertySchema;
}
......
......@@ -19,7 +19,7 @@ class DressPlugin extends StarterPlugin(DressConfig) {
}
class SkirtConfig {
@SchemaProperty()
@SchemaProperty({ default: 'S' })
size: string;
}
......@@ -60,4 +60,15 @@ describe('register map plugin instance', () => {
expect(await app.command('skirtSize').execute({})).toBe('XL');
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