Bus module fix.
This commit is contained in:
parent
462ba233ed
commit
43ab4586e5
20
lib/bus.js
20
lib/bus.js
|
@ -5,16 +5,16 @@ var util = require('util');
|
|||
|
||||
function Bus(params) {
|
||||
events.EventEmitter.call(this);
|
||||
this.db = params.db;
|
||||
this.node = params.node;
|
||||
}
|
||||
|
||||
util.inherits(Bus, events.EventEmitter);
|
||||
|
||||
Bus.prototype.subscribe = function(name) {
|
||||
var events = this.db.getPublishEvents();
|
||||
var events = this.node.db.getPublishEvents();
|
||||
|
||||
for(var i = 0; i < this.db.modules.length; i++) {
|
||||
var mod = this.db.modules[i];
|
||||
for(var i in this.node.modules) {
|
||||
var mod = this.node.modules[i];
|
||||
events = events.concat(mod.getPublishEvents());
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,10 @@ Bus.prototype.subscribe = function(name) {
|
|||
};
|
||||
|
||||
Bus.prototype.unsubscribe = function(name) {
|
||||
var events = this.db.getPublishEvents();
|
||||
var events = this.node.db.getPublishEvents();
|
||||
|
||||
for(var i = 0; i < this.db.modules.length; i++) {
|
||||
var mod = this.db.modules[i];
|
||||
for(var i in this.node.modules) {
|
||||
var mod = this.node.modules[i];
|
||||
events = events.concat(mod.getPublishEvents());
|
||||
}
|
||||
|
||||
|
@ -47,10 +47,10 @@ Bus.prototype.unsubscribe = function(name) {
|
|||
};
|
||||
|
||||
Bus.prototype.close = function() {
|
||||
var events = this.db.getPublishEvents();
|
||||
var events = this.node.db.getPublishEvents();
|
||||
|
||||
for(var i = 0; i < this.db.modules.length; i++) {
|
||||
var mod = this.db.modules[i];
|
||||
for(var i in this.node.modules) {
|
||||
var mod = this.node.modules[i];
|
||||
events = events.concat(mod.getPublishEvents());
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ function Node(config) {
|
|||
util.inherits(Node, EventEmitter);
|
||||
|
||||
Node.prototype.openBus = function() {
|
||||
return new Bus({db: this.db});
|
||||
return new Bus({node: this});
|
||||
};
|
||||
|
||||
Node.prototype.addModule = function(service) {
|
||||
|
|
|
@ -18,9 +18,12 @@ describe('Bus', function() {
|
|||
subscribe: subscribeDb
|
||||
}
|
||||
]
|
||||
),
|
||||
modules: [
|
||||
{
|
||||
)
|
||||
};
|
||||
var node = {
|
||||
db: db,
|
||||
modules: {
|
||||
module1: {
|
||||
getPublishEvents: sinon.stub().returns([
|
||||
{
|
||||
name: 'test',
|
||||
|
@ -29,9 +32,9 @@ describe('Bus', function() {
|
|||
}
|
||||
])
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
var bus = new Bus({db: db});
|
||||
var bus = new Bus({node: node});
|
||||
bus.subscribe('dbtest', 'a', 'b', 'c');
|
||||
bus.subscribe('test', 'a', 'b', 'c');
|
||||
subscribeModule.callCount.should.equal(1);
|
||||
|
@ -59,9 +62,12 @@ describe('Bus', function() {
|
|||
unsubscribe: unsubscribeDb
|
||||
}
|
||||
]
|
||||
),
|
||||
modules: [
|
||||
{
|
||||
)
|
||||
};
|
||||
var node = {
|
||||
db: db,
|
||||
modules: {
|
||||
module1: {
|
||||
getPublishEvents: sinon.stub().returns([
|
||||
{
|
||||
name: 'test',
|
||||
|
@ -70,9 +76,9 @@ describe('Bus', function() {
|
|||
}
|
||||
])
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
var bus = new Bus({db: db});
|
||||
var bus = new Bus({node: node});
|
||||
bus.unsubscribe('dbtest', 'a', 'b', 'c');
|
||||
bus.unsubscribe('test', 'a', 'b', 'c');
|
||||
unsubscribeModule.callCount.should.equal(1);
|
||||
|
@ -100,9 +106,12 @@ describe('Bus', function() {
|
|||
unsubscribe: unsubscribeDb
|
||||
}
|
||||
]
|
||||
),
|
||||
modules: [
|
||||
{
|
||||
)
|
||||
};
|
||||
var node = {
|
||||
db: db,
|
||||
modules: {
|
||||
module1: {
|
||||
getPublishEvents: sinon.stub().returns([
|
||||
{
|
||||
name: 'test',
|
||||
|
@ -111,10 +120,9 @@ describe('Bus', function() {
|
|||
}
|
||||
])
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
var bus = new Bus({db: db});
|
||||
var bus = new Bus({node: node});
|
||||
bus.close();
|
||||
|
||||
unsubscribeDb.callCount.should.equal(1);
|
||||
|
|
|
@ -82,10 +82,8 @@ describe('Bitcore Node', function() {
|
|||
describe('#openBus', function() {
|
||||
it('will create a new bus', function() {
|
||||
var node = new Node({});
|
||||
var db = {};
|
||||
node.db = db;
|
||||
var bus = node.openBus();
|
||||
bus.db.should.equal(db);
|
||||
bus.node.should.equal(node);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue