Dwip
This commit is contained in:
1 parent
c367d3f3ca
commit
2bc148342d
3 files changed
+39
-18
No files matched your search
+18
-18
@@ -1,34 +1,34 @@
|
||||
enum OpCode {
|
||||
PING,
|
||||
HELLO,
|
||||
MOVE,
|
||||
PING,
|
||||
HELLO,
|
||||
MOVE,
|
||||
}
|
||||
|
||||
type HelloEvent = {
|
||||
name: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
type MoveEvent = {
|
||||
x: number;
|
||||
y: number;
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
|
||||
type OpArgsMapping = {
|
||||
[OpCode.PING]: null;
|
||||
[OpCode.HELLO]: HelloEvent;
|
||||
[OpCode.MOVE]: MoveEvent;
|
||||
[OpCode.PING]: {};
|
||||
[OpCode.HELLO]: HelloEvent;
|
||||
[OpCode.MOVE]: MoveEvent;
|
||||
};
|
||||
|
||||
class WebSocketClient {
|
||||
public op<TOp extends OpCode, TArgs extends OpArgsMapping[TOp]>(
|
||||
op: TOp,
|
||||
args: TArgs,
|
||||
) {
|
||||
// ...
|
||||
}
|
||||
public op<TOp extends OpCode, TArgs extends OpArgsMapping[TOp]>(
|
||||
op: TOp,
|
||||
args: TArgs,
|
||||
) {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const client = new WebSocketClient();
|
||||
client.op(OpCode.HELLO, { name: "foo" });
|
||||
function main_ws() {
|
||||
const client = new WebSocketClient();
|
||||
client.op(OpCode.PING, {});
|
||||
}
|
||||
Reference in new issue
Block a user