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
3
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.5.0 to 1.6.0

35

dist/index.d.ts

@@ -1,6 +0,5 @@

import { Fn, MaybeAccessor, Many, Get, Clear } from '@solid-primitives/utils';
import { MaybeAccessor, Many } from '@solid-primitives/utils';
import { JSX, Accessor, Component } from 'solid-js';
import { Store } from 'solid-js/store';
declare type ClearListeners = Fn;
declare type EventListenerOptions = boolean | AddEventListenerOptions;

@@ -27,3 +26,3 @@ declare type TargetWithEventMap = Window | Document | HTMLElement | MediaQueryList;

lastEvent: Accessor<Event | undefined>,
clear: ClearListeners
clear: VoidFunction
];

@@ -41,3 +40,3 @@ /**

* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
* @see https://github.com/davedbase/solid-primitives/tree/main/packages/event-listener#createEventListener
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-listener#createEventListener
*

@@ -47,4 +46,4 @@ * @example

*/
declare function createEventListener<Target extends TargetWithEventMap, EventMap extends EventMapOf<Target>, EventType extends keyof EventMap>(target: MaybeAccessor<Many<Target>>, type: MaybeAccessor<Many<EventType>>, handler: (event: EventMap[EventType]) => void, options?: EventListenerOptions): ClearListeners;
declare function createEventListener<EventMap extends Record<string, Event>, EventType extends keyof EventMap = keyof EventMap>(target: MaybeAccessor<Many<EventTarget>>, type: MaybeAccessor<Many<EventType>>, handler: (event: EventMap[EventType]) => void, options?: EventListenerOptions): ClearListeners;
declare function createEventListener<Target extends TargetWithEventMap, EventMap extends EventMapOf<Target>, EventType extends keyof EventMap>(target: MaybeAccessor<Many<Target>>, type: MaybeAccessor<Many<EventType>>, handler: (event: EventMap[EventType]) => void, options?: EventListenerOptions): VoidFunction;
declare function createEventListener<EventMap extends Record<string, Event>, EventType extends keyof EventMap = keyof EventMap>(target: MaybeAccessor<Many<EventTarget>>, type: MaybeAccessor<Many<EventType>>, handler: (event: EventMap[EventType]) => void, options?: EventListenerOptions): VoidFunction;
/**

@@ -60,3 +59,3 @@ * Provides an reactive signal of last captured event.

* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
* @see https://github.com/davedbase/solid-primitives/tree/main/packages/event-listener#createEventSignal
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-listener#createEventSignal
*

@@ -85,3 +84,3 @@ * @example

};
declare type EventListenerStoreReturns<E> = [lastEvents: Store<Partial<E>>, clear: ClearListeners];
declare type EventListenerStoreReturns<E> = [lastEvents: Store<Partial<E>>, clear: VoidFunction];
/**

@@ -97,3 +96,3 @@ * A helpful primitive that listens to a map of events. Handle them by individual callbacks.

* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
* @see https://github.com/davedbase/solid-primitives/tree/main/packages/event-listener#createEventListenerMap
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-listener#createEventListenerMap
*

@@ -107,4 +106,4 @@ * @example

*/
declare function createEventListenerMap<EventMap extends Record<string, Event>, UsedEvents extends keyof EventMap = keyof EventMap>(target: MaybeAccessor<Many<EventTarget>>, handlersMap: Partial<Pick<EventHandlersMap<EventMap>, UsedEvents>>, options?: EventListenerOptions): ClearListeners;
declare function createEventListenerMap<Target extends TargetWithEventMap, EventMap extends EventMapOf<Target>, HandlersMap extends Partial<EventHandlersMap<EventMap>>>(target: MaybeAccessor<Many<Target>>, handlersMap: HandlersMap, options?: EventListenerOptions): ClearListeners;
declare function createEventListenerMap<EventMap extends Record<string, Event>, UsedEvents extends keyof EventMap = keyof EventMap>(target: MaybeAccessor<Many<EventTarget>>, handlersMap: Partial<Pick<EventHandlersMap<EventMap>, UsedEvents>>, options?: EventListenerOptions): VoidFunction;
declare function createEventListenerMap<Target extends TargetWithEventMap, EventMap extends EventMapOf<Target>, HandlersMap extends Partial<EventHandlersMap<EventMap>>>(target: MaybeAccessor<Many<Target>>, handlersMap: HandlersMap, options?: EventListenerOptions): VoidFunction;
/**

@@ -120,3 +119,3 @@ * A helpful primitive that listens to target events and provides a reactive store with the latest captured events.

* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
* @see https://github.com/davedbase/solid-primitives/tree/main/packages/event-listener#createEventStore
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-listener#createEventStore
*

@@ -156,3 +155,3 @@ * @example

*
* @see https://github.com/davedbase/solid-primitives/tree/main/packages/event-listener#WindowEventListener
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-listener#WindowEventListener
*

@@ -166,3 +165,3 @@ * @example

*
* @see https://github.com/davedbase/solid-primitives/tree/main/packages/event-listener#DocumentEventListener
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-listener#DocumentEventListener
*

@@ -175,5 +174,5 @@ * @example

declare type EventListenerBus<EventMap extends Record<string, any>> = Readonly<{
[K in `on${keyof EventMap extends string ? keyof EventMap : never}`]: (handler: Get<EventMap[K extends `on${infer T}` ? T : never]>) => Clear;
[K in `on${keyof EventMap extends string ? keyof EventMap : never}`]: (handler: (event: EventMap[K extends `on${infer T}` ? T : never]) => void) => VoidFunction;
} & {
on: <T extends keyof EventMap>(type: MaybeAccessor<Many<T>>, handler: Get<EventMap[T]>) => Clear;
on: <T extends keyof EventMap>(type: MaybeAccessor<Many<T>>, handler: (event: EventMap[T]) => void) => VoidFunction;
}>;

@@ -185,3 +184,3 @@ /**

* @returns a Proxy object, which lets you create event listeners by calling appropriate property
* @see https://github.com/davedbase/solid-primitives/tree/main/packages/event-listener#createEventListenerBus
* @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-listener#createEventListenerBus
* @example

@@ -200,2 +199,2 @@ * const bus = createEventListenerBus(document.body);

export { ClearListeners, DocumentEventListener, E, EventHandlersMap, EventListenerBus, EventListenerDirectiveProps, EventListenerMapDirectiveProps, EventListenerOptions, EventListenerSignalReturns, EventListenerStoreReturns, EventMapOf, TargetWithEventMap, WindowEventListener, createEventListener, createEventListenerBus, createEventListenerMap, createEventSignal, createEventStore, eventListener, eventListenerMap };
export { DocumentEventListener, E, EventHandlersMap, EventListenerBus, EventListenerDirectiveProps, EventListenerMapDirectiveProps, EventListenerOptions, EventListenerSignalReturns, EventListenerStoreReturns, EventMapOf, TargetWithEventMap, WindowEventListener, createEventListener, createEventListenerBus, createEventListenerMap, createEventSignal, createEventStore, eventListener, eventListenerMap };
// src/eventListener.ts
import {
createCallbackStack,
forEach,
isFunction,
noop,
isServer
isServer,
access,
asArray
} from "@solid-primitives/utils";

@@ -16,4 +16,4 @@ import { createEffect, onCleanup, createRenderEffect, createSignal } from "solid-js";

cleanup.execute();
forEach(type, (type2) => {
forEach(targets, (el) => {
asArray(access(type)).forEach((type2) => {
asArray(access(targets)).forEach((el) => {
if (!el)

@@ -26,3 +26,3 @@ return;

};
if (isFunction(targets))
if (typeof targets === "function")
createEffect(attachListeners);

@@ -29,0 +29,0 @@ else

{
"name": "@solid-primitives/event-listener",
"version": "1.5.0",
"version": "1.6.0",
"description": "Primitive to manage creating event listeners.",
"author": "David Di Biase <dave.dibiase@gmail.com>",
"license": "MIT",
"homepage": "https://github.com/davedbase/solid-primitives/tree/main/packages/event-listener",
"homepage": "https://github.com/solidjs-community/solid-primitives/tree/main/packages/event-listener",
"repository": {
"type": "git",
"url": "git+https://github.com/davedbase/solid-primitives.git"
"url": "git+https://github.com/solidjs-community/solid-primitives.git"
},

@@ -48,5 +48,5 @@ "primitive": {

"devDependencies": {
"jsdom": "^18.1.1",
"jsdom": "^19.0.0",
"prettier": "^2.5.0",
"solid-register": "0.1.5",
"solid-register": "^0.1.5",
"tslib": "^2.3.1",

@@ -64,5 +64,5 @@ "tsup": "^5.10.0",

"dependencies": {
"@solid-primitives/utils": "^0.2.1",
"@solid-primitives/rootless": "^0.0.101"
"@solid-primitives/rootless": "^0.1.0",
"@solid-primitives/utils": "^1.0.0"
}
}

@@ -0,1 +1,5 @@

<p>
<img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=Event%20Listener" alt="Solid Primitives Event Listener">
</p>
# @solid-primitives/event-listener

@@ -6,3 +10,3 @@

[![size](https://img.shields.io/npm/v/@solid-primitives/event-listener?style=for-the-badge)](https://www.npmjs.com/package/@solid-primitives/event-listener)
[![stage](https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fraw.githubusercontent.com%2Fdavedbase%2Fsolid-primitives%2Fmain%2Fassets%2Fbadges%2Fstage-3.json)](https://github.com/davedbase/solid-primitives#contribution-process)
[![stage](https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fraw.githubusercontent.com%2Fsolidjs-community%2Fsolid-primitives%2Fmain%2Fassets%2Fbadges%2Fstage-3.json)](https://github.com/solidjs-community/solid-primitives#contribution-process)

@@ -50,2 +54,9 @@ A set of primitives that help with listening to DOM and Custom Events.

createEventListener(ref, name, e => {}, { passive: true });
// also runs in createEffect so refs are already bound
// (but variable refs need to be wrapped in functions)
let ref;
createEventListener(() => ref, "mousemove", e => {});
return <div ref={ref}/>;
```

@@ -52,0 +63,0 @@

Sorry, the diff of this file is not supported yet

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