EVT
Search…
evt.getHandlers()
List all handlers attached to the Evt. Returns an array of Handler<T,any>.
Here a use case detaching all handlers that uses a given matcher:
1
import { Evt } from "evt";
2
3
const evtShape = new Evt<Shape>();
4
5
evtShape.attach(
6
matchCircle,
7
circle => console.log("1:", circle)
8
);
9
10
evtShape.attachOnce(
11
matchCircle,
12
circle => console.log("2:", circle)
13
);
14
15
evtShape.waitFor(matchCircle)
16
.then(circle => console.log("3:", circle))
17
;
18
19
//Only handler that does not use matchCircle as operator.
20
evtShape.attach(circle => console.log("4:", circle))
21
22
23
evtShape.getHandlers()
24
.filter(({ op }) => op === matchCircle)
25
.forEach(({ detach }) => detach())
26
;
27
28
//Prints only "4: ..." other handlers are detached.
29
evtShape.post({ "type": "CIRCLE", "radius": 300 });
Copied!
handler.detach(callback)
To detach all the handlers using a given callback function as we do with EventEmitter:
1
import { Evt } from "evt";
2
3
const evtText = new Evt<string>();
4
5
const callback = (text: string) => console.log(text);
6
7
evtText.attach(callback);
8
9
evtText.post("Foo"); //Prints "Foo"
10
11
evtText.getHandlers()
12
.filter(handler => handler.callback === callback)
13
.forEach(({detach})=> detach())
14
;
15
16
evtText.post("Foo"); //Prints nothing
Copied!
Last modified 1yr ago
Copy link