Simple event emitter for Javascript
MIT License
Get started by installing the package:
npm install sweet-event-emitter
# OR
yarn add sweet-event-emitter
The event emitter provides a simple yet rich API to work with events.
import { EventEmitter } from 'sweet-event-emitter';
const emitter = new EventEmitter();
emitter.on('event', () => {
console.log('Event fired!');
});
// Events can have parameters too
emitter.on('event-with-params', (param1, param2) => {
console.log('Event fired with params:', param1, param2);
});
// This will only fire once
emitter.once('event', () => {
console.log('Event fired!');
});
emitter.emit('event');
// Emit events with parameters
emitter.emit('event-with-params', 'param1', 'param2');
const listener = () => {
console.log('Event fired!');
};
emitter.on('event', listener);
// Remove a specific listener
emitter.off('event', listener);
emitter.removeAllListeners('event');
const listeners = emitter.listeners('start');
Contributions, issues and feature requests are welcome. After cloning & setting up project locally, you can just submit a PR to this repo and it will be deployed once it's accepted.
⚠️ It's good to have descriptive commit messages, or PR titles so that other contributors can understand about your commit or the PR created.
We love people's support to grow, improve and give the best. Be sure to drop a 🌟 if you like the project, and also contribute, if you're interested!