UNPKG

lazy-widgets

Version:

Typescript retained mode GUI for the HTML canvas API

32 lines (31 loc) 1.05 kB
import { ConcurrentCollection } from './ConcurrentCollection.js'; /** * A listener callback for a {@link Notifier}. * * @category Helper */ export type Listener<E> = (event: E) => void; /** * A base class that can be listened to, and dispatch events. * * @category Helper */ export declare abstract class Notifier<E> { protected readonly listeners: ConcurrentCollection<Listener<E>>; /** Listen to events from this helper. Duplicate listeners allowed. */ addEventListener(listener: Listener<E>): void; /** * Stop listening to events from this helper. If a duplicate listener is * removed, only one is removed. * * @returns True if a listener was removed, false otherwise. */ removeEventListener(listener: Listener<E>): boolean; /** * Dispatch an event to a specific listener. Listener does not have to be * added */ protected dispatchToListener(event: E, listener: Listener<E>): void; /** Dispatch an event to all listeners. */ protected dispatchEvent(event: E): void; }