-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
45 lines (33 loc) · 1.04 KB
/
test.ts
File metadata and controls
45 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { BaseEvent, EventSystem } from "./src";
// test the eventsystem
EventSystem.debug = true;
class TestEvent extends BaseEvent {
constructor() {
super("TestEvent");
}
}
class MapTestEvent extends BaseEvent {
constructor(public data: Map<string, number>) {
super("MapTestEvent");
}
}
const eventSystem = new EventSystem();
eventSystem.registerEvent<TestEvent>("TestEvent", (event) => {
console.log("TestEvent received");
console.log(event);
});
eventSystem.registerEvent<MapTestEvent>("MapTestEvent", (event) => {
console.log("MapTestEvent received");
console.log(event);
});
eventSystem.emit(new TestEvent());
// Test strigified Maps
const testMap = new Map<string, number>();
testMap.set("abc", 123);
testMap.set("def", 456);
const strigifiedEvent = new MapTestEvent(testMap).stringify();
eventSystem.parse(strigifiedEvent);
// Test unregistered event
eventSystem.unregisterEvent("TestEvent");
console.log("TestEvent unregistered");
eventSystem.emit(new TestEvent()); // should not be received