function / @typed/template/EventHandler

once

Modifies an EventHandler to run only once.

Package version
1.0.0-beta.7
Category
Listener lifetime
Since
1.0.0

Import

import { once } from "@typed/template/EventHandler";

Signatures

export declare function once<Ev extends Event, E = never, R = never>(handler: EventHandler<Ev, E, R>): EventHandler<Ev, E, R>;

Why

once uses listener metadata and delegated-source cleanup rather than local component state.

Ownership and lifetime

The first matching event disposes the registration; closing the mount Scope also removes it if it has not fired.

Examples

import * as EventHandler from "@typed/template/EventHandler"

const handler = EventHandler.make((event) => {
  console.log("This will only run once")
})

const onceHandler = EventHandler.once(handler)

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source