EVT
Search…
evt.isHandled(data)
Return true if:
    There is at least one handler matching this event data ( at least one handler's callback function will be invoked if the data is posted. )
    There is at least one handler that will be detached if the event data is posted.
1
const evtText = new Evt<string>();
2
3
/*
4
Handle the text starting with 'h'.
5
Ignore all other text, when a text starting with 'g'
6
is posted the handler is detached
7
*/
8
evtText.$attach(
9
text=> text.startsWith("h") ?
10
[ text ] :
11
text.startsWith("g") ? "DETACH" : null,
12
text=> {/* do something with the text */}
13
);
14
15
//"true", start with 'h'
16
console.log(
17
evtText.isHandled("hello world")
18
);
19
20
//"false", do not start with 'h' or 'g'
21
console.log(
22
evtText.isHandled("foo bar")
23
);
24
25
//"true", not matched but will cause the handler to be detached if posted
26
console.log(
27
evtText.isHandled("goodby world")
28
);
Copied!
Last modified 1yr ago
Copy link