Skip to main content
variable listenOnce
import { listenOnce } from "https://deno.land/x/30_seconds_of_typescript@v1.0.1/util.ts";

Adds an event listener to an element that will only run the callback the first time the event is triggered.

Use EventTarget.addEventListener() to add an event listener to an element, storing the reference in a variable. Use a condition to call fn only the first time the listener is triggered.

type

<E extends IEventListener>(
el: E,
evt: string,
fn: Func,
) => unknown