Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solid-primitives/event-listener

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-primitives/event-listener - npm Package Compare versions

Comparing version 1.2.3 to 1.2.4

dist/cjs/index.js

5

dist/index.d.ts

@@ -11,6 +11,3 @@ import { Accessor } from "solid-js";

interface Directives {
createEventListener: (ref: HTMLElement, props: Accessor<EventListenerProps<{}>>) => [
add: (target: EventTarget) => void,
remove: (target: EventTarget) => void
];
createEventListener: (ref: HTMLElement, props: Accessor<EventListenerProps<{}>>) => [add: (target: EventTarget) => void, remove: (target: EventTarget) => void];
}

@@ -17,0 +14,0 @@ }

8

dist/index.js
import { createEffect, onCleanup } from "solid-js";
export function createEventListener(target, nameOrProps, handler, options) {
const targets = Array.isArray(target) ? target : [target];
const props = typeof nameOrProps === 'function' ? nameOrProps : () => [nameOrProps ?? '', handler ?? null, options];
const props = typeof nameOrProps === "function"
? nameOrProps
: () => [nameOrProps ?? "", handler ?? null, options];
const add = (target) => {

@@ -18,3 +20,4 @@ targets.includes(target) || targets.push(target);

if (previousProps !== currentProps) {
previousProps && targets.forEach((target) => target.removeEventListener.apply(target, previousProps));
previousProps &&
targets.forEach(target => target.removeEventListener.apply(target, previousProps));
targets.forEach(add);

@@ -29,3 +32,2 @@ }

}
;
export default createEventListener;
{
"name": "@solid-primitives/event-listener",
"version": "1.2.3",
"version": "1.2.4",
"description": "Primitive to manage creating event listeners.",

@@ -15,2 +15,7 @@ "author": "David Di Biase <dave.dibiase@gmail.com>",

],
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"sideEffects": "false",

@@ -20,3 +25,3 @@ "scripts": {

"clean": "rimraf dist/",
"build": "tsc",
"build": "tsc && tsc --target es5 --module commonjs --declaration false --outDir ./dist/cjs",
"test": "jest"

@@ -23,0 +28,0 @@ },

@@ -0,4 +1,14 @@

---
Name: event-listener
Stage: 3
Package: "@solid-primitives/event-listener"
Primitives: createEventListener
Category: Browser APIs
---
# @solid-primitives/event-listener
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
[![size](https://img.shields.io/bundlephobia/minzip/@solid-primitives/event-listener)](https://bundlephobia.com/package/@solid-primitives/event-listener)
[![size](https://img.shields.io/npm/v/@solid-primitives/event-listener)](https://www.npmjs.com/package/@solid-primitives/event-listener)

@@ -9,2 +19,10 @@ A helpful event listener primitive that binds window and any element supplied.

## Installation
```bash
npm install @solid-primitives/event-listener
# or
yarn add @solid-primitives/event-listener
```
## How to use it

@@ -16,5 +34,9 @@

);
// or as a directive
```
or as a directive
```ts
<MyButton use:createEventListener={() => ["click", () => console.log("Click")]}>Click!</MyButton>;
// you can provide your own event map type:
// you can provide your own event map type as well:
createEventListener<{ myCustomEvent: Event }>(window, "myCustomEvent", () => console.log("yup!"));

@@ -44,2 +66,6 @@ ```

1.2.4
Added CJS build.
</details>
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc