File: index.js

package info (click to toggle)
node-sparkles 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 108 kB
  • ctags: 28
  • sloc: makefile: 2; sh: 2
file content (45 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';

var EventEmitter = require('events').EventEmitter;

var sparklesNamespace = 'store@sparkles';
var defaultNamespace = 'default';

function getStore(){
  var store = global[sparklesNamespace];

  if(!store){
    store = global[sparklesNamespace] = {};
  }

  return store;
}

function getEmitter(namespace){

  var store = getStore();

  namespace = namespace || defaultNamespace;

  var ee = store[namespace];

  if(!ee){
    ee = store[namespace] = new EventEmitter();
    ee.setMaxListeners(0);
    ee.remove = function remove(){
      ee.removeAllListeners();
      delete store[namespace];
    };
  }

  return ee;
}

function exists(namespace){
  var store = getStore();

  return !!(store[namespace]);
}

module.exports = getEmitter;
module.exports.exists = exists;