Skip to content

Commit

Permalink
chore: remove _pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored and jacobheun committed Jul 12, 2019
1 parent f28d923 commit 2b76101
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
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 2b76101

Please sign in to comment.