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

consolidated-events

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consolidated-events - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

34

__tests__/TargetEventHandlers-test.js

@@ -134,1 +134,35 @@ import TargetEventHandlers from '../src/TargetEventHandlers';

});
describe('#handleEvent', () => {
it('calls each handler', () => {
const target = new MockTarget();
const eventHandlers = new TargetEventHandlers(target);
const handlers = [jest.fn(), jest.fn(), jest.fn()];
handlers.forEach((handler) => {
eventHandlers.add('scroll', handler);
});
const event = {};
eventHandlers.handleEvent('scroll', undefined, event);
handlers.forEach((handler) => {
expect(handler).toHaveBeenCalledTimes(1);
expect(handler).toHaveBeenCalledWith(event);
});
});
it('calls each handler with options', () => {
const target = new MockTarget();
const eventHandlers = new TargetEventHandlers(target);
const handlers = [jest.fn(), jest.fn(), jest.fn()];
handlers.forEach((handler) => {
eventHandlers.add('scroll', handler, { passive: true });
});
const event = {};
eventHandlers.handleEvent('scroll', { passive: true }, event);
handlers.forEach((handler) => {
expect(handler).toHaveBeenCalledTimes(1);
expect(handler).toHaveBeenCalledWith(event);
});
});
});

4

CHANGELOG.md

@@ -0,3 +1,7 @@

## v1.0.1
- Fix bug with `handleEvent()`.
## v1.0.0
- Initial release.

6

lib/TargetEventHandlers.js

@@ -45,4 +45,4 @@ Object.defineProperty(exports, "__esModule", {

value: function () {
function handleEvent(eventName, event) {
var _getEventHandlers = this.getEventHandlers(eventName),
function handleEvent(eventName, options, event) {
var _getEventHandlers = this.getEventHandlers(eventName, options),
handlers = _getEventHandlers.handlers;

@@ -72,3 +72,3 @@

if (eventHandlers.size === 0) {
eventHandlers.handleEvent = this.handleEvent.bind(this, eventName);
eventHandlers.handleEvent = this.handleEvent.bind(this, eventName, options);

@@ -75,0 +75,0 @@ this.target.addEventListener(eventName, eventHandlers.handleEvent, options);

{
"name": "consolidated-events",
"version": "1.0.0",
"version": "1.0.1",
"description": "Manage multiple event handlers using few event listeners",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -23,4 +23,4 @@ import eventOptionsKey from './eventOptionsKey';

handleEvent(eventName, event) {
const { handlers } = this.getEventHandlers(eventName);
handleEvent(eventName, options, event) {
const { handlers } = this.getEventHandlers(eventName, options);
Object.keys(handlers).forEach((index) => {

@@ -43,3 +43,3 @@ const handler = handlers[index];

if (eventHandlers.size === 0) {
eventHandlers.handleEvent = this.handleEvent.bind(this, eventName);
eventHandlers.handleEvent = this.handleEvent.bind(this, eventName, options);

@@ -46,0 +46,0 @@ this.target.addEventListener(

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