fix: rename event emitter class #2173
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We add types to a
EventEmitterclass which extends the plain jsEventTarget.The name is chosen to give familiarity to node developers but it's not generally a good idea.
This refactor:
TypedEventTargetinterface which adds types toEventTargetEventEmittertoTypedEventEmitterto draw a distinction between themTypedEventEmitterasEventEmitterto preserve backwards compatibilityIn the future all consuming code should rely on the
TypedEventTargetinterface while implementing code usesTypedEventEmitteras an implementation of aTypedEventEmitter.By depending on the interface and not the implementation consuming code is isolated from problems that arise when two versions of
@libp2p/interfaceis in the dependency tree and the event subsystems would otherwise be compatible due to type overlap.This manifests as an error message about incompatible implementations of the private
#listenersfield in EventEmitter.Backwards compatibility is achieved by exporting the
TypedEventEmitterclass as the olderEventEmittername. This should be removed in a future PR to the v1.0 branch once external modules (e.g. Gossipsub) have been updated to use the newTypedEventEmittersymbol.Change checklist