|
|
|
@ -3,22 +3,6 @@
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
|
|
|
|
|
var real;
|
|
|
|
|
var fake = {
|
|
|
|
|
publishQueue: [],
|
|
|
|
|
publish: function (event, data) {
|
|
|
|
|
fake.publishQueue.push({ event: event, data: data });
|
|
|
|
|
},
|
|
|
|
|
listenQueue: {},
|
|
|
|
|
on: function (event, callback) {
|
|
|
|
|
if (!Object.prototype.hasOwnProperty.call(fake.listenQueue, event)) {
|
|
|
|
|
fake.listenQueue[event] = [];
|
|
|
|
|
}
|
|
|
|
|
fake.listenQueue[event].push(callback);
|
|
|
|
|
},
|
|
|
|
|
removeAllListeners: function (event) {
|
|
|
|
|
delete fake.listenQueue[event];
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function get() {
|
|
|
|
|
if (real) {
|
|
|
|
@ -37,22 +21,7 @@ function get() {
|
|
|
|
|
pubsub = require('./database/mongo/pubsub');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pubsub) {
|
|
|
|
|
return fake;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object.keys(fake.listenQueue).forEach(function (event) {
|
|
|
|
|
fake.listenQueue[event].forEach(function (callback) {
|
|
|
|
|
pubsub.on(event, callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fake.publishQueue.forEach(function (msg) {
|
|
|
|
|
pubsub.publish(msg.event, msg.data);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
real = pubsub;
|
|
|
|
|
fake = null;
|
|
|
|
|
|
|
|
|
|
return pubsub;
|
|
|
|
|
}
|
|
|
|
|