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

Commit

Permalink
fix: make events optional in mock upgrader (#385)
Browse files Browse the repository at this point in the history
To ease upgrading and not force users to pass a dummy object in.
  • Loading branch information
achingbrain authored Apr 24, 2023
1 parent 009a8cc commit 51f4aae
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/interface-mocks/src/upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import type { Libp2pEvents } from '@libp2p/interface-libp2p'

export interface MockUpgraderInit {
registrar?: Registrar
events: EventEmitter<Libp2pEvents>
events?: EventEmitter<Libp2pEvents>
}

class MockUpgrader implements Upgrader {
private readonly registrar?: Registrar
private readonly events: EventEmitter<Libp2pEvents>
private readonly events?: EventEmitter<Libp2pEvents>

constructor (init: MockUpgraderInit) {
this.registrar = init.registrar
Expand All @@ -26,7 +26,7 @@ class MockUpgrader implements Upgrader {
...opts
})

this.events.safeDispatchEvent('connection:open', { detail: connection })
this.events?.safeDispatchEvent('connection:open', { detail: connection })

return connection
}
Expand All @@ -38,7 +38,7 @@ class MockUpgrader implements Upgrader {
...opts
})

this.events.safeDispatchEvent('connection:open', { detail: connection })
this.events?.safeDispatchEvent('connection:open', { detail: connection })

return connection
}
Expand Down

0 comments on commit 51f4aae

Please sign in to comment.