You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 26, 2023. It is now read-only.
Replaces the node `EventEmitter` with the pure-js `EventTarget` class.
All events are now instances of [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event).
For typing [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) can be used which gives us a typed `.detail` field.
Tediously `EventTarget` itself [doesn't support typed events](microsoft/TypeScript#28357) (yet?) and node.js [doesn't support](nodejs/node#40678) `CustomEvent` globally so bit of trickery was required but hopefully this can be removed in future:
```js
import { EventEmitter, CustomEvent } from '@libp2p/interfaces'
interface EventMap {
'foo': CustomEvent<number>
}
class MyEmitter extends EventEmitter<EventMap> {
// ... other code here
}
const emitter = new MyEmitter()
emitter.addEventListener('foo', (evt) => {
const n = evt.detail // n is a 'number'
})
```
0 commit comments