Skip to content

Commit

Permalink
chore: remove _pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Jul 15, 2019
1 parent 4a1b05e commit 1dd19c2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"libp2p-delegated-content-routing": "^0.2.2",
"libp2p-delegated-peer-routing": "^0.2.2",
"libp2p-floodsub": "~0.17.0",
"libp2p-gossipsub": "ChainSafe/gossipsub-js#master",
"libp2p-gossipsub": "~0.0.3",
"libp2p-kad-dht": "^0.15.2",
"libp2p-mdns": "^0.12.3",
"libp2p-mplex": "^0.8.4",
Expand Down
13 changes: 5 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ class Libp2p extends EventEmitter {

// start pubsub
if (this._config.pubsub.enabled) {
const Pubsub = this._modules.pubsub

this._pubsub = new Pubsub(this)
this.pubsub = pubsub(this)
this.pubsub = pubsub(this, this._modules.pubsub)
}

// Attach remaining APIs
Expand Down Expand Up @@ -398,8 +395,8 @@ class Libp2p extends EventEmitter {
}
},
(cb) => {
if (this._pubsub) {
return this._pubsub.start(cb)
if (this.pubsub) {
return this.pubsub.start(cb)
}
cb()
},
Expand Down Expand Up @@ -437,8 +434,8 @@ class Libp2p extends EventEmitter {
)
},
(cb) => {
if (this._pubsub) {
return this._pubsub.stop(cb)
if (this.pubsub) {
return this.pubsub.stop(cb)
}
cb()
},
Expand Down
10 changes: 7 additions & 3 deletions src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const { messages, codes } = require('./errors')

const errCode = require('err-code')

module.exports = (node) => {
const pubsub = node._pubsub
module.exports = (node, Pubsub) => {
const pubsub = new Pubsub(node)

return {
subscribe: (topic, options, handler, callback) => {
Expand Down Expand Up @@ -94,6 +94,10 @@ module.exports = (node) => {

setMaxListeners (n) {
return pubsub.setMaxListeners(n)
}
},

start: (cb) => pubsub.start(cb),

stop: (cb) => pubsub.stop(cb)
}
}
2 changes: 1 addition & 1 deletion test/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('libp2p creation', () => {
let sw = node._switch
let cm = node.connectionManager
let dht = node._dht
let pub = node._pubsub
let pub = node.pubsub

sinon.spy(sw, 'start')
sinon.spy(cm, 'start')
Expand Down

0 comments on commit 1dd19c2

Please sign in to comment.