
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
event-listener-service
Advanced tools
Universal Event Litener with testability built in
Install with npm:
$ npm install event-listener-service
Declare usage without internal event registering implementation
Set internal event registering implementation
Add EventListener
Emit event using built in event emiting
Remove EventListener
import EventListenerService from 'event-listener-service';
// Declare usage without internal event registering implementation
EventListenerService.useWithoutImplementation();
function onSomeEvent(event) {
console.log('some-event', event);
}
// Adding EventLisner
EventListenerService.addListener('some-event', onSomeEvent);
// Emiting Events
EventListenerService.emit('some-event', { rand: 9 });
// Removing EventLisnter
EventListenerService.removeListener('some-event', onSomeEvent);
import EventListenerService from 'event-listener-service';
// Seting internal event registering implementation
EventListenerService.setImplementation({
addListener: window.addEventListener.bind(window),
removeListener: window.removeEventListener.bind(window)
});
function onResize() {
/* ... */
}
// Adding EventLisner
EventListenerService.addListener('resize', onResize, false);
// Removing EventLisnter
EventListenerService.removeListener('resize', onResize, false);
// Optionaly you can manually trigger event listeners in your tests or when you need to fully simulate event
EventListenerService.emit('resize', /* [event object] */);
// Set internal implementation for registering event listeners
EventListenerService.setImplementation({
addListener: /* (eventName: string, listener: (event?: any) => void, ...additional: any[]) => void */
removeListener: /* (eventName: string, listener: (event?: any) => void, ...additional: any[]) => void */
});
// And than use addListener and removeListner
EventListnerService.addListener(eventName: string, listener: (event?: any) => void, ...additional: any[]);
EventListnerService.removeListener(eventName: string, listener: (event?: any) => void, ...additional: any[]);
npm install
npm test
npm install
Make changes
If necessary add some tests to __tests__
npm test
Make a Pull Request
FAQs
Universal Event Litener with testability built in
The npm package event-listener-service receives a total of 76 weekly downloads. As such, event-listener-service popularity was classified as not popular.
We found that event-listener-service 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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.