進一步完善 Server API

This commit is contained in:
CrescentLeaf
2025-09-06 01:53:09 +08:00
parent c3c332017e
commit b0c67da340
6 changed files with 30 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
import EventCallbackFunction from "../types/EventCallbackFunction.ts"
import ApiManager from "./ApiManager.ts";
import ApiManager from "./ApiManager.ts"
import { CallMethod } from './ApiDeclare.ts'
export default abstract class BaseApi {
abstract getName(): string
@@ -7,7 +8,8 @@ export default abstract class BaseApi {
this.onInit()
}
abstract onInit(): void
registerEvent(name: string, func: EventCallbackFunction) {
ApiManager.addEventListener(this.getName() + "." + name, func)
registerEvent(name: CallMethod, func: EventCallbackFunction) {
if (!name.startsWith(this.getName() + ".")) throw Error("注冊的事件應該與接口集合命名空間相匹配: " + name)
ApiManager.addEventListener(name, func)
}
}