Skip to content

Releases: sindresorhus/emittery

v2.0.0

04 Mar 20:25

Choose a tag to compare

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/deinit lifecycle hooks - Register setup/teardown logic that runs when the first listener subscribes and the last listener unsubscribes for a given event.
  • Disposable support - Unsubscribe functions from .on() and .onAny() are now Disposable (usable with using for automatic cleanup).
  • AsyncDisposable support - Async iterators from .events() and .anyEvent() are now AsyncDisposable (usable with await using).
  • AbortSignal support 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 emitMetaEvent breaking async emit() 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...v2.0.0

v1.2.1

27 Feb 05:05

Choose a tag to compare

  • Fix emitSerial() not delivering events to async iterators a3c04ca

v1.2.0...v1.2.1

v1.2.0

20 Jun 19:04

Choose a tag to compare

  • Add support for filter predicate in once() (#124) 347c2cc

v1.1.0...v1.2.0

v1.1.0

27 Jan 13:26

Choose a tag to compare


v1.0.3...v1.1.0

v1.0.3

13 Feb 16:00

Choose a tag to compare

v1.0.2...v1.0.3

v1.0.2

29 Jan 07:10

Choose a tag to compare

  • Fix emitter.listenerCount() for symbol keys fad52b9

v1.0.1...v1.0.2

v1.0.1

06 Nov 14:19

Choose a tag to compare

  • Fix globalThis.process conflict in the browser (#107) 5133d6f

v1.0.0...v1.0.1

v1.0.0

06 Sep 06:38

Choose a tag to compare

Breaking

Breaking for TypeScript users

  • Some of the types that were previously accessed on Emittery. are now named exports.

v0.13.1...v1.0.0

v0.13.1

25 Aug 09:32

Choose a tag to compare

v0.13.0...v0.13.1

v0.13.0

25 Aug 03:37

Choose a tag to compare

  • Internal: Properly clean up listener storage (#103) 3641e7a

v0.12.1...v0.13.0