tgui-core 5.4.2 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/eventbus.d.ts +35 -15
- package/package.json +1 -1
|
@@ -11,32 +11,52 @@
|
|
|
11
11
|
* and update accordingly.
|
|
12
12
|
*
|
|
13
13
|
* @usage
|
|
14
|
+
*
|
|
15
|
+
* ### First step
|
|
16
|
+
*
|
|
17
|
+
* Create an EventBus with the listeners you want to handle.
|
|
18
|
+
*
|
|
14
19
|
* ```ts
|
|
15
20
|
* const bus = new EventBus(listeners);
|
|
21
|
+
*```
|
|
16
22
|
*
|
|
17
|
-
*
|
|
18
|
-
* const listeners = {
|
|
19
|
-
* 'messageTypeA': (message) => { logger.log(message.payload); },
|
|
20
|
-
* } as const;
|
|
23
|
+
* ### Second step
|
|
21
24
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* logger.log(payload.text);
|
|
25
|
-
* }
|
|
25
|
+
* Next, define the listeners object. These are the event types and their
|
|
26
|
+
* corresponding callbacks.
|
|
26
27
|
*
|
|
28
|
+
* ```ts
|
|
27
29
|
* const listeners = {
|
|
28
|
-
* messageTypeA,
|
|
30
|
+
* 'messageTypeA': handlerA,
|
|
29
31
|
* } as const;
|
|
32
|
+
*```
|
|
33
|
+
*
|
|
34
|
+
* ### Third step
|
|
30
35
|
*
|
|
36
|
+
* Write a handler for the specific message type.
|
|
31
37
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* payload: { text: 'Hello, world!' },
|
|
38
|
+
* ```ts
|
|
39
|
+
* type ExpectedPayloadA = {
|
|
40
|
+
* text: string;
|
|
36
41
|
* };
|
|
37
42
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
43
|
+
* function handlerA(payload: ExpectedPayloadA) {
|
|
44
|
+
* logger.log(payload.text);
|
|
45
|
+
* }
|
|
46
|
+
*```
|
|
47
|
+
|
|
48
|
+
* You can now dispatch the messageTypeA event! If you want to shorten the
|
|
49
|
+
* syntax, you can name the handler function after the incoming event type.
|
|
50
|
+
*
|
|
51
|
+
* ````ts
|
|
52
|
+
* function messageTypeA(payload: ExpectedPayloadA) {
|
|
53
|
+
* logger.log(payload.text);
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* const listeners = {
|
|
57
|
+
* messageTypeA,
|
|
58
|
+
* } as const;
|
|
59
|
+
*
|
|
40
60
|
*/
|
|
41
61
|
export declare class EventBus<TListeners extends Readonly<Record<string, (payload: unknown) => void>>> {
|
|
42
62
|
private listeners;
|
package/package.json
CHANGED