
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.
sg-event-emitter
Advanced tools
Very simple class allowing for dispatch custom events in DOM-like style. It's tested in production apps on both browser and node.
All available methods are:
addEventListener(name: string, listener: ()=>void)
- adds a new listener to given eventremoveEventListener(name: string, listener: ()=>void)
- removes registered listener for given event. You have to pass exactly the same function as passed previously to addEventListener
.dispatchEvent(name: string)
- dispatches given eventsettle(host: any)
- links addEventListener
and removeEventListener
from EventEmitter instance to given host object. This allows you to create really encapsulated EventEmitter instance and expose only these two public methods.
var EventEmitter = require('sg-event-emitter').EventEmitter;
//or
import {EventEmitter} from 'sg-event-emitter';
class Foo {
constructor () {
this._eventEmitter = new EventEmitter();
this._eventEmitter.settle(this); //from now this object has
//`addEventListener` and `removeEventListener` methods
}
makeSomeAction () {
this._eventEmitter.dispatchEvent('myEvent');
}
}
var foo = new Foo();
var listener = _ => console.log('dispatched');
foo.addEventListener('myEvent', listener);
foo.makeSomeAction(); //logs 'dispatched'
foo.removeEventListener('myEvent', listener);
foo.makeSomeAction(); //doesn't log anything
FAQs
Simple service registry
The npm package sg-event-emitter receives a total of 36 weekly downloads. As such, sg-event-emitter popularity was classified as not popular.
We found that sg-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.