EVT
GitHubHomePlaygroud
v2
v2
  • 🚀EVT Overview
  • 📖API Documentation
    • Evt<T>
      • Async iterator
      • evt.attach*(...)
      • evt.post*(data)
      • evt.waitFor(...)
      • evt.evt[Attach|Detach]
      • evt.pipe(...)
      • evt.getHandlers()
      • evt.isHandled(data)
      • evt.detach(ctx?)
      • evt.enableTrace(...)
      • evt.setMaxHandlers(n)
      • toStateful(initialState)
      • evt.getStatelessOp(op)
      • Evt.create(initalState?)
      • Evt.newCtx<T>()
      • Evt.getCtx(object)
      • Evt.from<T>(...)
      • Evt.merge([ evt1, evt2, ... ])
      • Evt.loosenType(evt)
      • Evt.factorize(evt)
      • Evt.asPostable(evt)
      • Evt.asNonPostable(evt)
      • Evt.setDefaultMaxHandlers(n)
    • Ctx<T>
    • Operator<T, U> (type)
    • StatefulEvt<T>
    • Helper types
    • Handler<T, U> (type)
  • 🪝React hooks
  • 🔩From EventEmitter to Evt
  • ⬆️v1 -> v2
Powered by GitBook
On this page
Edit on GitHub
  1. API Documentation
  2. Evt<T>

evt.getHandlers()

Previousevt.pipe(...)Nextevt.isHandled(data)

Last updated 2 years ago

List all handlers attached to the Evt. Returns an array of .

Here a use case detaching all handlers that uses a given matcher:

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)

To detach all the handlers using a given callback function as we do with EventEmitter:

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

📖
Handler<T,any>
Run the example
Run the example