better typization for cef
This commit is contained in:
parent
95352908f8
commit
1766f047a4
@ -1,16 +1,19 @@
|
|||||||
import rpc from 'rage-rpc'
|
import rpc from 'rage-rpc'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
_CefEventHasArgs,
|
||||||
|
_ClientEventHasArgs,
|
||||||
|
_ServerEventHasArgs,
|
||||||
RageFW_CefArguments,
|
RageFW_CefArguments,
|
||||||
RageFW_CefCallback,
|
RageFW_CefCallback,
|
||||||
RageFW_CefReturn,
|
RageFW_CefReturn,
|
||||||
RageFW_ClientArguments,
|
RageFW_ClientArguments,
|
||||||
RageFW_ClientReturn,
|
RageFW_ClientReturn,
|
||||||
RageFW_ServerArguments,
|
|
||||||
RageFW_ServerReturn,
|
|
||||||
RageFW_ICustomCefEvent,
|
RageFW_ICustomCefEvent,
|
||||||
RageFW_ICustomClientEvent,
|
RageFW_ICustomClientEvent,
|
||||||
RageFW_ICustomServerEvent,
|
RageFW_ICustomServerEvent,
|
||||||
|
RageFW_ServerArguments,
|
||||||
|
RageFW_ServerReturn,
|
||||||
} from './types'
|
} from './types'
|
||||||
|
|
||||||
class Cef {
|
class Cef {
|
||||||
@ -23,21 +26,27 @@ class Cef {
|
|||||||
|
|
||||||
public trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
public trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
args: RageFW_CefArguments<EventName>,
|
...args: _CefEventHasArgs<EventName> extends true
|
||||||
|
? [RageFW_CefArguments<EventName>]
|
||||||
|
: []
|
||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<RageFW_CefReturn<EventName>> {
|
||||||
return rpc.call(eventName, args)
|
return rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerServer<EventName extends keyof RageFW_ICustomServerEvent>(
|
public triggerServer<EventName extends keyof RageFW_ICustomServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
args: RageFW_ServerArguments<EventName>,
|
...args: _ServerEventHasArgs<EventName> extends true
|
||||||
|
? [RageFW_ServerArguments<EventName>]
|
||||||
|
: []
|
||||||
): Promise<RageFW_ServerReturn<EventName>> {
|
): Promise<RageFW_ServerReturn<EventName>> {
|
||||||
return rpc.callServer(eventName, args)
|
return rpc.callServer(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerClient<EventName extends keyof RageFW_ICustomClientEvent>(
|
public triggerClient<EventName extends keyof RageFW_ICustomClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
args: RageFW_ClientArguments<EventName>,
|
...args: _ClientEventHasArgs<EventName> extends true
|
||||||
|
? [RageFW_ClientArguments<EventName>]
|
||||||
|
: []
|
||||||
): Promise<RageFW_ClientReturn<EventName>> {
|
): Promise<RageFW_ClientReturn<EventName>> {
|
||||||
return rpc.callClient(eventName, args)
|
return rpc.callClient(eventName, args)
|
||||||
}
|
}
|
||||||
|
@ -30,3 +30,10 @@ export type RageFW_CefReturn<K extends RageFW_CefEvent> = ReturnType<
|
|||||||
export type RageFW_CefCallback<K extends keyof RageFW_ICustomCefEvent> = (
|
export type RageFW_CefCallback<K extends keyof RageFW_ICustomCefEvent> = (
|
||||||
args: RageFW_CefArguments<K>,
|
args: RageFW_CefArguments<K>,
|
||||||
) => RageFW_CefReturn<K>
|
) => RageFW_CefReturn<K>
|
||||||
|
|
||||||
|
export type _CefEventHasArgs<EventName extends keyof RageFW_ICustomCefEvent> =
|
||||||
|
keyof RageFW_ICustomCefEvent extends never
|
||||||
|
? false
|
||||||
|
: Parameters<RageFW_ICustomCefEvent[EventName]>[0] extends undefined
|
||||||
|
? false
|
||||||
|
: true
|
||||||
|
@ -22,3 +22,11 @@ export type RageFW_ClientArguments<K extends RageFW_ClientEvent> = Parameters<
|
|||||||
export type RageFW_ClientReturn<K extends RageFW_ClientEvent> = ReturnType<
|
export type RageFW_ClientReturn<K extends RageFW_ClientEvent> = ReturnType<
|
||||||
RageFW_ICustomClientEvent[K]
|
RageFW_ICustomClientEvent[K]
|
||||||
>
|
>
|
||||||
|
|
||||||
|
export type _ClientEventHasArgs<
|
||||||
|
EventName extends keyof RageFW_ICustomClientEvent,
|
||||||
|
> = keyof RageFW_ICustomClientEvent extends never
|
||||||
|
? false
|
||||||
|
: Parameters<RageFW_ICustomClientEvent[EventName]>[0] extends undefined
|
||||||
|
? false
|
||||||
|
: true
|
||||||
|
@ -22,3 +22,11 @@ export type RageFW_ServerArguments<K extends RageFW_ServerEvent> = Parameters<
|
|||||||
export type RageFW_ServerReturn<K extends RageFW_ServerEvent> = ReturnType<
|
export type RageFW_ServerReturn<K extends RageFW_ServerEvent> = ReturnType<
|
||||||
RageFW_ICustomServerEvent[K]
|
RageFW_ICustomServerEvent[K]
|
||||||
>
|
>
|
||||||
|
|
||||||
|
export type _ServerEventHasArgs<
|
||||||
|
EventName extends keyof RageFW_ICustomServerEvent,
|
||||||
|
> = keyof RageFW_ICustomServerEvent extends never
|
||||||
|
? false
|
||||||
|
: Parameters<RageFW_ICustomServerEvent[EventName]>[0] extends undefined
|
||||||
|
? false
|
||||||
|
: true
|
||||||
|
Loading…
Reference in New Issue
Block a user