進一步完善 Server API
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user