Commit 5c61c08d authored by nanahira's avatar nanahira

rework register sequence

parent 633fb72f
...@@ -146,8 +146,8 @@ export function DefinePlugin<T>( ...@@ -146,8 +146,8 @@ export function DefinePlugin<T>(
} }
_registerDeclarationsProcess( _registerDeclarationsProcess(
methodKey: keyof C & string,
ctx: Context, ctx: Context,
methodKey: keyof C & string,
view: Record<string, any> = {}, view: Record<string, any> = {},
) { ) {
const result = this.__registrar.register(ctx, methodKey, false, view); const result = this.__registrar.register(ctx, methodKey, false, view);
...@@ -163,33 +163,14 @@ export function DefinePlugin<T>( ...@@ -163,33 +163,14 @@ export function DefinePlugin<T>(
} }
} }
_registerDeclarationsResolving(
methodKey: keyof C & string,
view: Record<string, any> = {},
) {
const ctx = this.__registrar.getScopeContext(
this.__ctx,
methodKey,
false,
);
const sub = this.__registrar
.runLayers(
ctx,
(innerCtx) =>
this._registerDeclarationsProcess(methodKey, innerCtx, view),
methodKey,
)
.subscribe();
this.__disposables.push(() => sub.unsubscribe());
}
_registerDeclarationsWithStack( _registerDeclarationsWithStack(
ctx: Context,
methodKey: keyof C & string, methodKey: keyof C & string,
stack: ControlType[], stack: ControlType[],
existing: Record<string, any> = {}, existing: Record<string, any> = {},
) { ) {
if (!stack.length) { if (!stack.length) {
return this._registerDeclarationsResolving(methodKey, existing); return this._registerDeclarationsProcess(ctx, methodKey, existing);
} }
const rest = [...stack]; const rest = [...stack];
const control = rest.pop(); const control = rest.pop();
...@@ -199,6 +180,7 @@ export function DefinePlugin<T>( ...@@ -199,6 +180,7 @@ export function DefinePlugin<T>(
if (!(control as ControlType<'if'>).condition(this, existing)) if (!(control as ControlType<'if'>).condition(this, existing))
return; return;
return this._registerDeclarationsWithStack( return this._registerDeclarationsWithStack(
ctx,
methodKey, methodKey,
rest, rest,
existing, existing,
...@@ -208,7 +190,7 @@ export function DefinePlugin<T>( ...@@ -208,7 +190,7 @@ export function DefinePlugin<T>(
this, this,
existing, existing,
)) { )) {
this._registerDeclarationsWithStack(methodKey, rest, { this._registerDeclarationsWithStack(ctx, methodKey, rest, {
...existing, ...existing,
...view, ...view,
}); });
...@@ -217,17 +199,35 @@ export function DefinePlugin<T>( ...@@ -217,17 +199,35 @@ export function DefinePlugin<T>(
} }
} }
_registerDeclarationsFor(methodKey: keyof C & string) { _registerDeclarationsFor(ctx: Context, methodKey: keyof C & string) {
const scopeCtx = this.__registrar.getScopeContext(
this.__ctx,
methodKey,
false,
);
const stack = reflector.getArray('KoishiControl', this, methodKey); const stack = reflector.getArray('KoishiControl', this, methodKey);
return this._registerDeclarationsWithStack(methodKey, stack); const sub = this.__registrar
.runLayers(
scopeCtx,
(innerCtx) =>
this._registerDeclarationsWithStack(innerCtx, methodKey, stack),
methodKey,
)
.subscribe();
scopeCtx.on('dispose', () => sub.unsubscribe());
} }
_registerDeclarations() { _registerDeclarations() {
const methodKeys = const methodKeys =
this.__registrar.getAllFieldsToRegister() as (keyof C & string)[]; this.__registrar.getAllFieldsToRegister() as (keyof C & string)[];
methodKeys.forEach((methodKey) => const sub = this.__registrar
this._registerDeclarationsFor(methodKey), .runLayers(this.__ctx, (innerCtx) =>
); methodKeys.forEach((methodKey) =>
this._registerDeclarationsFor(innerCtx, methodKey),
),
)
.subscribe();
this.__disposables.push(() => sub.unsubscribe());
} }
_getProvidingServices() { _getProvidingServices() {
......
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