Files
PicList/src/main/events/rpc/router.ts
T

27 lines
668 B
TypeScript

import { IRPCType, IRPCActionType } from '#/types/enum'
interface IBatchAddParams {
action: IRPCActionType
handler: IRPCHandler<any>
type?: IRPCType
}
export class RPCRouter implements IRPCRouter {
private routeMap: IRPCRoutes = new Map()
add = <T>(action: IRPCActionType, handler: IRPCHandler<T>, type: IRPCType = IRPCType.SEND): this => {
this.routeMap.set(action, { handler, type })
return this
}
addBatch = (params: IBatchAddParams[]): this => {
for (const { action, handler, type = IRPCType.SEND } of params) {
this.routeMap.set(action, { handler, type })
}
return this
}
routes () {
return this.routeMap
}
}