Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
feat!: rename peer discovery symbol to peerDiscovery (#394)
Browse files Browse the repository at this point in the history
The export `symbol` from the `@libp2p/interface-peer-discovery` is too
generic to use with modules that might implement peer discovery and
something else so it's been renamed to `peerDiscovery`.

Objects with `peerDiscovery` symbol properties getters should return
`PeerDiscovery` instances instead of `boolean` values.

BREAKING CHANGE: the `symbol` export is now named `peerDiscovery` and the getter with that name should return an instance of `PeerDiscovery`
  • Loading branch information
achingbrain authored May 4, 2023
1 parent 918721d commit 5957c77
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
6 changes: 2 additions & 4 deletions packages/interface-mocks/src/peer-discovery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { symbol } from '@libp2p/interface-peer-discovery'
import { peerDiscovery } from '@libp2p/interface-peer-discovery'
import { EventEmitter } from '@libp2p/interfaces/events'
import * as PeerIdFactory from '@libp2p/peer-id-factory'
import { multiaddr } from '@multiformats/multiaddr'
Expand All @@ -24,9 +24,7 @@ export class MockDiscovery extends EventEmitter<PeerDiscoveryEvents> implements
this._isRunning = false
}

readonly [symbol] = true

readonly [Symbol.toStringTag] = 'MockDiscovery'
readonly [peerDiscovery] = this

start (): void {
this._isRunning = true
Expand Down
18 changes: 1 addition & 17 deletions packages/interface-peer-discovery/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,8 @@ import type { EventEmitter } from '@libp2p/interfaces/events'
*/
export const peerDiscovery = Symbol.for('@libp2p/peer-discovery')

export const symbol = Symbol.for('@libp2p/peer-discovery')

export interface PeerDiscoveryEvents {
'peer': CustomEvent<PeerInfo>
}

export interface PeerDiscovery extends EventEmitter<PeerDiscoveryEvents> {
/**
* Used to identify the peer discovery mechanism
*/
[Symbol.toStringTag]: string

/**
* Used by the isPeerDiscovery function
*/
[symbol]: true
}

export function isPeerDiscovery (other: any): other is PeerDiscovery {
return other != null && Boolean(other[symbol])
}
export interface PeerDiscovery extends EventEmitter<PeerDiscoveryEvents> {}

0 comments on commit 5957c77

Please sign in to comment.