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
Member of
EventHandler

Import

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

Access EventHandler.once through the imported EventHandler export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

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