@solid-primitives/event-listener
Advanced tools
Comparing version 0.0.100 to 1.1.3
@@ -13,3 +13,3 @@ /** | ||
*/ | ||
declare const createEventListener: <T extends HTMLElement>(eventName: keyof WindowEventMap, handler: (event: Event) => void, targets?: Window | T) => [add: (el: Window | T) => void, remove: (el: Window | T) => void]; | ||
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]; | ||
export default createEventListener; |
@@ -16,8 +16,7 @@ import { onMount, onCleanup } from "solid-js"; | ||
const add = (target) => target.addEventListener && target.addEventListener(eventName, handler); | ||
const remove = (target) => target.removeEventListener && | ||
target.removeEventListener(eventName, handler); | ||
onMount(() => Array.isArray(targets) ? targets.forEach(add) : add(targets)); | ||
onCleanup(() => Array.isArray(targets) ? targets.forEach(remove) : remove(targets)); | ||
const remove = (target) => target.removeEventListener && target.removeEventListener(eventName, handler); | ||
onMount(() => (Array.isArray(targets) ? targets.forEach(add) : add(targets))); | ||
onCleanup(() => (Array.isArray(targets) ? targets.forEach(remove) : remove(targets))); | ||
return [add, remove]; | ||
}; | ||
export default createEventListener; |
{ | ||
"name": "@solid-primitives/event-listener", | ||
"version": "0.0.100", | ||
"version": "1.1.3", | ||
"description": "Primitive to manage creating event listeners.", | ||
@@ -34,4 +34,4 @@ "author": "David Di Biase <dave.dibiase@gmail.com>", | ||
}, | ||
"dependencies": { | ||
"solid-js": "^1.0.3" | ||
"peerDependencies": { | ||
"solid-js": "^1.0.7" | ||
}, | ||
@@ -43,2 +43,2 @@ "jest": { | ||
} | ||
} | ||
} |
@@ -12,3 +12,4 @@ # @solid-primitives/event-listener | ||
```ts | ||
createEventListener("mouseDown", () => console.log("Click"), document.getElementById("mybutton")) | ||
const [listener] = createEventListener("mouseDown", () => console.log("Click"), document.getElementById("mybutton")) | ||
<button use:listener>Click me</button> | ||
``` | ||
@@ -15,0 +16,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4317
0
30
35
- Removedsolid-js@^1.0.3