Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
732 bytes
|
Line | |
---|
1 | 'use strict'
|
---|
2 |
|
---|
3 | class EmitterWrapper {
|
---|
4 | constructor (emitter) {
|
---|
5 | this.listeners = {}
|
---|
6 | this.emitter = emitter
|
---|
7 | }
|
---|
8 |
|
---|
9 | addListener (event, listener) {
|
---|
10 | this.emitter.addListener(event, listener)
|
---|
11 | this.listeners[event] = this.listeners[event] || []
|
---|
12 | this.listeners[event].push(listener)
|
---|
13 | return this
|
---|
14 | }
|
---|
15 |
|
---|
16 | on (event, listener) {
|
---|
17 | return this.addListener(event, listener)
|
---|
18 | }
|
---|
19 |
|
---|
20 | removeAllListeners (event) {
|
---|
21 | const events = event ? [event] : Object.keys(this.listeners)
|
---|
22 | events.forEach((event) => {
|
---|
23 | this.listeners[event].forEach((listener) => {
|
---|
24 | this.emitter.removeListener(event, listener)
|
---|
25 | })
|
---|
26 | delete this.listeners[event]
|
---|
27 | })
|
---|
28 |
|
---|
29 | return this
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | module.exports = EmitterWrapper
|
---|
Note:
See
TracBrowser
for help on using the repository browser.