@solid-primitives/event-listener
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -7,2 +7,3 @@ /** | ||
* @param element - HTML element to bind the event to | ||
* @param options - *useCapture* boolean or an object that specifies characteristics about the event listener. | ||
* | ||
@@ -14,3 +15,3 @@ * @example | ||
*/ | ||
declare const createEventListener: <T extends HTMLElement>(eventName: keyof WindowEventMap, handler: (event: Event) => void, targets?: Window | T | T[]) => [add: (el: Window | T) => void, remove: (el: Window | T) => void]; | ||
declare const createEventListener: <T extends HTMLElement, E extends keyof WindowEventMap>(eventName: E, handler: (event: WindowEventMap[E]) => void, targets?: Window | T | T[], options?: boolean | AddEventListenerOptions | undefined) => readonly [add: (el: Window | T) => void, remove: (el: Window | T) => void]; | ||
export default createEventListener; |
@@ -8,2 +8,3 @@ import { onMount, onCleanup } from "solid-js"; | ||
* @param element - HTML element to bind the event to | ||
* @param options - *useCapture* boolean or an object that specifies characteristics about the event listener. | ||
* | ||
@@ -15,5 +16,7 @@ * @example | ||
*/ | ||
const createEventListener = (eventName, handler, targets = window) => { | ||
const add = (target) => target.addEventListener && target.addEventListener(eventName, handler); | ||
const remove = (target) => target.removeEventListener && target.removeEventListener(eventName, handler); | ||
const createEventListener = (eventName, handler, targets = window, options) => { | ||
const add = (target) => target.addEventListener && | ||
target.addEventListener(eventName, handler, options); | ||
const remove = (target) => target.removeEventListener && | ||
target.removeEventListener(eventName, handler, options); | ||
onMount(() => (Array.isArray(targets) ? targets.forEach(add) : add(targets))); | ||
@@ -20,0 +23,0 @@ onCleanup(() => (Array.isArray(targets) ? targets.forEach(remove) : remove(targets))); |
{ | ||
"name": "@solid-primitives/event-listener", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Primitive to manage creating event listeners.", | ||
@@ -5,0 +5,0 @@ "author": "David Di Biase <dave.dibiase@gmail.com>", |
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
4673
40