import { Evt } from "evt";
const evtShape = new Evt<Shape>();
evtShape.attach(
matchCircle,
circle => console.log("1:", circle)
);
evtShape.attachOnce(
matchCircle,
circle => console.log("2:", circle)
);
evtShape.waitFor(matchCircle)
.then(circle => console.log("3:", circle))
;
//Only handler that does not use matchCircle as operator.
evtShape.attach(circle => console.log("4:", circle))
evtShape.getHandlers()
.filter(({ op }) => op === matchCircle)
.forEach(({ detach }) => detach())
;
//Prints only "4: ..." other handlers are detached.
evtShape.post({ "type": "CIRCLE", "radius": 300 });
Equivalent of EventEmitter's handler.detach(callback)
import { Evt } from "evt";
const evtText = new Evt<string>();
const callback = (text: string) => console.log(text);
evtText.attach(callback);
evtText.post("Foo"); //Prints "Foo"
evtText.getHandlers()
.filter(handler => handler.callback === callback)
.forEach(({detach})=> detach())
;
evtText.post("Foo"); //Prints nothing