11import { onDomReady } from './ready' ;
22
3- export type EventHandler < E extends Element = Element > = ( element : E , event : Event ) => void ;
4- export type EventHandlers < E extends Element = Element > = Record < string , EventHandler < E > > ;
3+ export type DomEventCallback < E extends Element = Element > = ( element : E , event : Event ) => void | Promise < void > ;
4+ export type DomEventCallbacks < E extends Element = Element > = Record < string , DomEventCallback < E > > ;
55
66type EventName = 'click' | 'change' ;
77type Selector = string ;
@@ -16,14 +16,14 @@ type SelectorListenOptions = BaseListenOptions & {
1616}
1717
1818type SelectorsListenOptions < E extends Element = Element > = BaseListenOptions & {
19- readonly selectors : EventHandlers < E > ;
19+ readonly selectors : DomEventCallbacks < E > ;
2020 selector ?: never ;
2121}
2222
23- export function onDomEvents < E extends Element = Element > ( eventName : EventName , options : SelectorListenOptions | string , handler : EventHandler < E > ) : void ;
23+ export function onDomEvents < E extends Element = Element > ( eventName : EventName , options : SelectorListenOptions | string , handler : DomEventCallback < E > ) : void ;
2424export function onDomEvents < E extends Element = Element > ( eventName : EventName , options : SelectorsListenOptions < E > ) : void ;
2525
26- export function onDomEvents < E extends Element = Element > ( eventName : EventName , options : SelectorListenOptions | SelectorsListenOptions < E > | string , handler ?: EventHandler < E > ) : void {
26+ export function onDomEvents < E extends Element = Element > ( eventName : EventName , options : SelectorListenOptions | SelectorsListenOptions < E > | string , handler ?: DomEventCallback < E > ) : void {
2727 if ( typeof options === 'string' ) {
2828 options = < SelectorListenOptions > {
2929 selector : options ,
@@ -34,20 +34,20 @@ export function onDomEvents<E extends Element = Element>(eventName: EventName, o
3434 throw new Error ( 'Only one option must be provided: either selectors or callback, not both.' ) ;
3535 }
3636
37- let selectors : EventHandlers ;
37+ let selectors : DomEventCallbacks ;
3838
3939 if ( options . selectors ) {
40- selectors = options . selectors as EventHandlers ;
40+ selectors = options . selectors as DomEventCallbacks ;
4141 } else {
4242 if ( ! handler ) {
4343 throw new Error ( 'Missed handler' ) ;
4444 }
4545
4646 selectors = { } ;
47- selectors [ options . selector ] = handler as EventHandler ;
47+ selectors [ options . selector ] = handler as DomEventCallback ;
4848 }
4949
50- const findHandler = ( selectors : EventHandlers , element : HTMLElement ) : [ HTMLElement , EventHandler ] | null => {
50+ const findHandler = ( selectors : DomEventCallbacks , element : HTMLElement ) : [ HTMLElement , DomEventCallback ] | null => {
5151 for ( const [ selector , handler ] of Object . entries ( selectors ) ) {
5252 if ( element . matches ( selector ) ) {
5353 return [ element , handler ] ;
0 commit comments