Skip to content

Commit

Permalink
fix: demand pubsub subclass instead of pubsub instance (#922)
Browse files Browse the repository at this point in the history
Changes the `Libp2pModules.pubsub` property to be a class that maybe
extends `PubsubBaseProtocol` instead of an instance of that class.
  • Loading branch information
achingbrain authored Apr 21, 2021
1 parent cc1f4af commit 086b0ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @property {PeerRoutingModule[]} [peerRouting]
* @property {ContentRoutingModule[]} [contentRouting]
* @property {Object} [dht]
* @property {Pubsub} [pubsub]
* @property {{new(...args: any[]): Pubsub}} [pubsub]
* @property {Protector} [connProtector]
*
* @typedef {Object} Libp2pOptions
Expand Down
5 changes: 3 additions & 2 deletions src/pubsub-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/

/**
* @param {import("libp2p-interfaces/src/pubsub")} PubsubRouter
* @param {{new(...args: any[]): PubsubRouter}} PubsubRouter
* @param {import('.')} libp2p
* @param {{ enabled: boolean; } & import(".").PubsubLocalOptions & import("libp2p-interfaces/src/pubsub").PubsubOptions} options
*/
function pubsubAdapter (PubsubRouter, libp2p, options) {
// @ts-ignore Pubsub constructor type not defined
/** @type {PubsubRouter & { _subscribeAdapter: PubsubRouter['subscribe'], _unsubscribeAdapter: PubsubRouter['unsubscribe'] }} */
// @ts-ignore we set the extra _subscribeAdapter and _unsubscribeAdapter properties afterwards
const pubsub = new PubsubRouter(libp2p, options)
pubsub._subscribeAdapter = pubsub.subscribe
pubsub._unsubscribeAdapter = pubsub.unsubscribe
Expand Down

0 comments on commit 086b0ec

Please sign in to comment.