Releases: sindresorhus/emittery
Releases · sindresorhus/emittery
v2.0.0
Breaking Changes
Listeners now receive a unified {name, data} object instead of raw data
All listeners (.on(), .onAny(), .once(), async iterators) now receive a single event object with name and data properties instead of the raw event data.
- emitter.on('🦄', data => {
- console.log(data);
+ emitter.on('🦄', ({data}) => {
+ console.log(data);
});For .onAny():
- emitter.onAny((eventName, eventData) => {
- console.log(eventName, eventData);
+ emitter.onAny(({name, data}) => {
+ console.log(name, data);
});For .once():
- const data = await emitter.once('🦄');
+ const {data} = await emitter.once('🦄');For .events() and .anyEvent() async iterators:
- for await (const data of emitter.events('🦄')) {
+ for await (const {data} of emitter.events('🦄')) {
console.log(data);
}
- for await (const [eventName, eventData] of emitter.anyEvent()) {
+ for await (const {name, data} of emitter.anyEvent()) {
…
}For predicates in .once():
- emitter.once('data', data => data.ok === true);
+ emitter.once('data', ({data}) => data.ok === true);emit() now throws AggregateError instead of rejecting with a single error
When multiple listeners throw, emit() now collects all errors into an AggregateError instead of silently dropping errors after the first one. All listeners always run to completion.
try {
await emitter.emit('event');
} catch (error) {
- // error was from the first listener that threw
+ // error is an AggregateError with all listener errors in error.errors
+ console.log(error.errors);
}Requires Node.js 22
The minimum required Node.js version is now 22 (previously 14.16).
New Features
init/deinitlifecycle hooks - Register setup/teardown logic that runs when the first listener subscribes and the last listener unsubscribes for a given event.Disposablesupport - Unsubscribe functions from.on()and.onAny()are nowDisposable(usable withusingfor automatic cleanup).AsyncDisposablesupport - Async iterators from.events()and.anyEvent()are nowAsyncDisposable(usable withawait using).AbortSignalsupport for.events(),.anyEvent(), and.once()- Pass{signal}to cancel subscriptions externally..once()options object - Accepts{predicate, signal}in addition to a plain predicate function.- TC39 standard decorator support -
Emittery.mixin()now works with both legacy and TC39 standard decorator syntax.
Bug Fixes
emit()no longer silently drops errors from multiple listeners- Debug logger no longer emits noise for internal meta events
- Fixed
emitMetaEventbreaking asyncemit()overrides in subclasses - Fixed Emittery not working when wrapped in a
Proxy - Fixed mixin decorator to work with TC39 standard decorator syntax
v1.2.1
v1.2.0
v1.1.0
v1.0.3
v1.0.2
- Fix
emitter.listenerCount()for symbol keys fad52b9
v1.0.1
v1.0.0
Breaking
Breaking for TypeScript users
- Some of the types that were previously accessed on
Emittery.are now named exports.