consolidated-events
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -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); | ||
}); | ||
}); | ||
}); |
@@ -0,3 +1,7 @@ | ||
## v1.0.1 | ||
- Fix bug with `handleEvent()`. | ||
## v1.0.0 | ||
- Initial release. |
@@ -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( |
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
32351
681