For the complete documentation index, see llms.txt. This page is also available as Markdown.

evt.detach(ctx?)

Similar to EventEmitter.prototype.removeListener()

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 Ctx<T> .

To chery pick the handlers to detach use evt.getHandlers() or ctx.getHandlers()``

Returns

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

Parameters

ctx?: Ctx If Ctx 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");

Run the example

Last updated

Was this helpful?