-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (44 loc) · 973 Bytes
/
Copy pathindex.js
File metadata and controls
50 lines (44 loc) · 973 Bytes
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
46
47
48
49
50
/* eslint no-unused-vars:0, no-console:0 */
import EventEmitter from 'events';
/**
* @module Notifier
*/
/**
* The Notifier class
* @class
*/
class Notifier extends EventEmitter {
/**
* Create an instance of Notifier class
* @param {config} config - the global config options
*/
constructor(config) {
super();
this.subscribers = {};
}
/**
* create a subscriber
* @param {string} name - the key name of the subscribers
* @return {object} ins - the instance of event emitter
*/
subscribe(name) {
this.subscribers[name] = new EventEmitter();
return this.subscribers[name];
}
/**
* Notify all the subscribers
*/
notifyAll(...args) {
this.emit(...args);
}
/**
* Notify a subscribers
* @param {string} name - whom to notify
*/
notify(name, ...args) {
if (this.subscribers[name] instanceof EventEmitter) {
this.subscribers[name].emit(...args);
}
}
}
export default Notifier;