mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-19 13:10:16 +08:00
Refactor createListenerFunction type and usage
Simplifies the generic type signature of createListenerFunction and updates the way createEventFunction is called, removing unnecessary type parameters and using a direct function call with TypeScript ignore for type checking.
This commit is contained in:
parent
f04ffa5dc6
commit
5cfe479044
@ -78,18 +78,15 @@ export class NTEventWrapper {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
createListenerFunction<T, Listener extends keyof ListenerNamingMapping,
|
createListenerFunction<T> (listenerMainName: string, uniqueCode: string = ''): T {
|
||||||
ListenerMethod extends FuncKeys<ListenerNamingMapping[Listener]>>(listenerMainName: string, uniqueCode: string = ''): T {
|
|
||||||
const existListener = this.listenerManager.get(listenerMainName + uniqueCode);
|
const existListener = this.listenerManager.get(listenerMainName + uniqueCode);
|
||||||
if (!existListener) {
|
if (!existListener) {
|
||||||
const Listener = this.createProxyDispatch(listenerMainName);
|
const Listener = this.createProxyDispatch(listenerMainName);
|
||||||
const ServiceSubName = /^NodeIKernel(.*?)Listener$/.exec(listenerMainName)![1];
|
const ServiceSubName = /^NodeIKernel(.*?)Listener$/.exec(listenerMainName)![1];
|
||||||
const Service = `NodeIKernel${ServiceSubName}Service/addKernel${ServiceSubName}Listener` as `${Listener}/${ListenerMethod}`;
|
const Service = `NodeIKernel${ServiceSubName}Service/addKernel${ServiceSubName}Listener`;
|
||||||
this.createEventFunction<
|
|
||||||
keyof ServiceNamingMapping,
|
// @ts-ignore
|
||||||
FuncKeys<ServiceNamingMapping[keyof ServiceNamingMapping]>,
|
this.createEventFunction(Service)(Listener as T);
|
||||||
(...args: any[]) => any
|
|
||||||
>(Service as `${keyof ServiceNamingMapping}/${FuncKeys<ServiceNamingMapping[keyof ServiceNamingMapping]>}`);
|
|
||||||
this.listenerManager.set(listenerMainName + uniqueCode, Listener);
|
this.listenerManager.set(listenerMainName + uniqueCode, Listener);
|
||||||
return Listener as T;
|
return Listener as T;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user