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
  • Returns
  • Parameters
  • Examples
Edit on GitHub
  1. API Documentation
  2. Evt<T>

evt.detach(ctx?)

Similar to EventEmitter.prototype.removeListener()

Previousevt.isHandled(data)Nextevt.enableTrace(...)

Last updated 2 years ago

Detach all handlers from the Evt or all Evt's handler that are bound to a given context.

The prefered way of detaching handler in TS-EVT is via .

Calling this method without passing a context argument is almost never a good idea. An Evt instance should be sharable by modules that are isolated one another. If a module take the liberty to call evt.detach() it can brek the code elswhere.

To chery pick the handlers to detach use or ``

Returns

Handler<T,any>[] array of Handler that have been detached.

Parameters

ctx?: Ctx If is provided only Handler bound to the given context will be removed.

Examples

To detach all handlers at once:

const evtText = new Evt<string>();
//detach with no argument will detach all handlers (attach, attachOnce, waitFor... )
evtText.detach();

Using a context argument

import { Evt } from "evt";

const evtText = new Evt<string>();

evtText.attachOnce(text=> console.log(`Hello ${text}`));

const ctx = Evt.newCtx();

evtText.attach(
    ctx,
    _text => console.assert(false,"never")
);

evtText.attachOnce(
    ctx,
    _text => console.assert(false,"never")
);

evtText.detach(ctx);

//"Hello World" will be printed
evtText.post("World");

📖
Ctx<T>
evt.getHandlers()
ctx.getHandlers()
Ctx
Run the example