mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-04 23:19:09 +08:00
27 lines
668 B
TypeScript
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
|
|
}
|
|
}
|