export declare type DelegatedEventTarget = Window | Document | HTMLElement; /** * This is a "shared" event handler for the provided `eventType`. The event * listener will only be created once, but every single callback will be called * when the throttled event is triggered. This means that you will need to make * sure to remove the provided callback when it is no longer in use. */ export interface DelegatedEventHandler { /** * Adds the provided callback to the throttled event listener. */ add: (callback: EventListener) => void; /** * Attempts to remove the provided callback from the throttled event listener. */ remove: (callback: EventListener) => void; } export interface DelegatableEvent { type: string; target: DelegatedEventTarget; throttle: boolean; handler: DelegatedEventHandler; options?: boolean | AddEventListenerOptions; } /** * Creates a delegated event listener using custom events. Most of this code * comes from the MDN about resize listeners. * * This will return an object for adding or removing event handlers for the * provided `eventType` since only one base throttled event listener will be * created. Each callback that is added will be called with the event each time * the event is triggered. This does mean that you will manually need to remove * your callback like normal or else it can be called when no longer in use. * This also means that it doesn't "hurt" to call this function without * immediately calling the `add` function since the event won't start until * there is at least 1 callback. * * @see https://developer.mozilla.org/en-US/docs/Web/Events/resize#Examples * @param eventType One of the event types that should be used to create a * delegated event for. This should be things like resize, click, scroll, etc. * @param eventTarget The target that should have the delegated event handler * attached to. This is normally the window, but can be any element as needed. * @param throttle Boolean if the event should be throttled or not. Normally * only event types like resize or scroll should be throttled for performance * boosts, but anything can be. * @return The delegated event handler that allows you to add or remove * `EventListener`s to that event. */ export default function delegateEvent(eventType: string, eventTarget?: DelegatedEventTarget, throttle?: boolean, options?: boolean | AddEventListenerOptions): DelegatedEventHandler;