-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test2.ts
52 lines (31 loc) 路 838 Bytes
/
test2.ts
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
46
47
48
49
50
51
52
import { Evt, Ctx } from "../lib/index.ts";
type T = string;
let evt = new Evt<T>();
//evt.enableTrace("evt");
let evtProxy = new Evt<T>();
//evtProxy.enableTrace("evtProxy");
{
const map = new Map<string, Ctx<void>>();
evt.attach(data => {
if (!map.has(data)) {
map.set(data, Evt.newCtx());
}
if (!evtProxy.evtAttach.postCount) {
evtProxy.evtAttach.attachOnce(map.get(data)!, () => evtProxy.post(data));
} else {
evtProxy.post(data);
}
});
}
for (let char of ["a", "b", "c", "d", "e"])
evt.post(char);
let alphabet = "";
evtProxy.attach(data => {
alphabet += data;
});
for (let char of ["f", "g", "h"])
evt.post(char);
//cSpell: disable
console.assert(alphabet === "abcdefgh");
//cSpell: enable
console.log("PASS");