bare-events 2.8.2 → 2.8.3
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/package.json +7 -5
- package/web.js +32 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-events",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.3",
|
|
4
4
|
"description": "Event emitters for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package": "./package.json",
|
|
@@ -28,10 +28,11 @@
|
|
|
28
28
|
"lib"
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"test
|
|
34
|
-
"
|
|
31
|
+
"format": "prettier --write . && lunte --fix",
|
|
32
|
+
"lint": "prettier --check . && lunte",
|
|
33
|
+
"test": "npm run test:bare && npm run test:node",
|
|
34
|
+
"test:bare": "brittle-bare --coverage test.js",
|
|
35
|
+
"test:node": "brittle-node --coverage test.js"
|
|
35
36
|
},
|
|
36
37
|
"repository": {
|
|
37
38
|
"type": "git",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"bare-abort-controller": "^1.0.0",
|
|
48
49
|
"brittle": "^3.3.2",
|
|
50
|
+
"lunte": "^1.8.0",
|
|
49
51
|
"prettier": "^3.4.2",
|
|
50
52
|
"prettier-config-holepunch": "^2.0.0",
|
|
51
53
|
"uncaughts": "^1.1.1"
|
package/web.js
CHANGED
|
@@ -10,6 +10,7 @@ const STOP = 0x20
|
|
|
10
10
|
const CAPTURE = 0x1
|
|
11
11
|
const PASSIVE = 0x2
|
|
12
12
|
const ONCE = 0x4
|
|
13
|
+
const REMOVED = 0x8
|
|
13
14
|
|
|
14
15
|
// https://dom.spec.whatwg.org/#event
|
|
15
16
|
class Event {
|
|
@@ -144,8 +145,7 @@ exports.EventTarget = class EventTarget {
|
|
|
144
145
|
|
|
145
146
|
const listeners = this._listeners.get(type)
|
|
146
147
|
|
|
147
|
-
if (listeners
|
|
148
|
-
else {
|
|
148
|
+
if (listeners !== undefined) {
|
|
149
149
|
for (const existing of listeners) {
|
|
150
150
|
if (callback === existing.callback && capture === existing.capture) {
|
|
151
151
|
return // Duplicate listener
|
|
@@ -153,13 +153,16 @@ exports.EventTarget = class EventTarget {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
listener.link(listeners)
|
|
156
|
+
} else {
|
|
157
|
+
this._listeners.set(type, listener)
|
|
158
|
+
}
|
|
156
159
|
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
if (signal !== null) {
|
|
161
|
+
const self = this
|
|
162
|
+
signal.addEventListener('abort', onabort)
|
|
159
163
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
164
|
+
function onabort() {
|
|
165
|
+
self._unlink(type, listener)
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
}
|
|
@@ -176,10 +179,7 @@ exports.EventTarget = class EventTarget {
|
|
|
176
179
|
|
|
177
180
|
for (const existing of listeners) {
|
|
178
181
|
if (callback === existing.callback && capture === existing.capture) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (listeners === existing) this._listeners.set(type, next)
|
|
182
|
-
|
|
182
|
+
this._unlink(type, existing)
|
|
183
183
|
return
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -195,10 +195,14 @@ exports.EventTarget = class EventTarget {
|
|
|
195
195
|
try {
|
|
196
196
|
if (listeners === undefined) return true
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
const snapshot = Array.from(listeners)
|
|
199
|
+
|
|
200
|
+
for (const listener of snapshot) {
|
|
199
201
|
// https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke
|
|
200
202
|
|
|
201
|
-
if (listener.
|
|
203
|
+
if (listener.removed) continue
|
|
204
|
+
|
|
205
|
+
if (listener.once) this._unlink(event.type, listener)
|
|
202
206
|
|
|
203
207
|
let callback = listener.callback
|
|
204
208
|
let context = this
|
|
@@ -229,6 +233,18 @@ exports.EventTarget = class EventTarget {
|
|
|
229
233
|
__proto__: { constructor: EventTarget }
|
|
230
234
|
}
|
|
231
235
|
}
|
|
236
|
+
|
|
237
|
+
_unlink(type, listener) {
|
|
238
|
+
if (listener.removed) return
|
|
239
|
+
|
|
240
|
+
const head = this._listeners.get(type)
|
|
241
|
+
const next = listener.unlink()
|
|
242
|
+
|
|
243
|
+
if (head === listener) {
|
|
244
|
+
if (next === listener) this._listeners.delete(type)
|
|
245
|
+
else this._listeners.set(type, next)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
232
248
|
}
|
|
233
249
|
|
|
234
250
|
// https://dom.spec.whatwg.org/#concept-event-listener
|
|
@@ -268,7 +284,7 @@ class EventListener {
|
|
|
268
284
|
}
|
|
269
285
|
|
|
270
286
|
get removed() {
|
|
271
|
-
return this.
|
|
287
|
+
return (this._state & REMOVED) !== 0
|
|
272
288
|
}
|
|
273
289
|
|
|
274
290
|
link(listener) {
|
|
@@ -287,6 +303,8 @@ class EventListener {
|
|
|
287
303
|
unlink() {
|
|
288
304
|
if (this.removed) return this
|
|
289
305
|
|
|
306
|
+
this._state |= REMOVED
|
|
307
|
+
|
|
290
308
|
const next = this._next
|
|
291
309
|
const previous = this._previous
|
|
292
310
|
|