-
Notifications
You must be signed in to change notification settings - Fork 27
feat: add content and peer routing progress events #355
base: master
Are you sure you want to change the base?
feat: add content and peer routing progress events #355
Conversation
These are added as optional generics so this change should be non-breaking.
export interface Libp2p< | ||
FindPeerProgressEvents extends ProgressEvent = ProgressEvent, | ||
GetClosestPeersProgressEvents extends ProgressEvent = ProgressEvent, | ||
ProvideProgressEvents extends ProgressEvent = ProgressEvent, | ||
FindProvidersProgressEvents extends ProgressEvent = ProgressEvent, | ||
PutProgressEvents extends ProgressEvent = ProgressEvent, | ||
GetProgressEvents extends ProgressEvent = ProgressEvent | ||
> extends Startable, EventEmitter<Libp2pEvents> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add generics to the extends ProgressEvent
in order to appropriately populate progressEvent or else users won't be able to customize their data since it's always going to be set to ProgressEvent<any, unknown>
e.g.
export interface Libp2p< | |
FindPeerProgressEvents extends ProgressEvent = ProgressEvent, | |
GetClosestPeersProgressEvents extends ProgressEvent = ProgressEvent, | |
ProvideProgressEvents extends ProgressEvent = ProgressEvent, | |
FindProvidersProgressEvents extends ProgressEvent = ProgressEvent, | |
PutProgressEvents extends ProgressEvent = ProgressEvent, | |
GetProgressEvents extends ProgressEvent = ProgressEvent | |
> extends Startable, EventEmitter<Libp2pEvents> { | |
export interface Libp2p< | |
FindPeerT extends string = any, FindPeerD = unknown, | |
GetClosestPeersT extends string = any, GetClosestPeersD = unknown, | |
ProvideT extends string = any, ProvideD = unknown, | |
FindProvidersT extends string = any, FindProvidersD = unknown, | |
PutT extends string = any, PutD = unknown, | |
GetT extends string = any, GetD = unknown, | |
> extends Startable, EventEmitter<Libp2pEvents> { |
this can obviously be improved, but without piping the generics through, you will lock types to any and unknown, and aren't getting much benefit
@@ -138,7 +146,7 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> { | |||
* } | |||
* ``` | |||
*/ | |||
peerRouting: PeerRouting | |||
peerRouting: PeerRouting<FindPeerProgressEvents, GetClosestPeersProgressEvents> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
peerRouting: PeerRouting<FindPeerProgressEvents, GetClosestPeersProgressEvents> | |
peerRouting: PeerRouting<ProgressEvent<FindPeerT, FindPeerD>, ProgressEvent<GetClosestPeersT, GetClosestPeersD>> |
@@ -154,7 +162,7 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> { | |||
* } | |||
* ``` | |||
*/ | |||
contentRouting: ContentRouting | |||
contentRouting: ContentRouting<ProvideProgressEvents, FindProvidersProgressEvents, PutProgressEvents, GetProgressEvents> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contentRouting: ContentRouting<ProvideProgressEvents, FindProvidersProgressEvents, PutProgressEvents, GetProgressEvents> | |
contentRouting: ContentRouting<ProgressEvent<ProvideT, ProvideD>, ProgressEvent<FindProvidersT, FindProvidersD>, ProgressEvent<PutT, PutD>, ProgressEvent<GetT, GetD>> |
export interface PeerRouting< | ||
FindPeerProgressEvents extends ProgressEvent = ProgressEvent, | ||
GetClosestPeersProgressEvents extends ProgressEvent = ProgressEvent, | ||
> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
These are added as optional generics so this change should be non-breaking.
Refs: libp2p/js-libp2p#1652