Skip to content

Commit

Permalink
Only accept iterables, not any array-likes
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jun 23, 2022
1 parent 6ac66e2 commit ec3232d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 6 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function editLedger(
}

function isEventTarget(
elements: EventTarget | Document | ArrayLike<Element> | string,
elements: EventTarget | Document | Iterable<Element> | string,
): elements is EventTarget {
return typeof (elements as EventTarget).addEventListener === 'function';
}
Expand Down Expand Up @@ -83,7 +83,7 @@ function delegate<
TElement extends Element = ParseSelector<Selector, HTMLElement>,
TEventType extends EventType = EventType,
>(
base: EventTarget | Document | ArrayLike<Element> | string,
base: EventTarget | Document | Iterable<Element> | string,
selector: Selector,
type: TEventType,
callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>,
Expand All @@ -94,7 +94,7 @@ function delegate<
TElement extends Element = HTMLElement,
TEventType extends EventType = EventType,
>(
base: EventTarget | Document | ArrayLike<Element> | string,
base: EventTarget | Document | Iterable<Element> | string,
selector: string,
type: TEventType,
callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>,
Expand All @@ -106,7 +106,7 @@ function delegate<
TElement extends Element,
TEventType extends EventType = EventType,
>(
base: EventTarget | Document | ArrayLike<Element> | string,
base: EventTarget | Document | Iterable<Element> | string,
selector: string,
type: TEventType,
callback: DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>,
Expand Down Expand Up @@ -137,9 +137,9 @@ function delegate<

// Handle Array-like based usage
if (!isEventTarget(base)) {
Array.prototype.forEach.call(base, element => {
for (const element of base) {
delegate(element, selector, type, callback, listenerOptions);
});
}

return internalController;
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
],
"rules": {
"max-params": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/naming-convention": "off"
}
},
Expand Down

0 comments on commit ec3232d

Please sign in to comment.