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

Commit

Permalink
fix: dispatch peer event on adding new addresses as well as set (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Apr 11, 2023
1 parent 3df533c commit f6d7658
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/address-book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class PeerStoreAddressBook {
const release = await this.store.lock.writeLock()
log.trace('add got write lock')

let hasPeer
let hasPeer = false
let peer: Peer | undefined
let updatedPeer

Expand Down Expand Up @@ -291,7 +291,7 @@ export class PeerStoreAddressBook {
}))

// Notify the existence of a new peer
if (hasPeer === true) {
if (!hasPeer) {
this.dispatchEvent(new CustomEvent<PeerInfo>('peer', {
detail: {
id: peerId,
Expand Down
26 changes: 26 additions & 0 deletions test/address-book.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,32 @@ describe('addressBook', () => {
await defer.promise
})

it('emits peer event if new peer has addresses added', async () => {
const defer = pDefer()

peerStore.addEventListener('peer', () => {
defer.resolve()
})

await ab.add(await createEd25519PeerId(), [
multiaddr('/ip4/42.14.53.21/tcp/3981')
])
await defer.promise
})

it('emits peer event if new peer has addresses set', async () => {
const defer = pDefer()

peerStore.addEventListener('peer', () => {
defer.resolve()
})

await ab.set(await createEd25519PeerId(), [
multiaddr('/ip4/42.14.53.21/tcp/3981')
])
await defer.promise
})

it('adds the new content and emits change event', async () => {
const defer = pDefer()

Expand Down

0 comments on commit f6d7658

Please sign in to comment.