
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.
composite-disposable
Advanced tools
This is a simple library for implementing event subscription APIs. Inspired https://github.com/atom/event-kit. Use default event handler in Node.js.
const { EventEmitter } = require('events');
const CompositeDisposable = require('composite-disposable');
class User {
constructor() {
this.emitter = new EventEmitter();
this.subscriptions = new CompositeDisposable();
}
onDidChangeName(callback) {
this.subscriptions.add(this.emitter.on('change-name', callback));
}
setName(name) {
if (this.name !== name) {
this.name = name;
this.emitter.emit('change-name', this.name);
}
return this.name;
}
destroy() {
this.subscriptions.dispose();
}
}
In the example above, we implement ::onDidChangeName
on the user object, which will register callbacks to be invoked whenever the user's name changes. To do so, we make use of an internal EventEmitter
instance. We use ::on
to subscribe the given callback in ::onDidChangeName
, and ::emit
in ::setName
to notify subscribers. Finally, when the User instance is destroyed we call ::dispose
on the emitter to unsubscribe all subscribers.
FAQs
Simple library for implementing and consuming evented APIs
We found that composite-disposable 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.