delegate-it
Advanced tools
Comparing version 4.0.1 to 5.0.0
@@ -12,4 +12,4 @@ import type { ParseSelector } from 'typed-query-selector/parser.d.js'; | ||
*/ | ||
declare function delegate<Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>, TEventType extends EventType = EventType>(base: EventTarget | Document | Iterable<Element> | string, selector: Selector, type: TEventType, callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>, options?: DelegateOptions): AbortController; | ||
declare function delegate<TElement extends Element = HTMLElement, TEventType extends EventType = EventType>(base: EventTarget | Document | Iterable<Element> | string, selector: string, type: TEventType, callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>, options?: DelegateOptions): AbortController; | ||
declare function delegate<Selector extends string, TElement extends Element = ParseSelector<Selector, HTMLElement>, TEventType extends EventType = EventType>(base: EventTarget | Document | Iterable<Element> | string, selector: Selector, type: TEventType, callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>, options?: DelegateOptions): void; | ||
declare function delegate<TElement extends Element = HTMLElement, TEventType extends EventType = EventType>(base: EventTarget | Document | Iterable<Element> | string, selector: string, type: TEventType, callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>, options?: DelegateOptions): void; | ||
export default delegate; |
20
index.js
@@ -42,18 +42,9 @@ /** Keeps track of raw listeners added to the base elements to avoid duplication */ | ||
function delegate(base, selector, type, callback, options) { | ||
const internalController = new AbortController(); | ||
const listenerOptions = typeof options === 'object' ? options : { capture: options }; | ||
// Drop unsupported `once` option https://github.com/fregante/delegate-it/pull/28#discussion_r863467939 | ||
delete listenerOptions.once; | ||
if (listenerOptions.signal) { | ||
if (listenerOptions.signal.aborted) { | ||
internalController.abort(); | ||
return internalController; | ||
} | ||
listenerOptions.signal.addEventListener('abort', () => { | ||
internalController.abort(); | ||
}); | ||
const { signal } = listenerOptions; | ||
if (signal?.aborted) { | ||
return; | ||
} | ||
else { | ||
listenerOptions.signal = internalController.signal; | ||
} | ||
// Handle Selector-based usage | ||
@@ -68,3 +59,3 @@ if (typeof base === 'string') { | ||
} | ||
return internalController; | ||
return; | ||
} | ||
@@ -87,7 +78,6 @@ // `document` should never be the base, it's just an easy way to define "global event listeners" | ||
} | ||
internalController.signal.addEventListener('abort', () => { | ||
signal?.addEventListener('abort', () => { | ||
editLedger(false, baseElement, callback, setup); | ||
}); | ||
return internalController; | ||
} | ||
export default delegate; |
{ | ||
"name": "delegate-it", | ||
"version": "4.0.1", | ||
"version": "5.0.0", | ||
"description": "Lightweight and modern event delegation in the browser", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10802
96