bare-events 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +25 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -30,6 +30,17 @@ class EventListener {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
removeAll (ctx, name) {
|
|
34
|
+
const list = [...this.list]
|
|
35
|
+
this.list = []
|
|
36
|
+
|
|
37
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
38
|
+
ctx.emit('removeListener', name, list[i][0]) // Emit AFTER removing
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this.list.length === 0) delete ctx._events[name]
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
emit (ctx, name, ...args) {
|
|
34
45
|
const list = [...this.list]
|
|
35
46
|
|
|
@@ -120,6 +131,20 @@ module.exports = exports = class EventEmitter {
|
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
setMaxListeners (n) {}
|
|
134
|
+
|
|
135
|
+
removeAllListeners (name) {
|
|
136
|
+
if (arguments.length === 0) {
|
|
137
|
+
for (const key of Reflect.ownKeys(this._events)) {
|
|
138
|
+
if (key === 'removeListener') continue
|
|
139
|
+
this.removeAllListeners(key)
|
|
140
|
+
}
|
|
141
|
+
this.removeAllListeners('removeListener')
|
|
142
|
+
} else {
|
|
143
|
+
const e = this._events[name]
|
|
144
|
+
if (e !== undefined) e.removeAll(this, name)
|
|
145
|
+
}
|
|
146
|
+
return this
|
|
147
|
+
}
|
|
123
148
|
}
|
|
124
149
|
|
|
125
150
|
exports.EventEmitter = exports
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-events",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Event emitters for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/holepunchto/bare-events.git"
|
|
15
|
+
"url": "git+https://github.com/holepunchto/bare-events.git"
|
|
16
16
|
},
|
|
17
17
|
"author": "Holepunch",
|
|
18
18
|
"license": "Apache-2.0",
|