wallet-core/node_modules/sparkles/index.js

46 lines
794 B
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02:00
'use strict';
var EventEmitter = require('events').EventEmitter;
var sparklesNamespace = 'store@sparkles';
var defaultNamespace = 'default';
2018-09-20 02:56:13 +02:00
function getStore() {
2016-10-10 03:43:44 +02:00
var store = global[sparklesNamespace];
2018-09-20 02:56:13 +02:00
if (!store) {
2016-10-10 03:43:44 +02:00
store = global[sparklesNamespace] = {};
}
return store;
}
2018-09-20 02:56:13 +02:00
function getEmitter(namespace) {
2016-10-10 03:43:44 +02:00
var store = getStore();
namespace = namespace || defaultNamespace;
var ee = store[namespace];
2018-09-20 02:56:13 +02:00
if (!ee) {
2016-10-10 03:43:44 +02:00
ee = store[namespace] = new EventEmitter();
ee.setMaxListeners(0);
2018-09-20 02:56:13 +02:00
ee.remove = function remove() {
2016-10-10 03:43:44 +02:00
ee.removeAllListeners();
delete store[namespace];
};
}
return ee;
}
2018-09-20 02:56:13 +02:00
function exists(namespace) {
2016-10-10 03:43:44 +02:00
var store = getStore();
return !!(store[namespace]);
}
module.exports = getEmitter;
module.exports.exists = exists;