Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
consolidated-events
Advanced tools
The consolidated-events npm package is designed to optimize event handling in web applications. It allows developers to add event listeners that are automatically consolidated, reducing the number of separate event listeners that need to be managed and improving performance, especially in scenarios with many event listeners.
Add consolidated event listener
This feature allows you to add an event listener to an element, which will be consolidated with other listeners for the same event type, improving performance.
import { addEventListener } from 'consolidated-events';
const listener = event => console.log('Event fired:', event);
const options = { passive: true, capture: false };
const removeEventListener = addEventListener(window, 'resize', listener, options);
Remove consolidated event listener
This feature provides a way to remove a previously added consolidated event listener, ensuring that the listener is properly cleaned up and does not cause memory leaks.
import { addEventListener } from 'consolidated-events';
const listener = event => console.log('Event fired:', event);
const options = { passive: true, capture: false };
const removeEventListener = addEventListener(window, 'resize', listener, options);
// Later, when you want to remove the event listener:
removeEventListener();
The dom-listener package provides a way to add and remove event listeners with automatic deduplication, similar to consolidated-events. However, it may not have the same level of consolidation and performance optimization as consolidated-events.
While react-event-listener is designed specifically for React applications, it offers similar functionality to consolidated-events by providing a declarative API for event listeners. It differs in that it is tailored to work within the React ecosystem.
EventEmitter3 is an implementation of the EventEmitter module found in Node.js but for the browser. It allows you to emit and listen for custom events. It's not specifically for consolidating native DOM event listeners, but it can be used to manage custom event systems within an application.
Manage multiple event handlers using few event listeners.
import { addEventListener, removeEventListener } from 'consolidated-events';
const handle = addEventListener(
window,
'scroll',
() => { console.log('scrolling') },
{ passive: true }
);
...
removeEventListener(handle);
v1.0.0
FAQs
Manage multiple event handlers using few event listeners
The npm package consolidated-events receives a total of 591,479 weekly downloads. As such, consolidated-events popularity was classified as popular.
We found that consolidated-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.