registerMany untyped proposal
This commit is contained in:
parent
788be34951
commit
3f911a7aec
@ -8,6 +8,22 @@ class Server implements RageFW_Server {
|
|||||||
): void {
|
): void {
|
||||||
rpc.register(eventName, callback as rpc.ProcedureListener)
|
rpc.register(eventName, callback as rpc.ProcedureListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public registerMany<EventName extends RageFW_ServerEvent>(events: {
|
||||||
|
[key in EventName]: RageFW_ServerEventCallback<EventName>
|
||||||
|
}): void {
|
||||||
|
Object.keys(events).forEach(eventName =>
|
||||||
|
// unknown[] ?
|
||||||
|
// rpc.register(eventName, (args: unknown[]) =>
|
||||||
|
// Array.isArray(args) ? events[eventName as keyof typeof events](...args) : callback(args),
|
||||||
|
// ),
|
||||||
|
rpc.register(eventName, (args: unknown[]) =>
|
||||||
|
Array.isArray(args)
|
||||||
|
? events[eventName as EventName](args)
|
||||||
|
: events[eventName as EventName](args),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const rage = {
|
export const rage = {
|
||||||
@ -18,14 +34,8 @@ rage.event.register('customServerEvent', (player, arg1, arg2) => {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
// public registerMultiple(events: {
|
rage.event.registerMany({
|
||||||
// [name: string]: (player: PlayerMp, ...args: any[]) => any
|
customServerEvent: (player, arg1, arg2) => {
|
||||||
// }): void
|
return true
|
||||||
//
|
},
|
||||||
// registerMultiple(events: { [name: string]: (...args: any[]) => any }) {
|
})
|
||||||
// Object.entries(events).forEach(([name, callback]) =>
|
|
||||||
// rpc.register(name, (data: any[]) => {
|
|
||||||
// return Array.isArray(data) ? callback(...data) : callback(data)
|
|
||||||
// }),
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
4
shared/server/index.d.ts
vendored
4
shared/server/index.d.ts
vendored
@ -23,4 +23,8 @@ declare class RageFW_Server {
|
|||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ServerEventCallback<EventName>,
|
callback: RageFW_ServerEventCallback<EventName>,
|
||||||
): void
|
): void
|
||||||
|
|
||||||
|
declare registerMany<EventName extends RageFW_ServerEvent>(events: {
|
||||||
|
[key: EventName]: RageFW_ServerEventCallback<EventName>
|
||||||
|
}): void
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user