Commit 17dc75ff authored by nanahira's avatar nanahira

put decorateMethod into info

parent 20ed2d33
...@@ -57,9 +57,10 @@ export class RegistrarAspect<Ctx extends Context, T = any> { ...@@ -57,9 +57,10 @@ export class RegistrarAspect<Ctx extends Context, T = any> {
const data = this.registrar.reflector.get('CordisRegister', this.obj, key); const data = this.registrar.reflector.get('CordisRegister', this.obj, key);
if (!data) return; if (!data) return;
const specificCtx = this.getScopeContext(ctx, key, extraView, false); const specificCtx = this.getScopeContext(ctx, key, extraView, false);
const view = { ...this.view, ...extraView };
const result = data.run( const result = data.run(
{ ...this.view, ...extraView }, view,
specificCtx, { ctx: specificCtx, obj: this.obj, key, view },
extractObjectMethod(this.obj, key), extractObjectMethod(this.obj, key),
); );
return { return {
......
...@@ -57,11 +57,18 @@ export namespace Registrar { ...@@ -57,11 +57,18 @@ export namespace Registrar {
R = any, R = any,
> = (ctx: Ctx, param: P, ...args: A) => R; > = (ctx: Ctx, param: P, ...args: A) => R;
export interface MethodResolveInfo<Ctx extends Context> {
ctx: Ctx;
obj: any;
key: string;
view: any;
}
export type MethodResolver< export type MethodResolver<
Ctx extends Context, Ctx extends Context,
A extends any[] = any[], A extends any[] = any[],
F extends (...args: any[]) => any = (...args: any[]) => any, F extends (...args: any[]) => any = (...args: any[]) => any,
> = DecorateFunctionParamSingle<Ctx, F, A>; > = (info: MethodResolveInfo<Ctx>, fun: F, ...args: A) => any;
export type MethodMeta<Ctx extends Context> = RegisterMeta< export type MethodMeta<Ctx extends Context> = RegisterMeta<
MethodResolver<Ctx>, MethodResolver<Ctx>,
...@@ -422,13 +429,13 @@ export class Registrar<Ctx extends Context> { ...@@ -422,13 +429,13 @@ export class Registrar<Ctx extends Context> {
return { return {
UseEvent: this.decorateMethod( UseEvent: this.decorateMethod(
'on', 'on',
(ctx, fun, event: keyof GetEvents<Ctx>, prepend?: boolean) => ({ ctx }, fun, event: keyof GetEvents<Ctx>, prepend?: boolean) =>
ctx.on(event as any, fun, prepend), ctx.on(event as any, fun, prepend),
), ),
UsePlugin: this.decorateMethod( UsePlugin: this.decorateMethod(
'plugin', 'plugin',
( (
ctx, { ctx },
fun: ( fun: (
...args: any[] ...args: any[]
) => Awaitable<PluginRegistrar.PluginDefinition<Ctx>>, ) => Awaitable<PluginRegistrar.PluginDefinition<Ctx>>,
...@@ -447,7 +454,7 @@ export class Registrar<Ctx extends Context> { ...@@ -447,7 +454,7 @@ export class Registrar<Ctx extends Context> {
} }
}, },
), ),
Apply: this.decorateMethod('apply', (ctx, fun) => fun()), Apply: this.decorateMethod('apply', (info, fun) => fun()),
}; };
} }
......
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