
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
smelly-event-emitter
Advanced tools
A minimal and fast event-emitter for the browser. This can be used as a standalone class or attached to an existing objects prototype. See usage example below.
npm
npm install smelly-event-emitter --save
browser
<script src="/source/to/event-emitter.min.js"></script>
commonjs environment with inheritance (ES6)
import EventEmitter from 'event-emitter';
class Foo extends EventEmitter {
constructor() {
super();
this.on('foo', this.bar);
this.emit('foo');
}
bar() {
console.log('foo event emitted!');
}
}
commonjs environment with inheritance (ES5)
var EventEmitter = require('smelly-event-emitter');
function Foo() {
EventEmitter.call(this); // super
this.on('foo', this.bar);
}
Foo.prototype.bar = function() {
console.log('foo event emitted');
}
Foo.prototype = Object.create(EventEmitter.prototype);
Foo.prototype.constructor = Foo;
var test = new Foo();
test.emit('foo');
browser environment with inheritance
function Foo() {
EventEmitter.call(this); // super
this.on('foo', this.bar);
}
Foo.prototype.bar = function() {
console.log('foo event emitted');
}
Foo.prototype = Object.create(EventEmitter.prototype);
Foo.prototype.constructor = Foo;
var test = new Foo();
foo.emit('foo');
standalone (commonjs ES6)
import EventEmitter from 'event-emitter';
const ee = new EventEmitter();
class Foo {
constructor() {
ee.on('foo', this.bar);
ee.emit('foo');
}
bar() {
console.log('foo event called');
}
}
.on(eventName, listener)
Attaches a listener to an event name. The listener can be removed by calling .off(eventName, listener)
. Note that if you pass an anonymous function as the lister, the .off()
method will not be able to correctly remove that listener from the event listener list.
.off(eventName, listener)
Removes a listener from an event name. The listener will only correctly be removed if it is a named function (with the exception of if there is only a single listener attached).
.once(eventName, listener)
Attaches a listener to an event name that will only be fired once and then removed after being fired.
.emit(eventName, ...args)
Fire off all listeners for a specified event name and pass in any params to them as well. You can pass in any number of arguments you want e.g. this.emit('foo', 'bar', 'baz', 'boz')
or this.emit('foo', { bar: 'baz' })
. Note, a listener must have been attached with .on()
or .once()
before it can be fired with .emit()
.
.getMaxListeners()
Gets the specified maxListener count for the EventEmitter. Note this is used only to warn you against attaching too many listeners at once to a single event name.
.setMaxListeners()
Sets the maxListener count for the EventEmitter.
.getAllListeners(eventName = null)
Grabs all listeners for a specific event name, or if none is provided simply grabs the entire EventEmitter listeners object.
FAQs
A minimal and fast event-emitter for the browser.
The npm package smelly-event-emitter receives a total of 5 weekly downloads. As such, smelly-event-emitter popularity was classified as not popular.
We found that smelly-event-emitter 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.