* Listens to native events. * - `destroy()` can unsubscribe all events. * - In IE, mediaQueryList does not inherit EventTarget, * and only supports deprecated `addListener` and `removeListener`. * * @link https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener
(
targets: EventTargets,
events: string | string[],
callback: AnyFunction,
options?: AddEventListenerOptions
)
| 50 | * @param options - Optional. The options to pass to the `addEventListener` function. |
| 51 | */ |
| 52 | function bind( |
| 53 | targets: EventTargets, |
| 54 | events: string | string[], |
| 55 | callback: AnyFunction, |
| 56 | options?: AddEventListenerOptions |
| 57 | ): void { |
| 58 | forEachEvent( targets, events, ( target, event, namespace ) => { |
| 59 | const isEventTarget = 'addEventListener' in target; |
| 60 | const remover = isEventTarget |
| 61 | ? target.removeEventListener.bind( target, event, callback, options ) |
| 62 | : target[ 'removeListener' ].bind( target, callback ); |
| 63 | |
| 64 | isEventTarget ? target.addEventListener( event, callback, options ) : target[ 'addListener' ]( callback ); |
| 65 | listeners.push( [ target, event, namespace, callback, remover ] ); |
| 66 | } ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Removes the event handler. |
no test coverage detected
searching dependent graphs…