From c850b258b4e2487b0456a95cd6b65c169ffb9de2 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 5 Mar 2020 08:36:13 -0500 Subject: Support async function and EventListenerObject as listeners (#4240) --- cli/js/dom_types.ts | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'cli/js/dom_types.ts') diff --git a/cli/js/dom_types.ts b/cli/js/dom_types.ts index 1e6c622c8..cdd681615 100644 --- a/cli/js/dom_types.ts +++ b/cli/js/dom_types.ts @@ -76,20 +76,44 @@ export const eventTargetListeners: unique symbol = Symbol(); export const eventTargetMode: unique symbol = Symbol(); export const eventTargetNodeType: unique symbol = Symbol(); +export interface EventListener { + // Different from lib.dom.d.ts. Added Promise + (evt: Event): void | Promise; +} + +export interface EventListenerObject { + // Different from lib.dom.d.ts. Added Promise + handleEvent(evt: Event): void | Promise; +} + +export type EventListenerOrEventListenerObject = + | EventListener + | EventListenerObject; + +// This is actually not part of actual DOM types, +// but an implementation specific thing on our custom EventTarget +// (due to the presence of our custom symbols) +export interface EventTargetListener { + callback: EventListenerOrEventListenerObject; + options: AddEventListenerOptions; +} + export interface EventTarget { + // TODO: below 4 symbol props should not present on EventTarget WebIDL. + // They should be implementation specific details. [eventTargetHost]: EventTarget | null; - [eventTargetListeners]: { [type in string]: EventListener[] }; + [eventTargetListeners]: { [type in string]: EventTargetListener[] }; [eventTargetMode]: string; [eventTargetNodeType]: NodeType; addEventListener( type: string, - callback: (event: Event) => void | null, + listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions ): void; dispatchEvent(event: Event): boolean; removeEventListener( type: string, - callback?: (event: Event) => void | null, + listener: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean ): void; } @@ -147,12 +171,6 @@ export interface URLSearchParams extends DomIterable { ): void; } -export interface EventListener { - handleEvent(event: Event): void; - readonly callback: (event: Event) => void | null; - readonly options: boolean | AddEventListenerOptions; -} - export interface EventInit { bubbles?: boolean; cancelable?: boolean; -- cgit v1.2.3