emittery 1.0.1 → 1.0.2
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 +7 -5
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -10,8 +10,10 @@ const listenerRemoved = Symbol('listenerRemoved');
|
|
|
10
10
|
let canEmitMetaEvents = false;
|
|
11
11
|
let isGlobalDebugEnabled = false;
|
|
12
12
|
|
|
13
|
+
const isEventKeyType = key => typeof key === 'string' || typeof key === 'symbol' || typeof key === 'number';
|
|
14
|
+
|
|
13
15
|
function assertEventName(eventName) {
|
|
14
|
-
if (
|
|
16
|
+
if (!isEventKeyType(eventName)) {
|
|
15
17
|
throw new TypeError('`eventName` must be a string, symbol, or number');
|
|
16
18
|
}
|
|
17
19
|
}
|
|
@@ -32,7 +34,7 @@ function getListeners(instance, eventName) {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
function getEventProducers(instance, eventName) {
|
|
35
|
-
const key =
|
|
37
|
+
const key = isEventKeyType(eventName) ? eventName : anyProducer;
|
|
36
38
|
const producers = producersMap.get(instance);
|
|
37
39
|
if (!producers.has(key)) {
|
|
38
40
|
return;
|
|
@@ -432,7 +434,7 @@ export default class Emittery {
|
|
|
432
434
|
for (const eventName of eventNames) {
|
|
433
435
|
this.logIfDebugEnabled('clear', eventName, undefined);
|
|
434
436
|
|
|
435
|
-
if (
|
|
437
|
+
if (isEventKeyType(eventName)) {
|
|
436
438
|
const set = getListeners(this, eventName);
|
|
437
439
|
if (set) {
|
|
438
440
|
set.clear();
|
|
@@ -471,7 +473,7 @@ export default class Emittery {
|
|
|
471
473
|
let count = 0;
|
|
472
474
|
|
|
473
475
|
for (const eventName of eventNames) {
|
|
474
|
-
if (
|
|
476
|
+
if (isEventKeyType(eventName)) {
|
|
475
477
|
count += anyMap.get(this).size
|
|
476
478
|
+ (getListeners(this, eventName)?.size ?? 0)
|
|
477
479
|
+ (getEventProducers(this, eventName)?.size ?? 0)
|
|
@@ -480,7 +482,7 @@ export default class Emittery {
|
|
|
480
482
|
continue;
|
|
481
483
|
}
|
|
482
484
|
|
|
483
|
-
if (
|
|
485
|
+
if (eventName !== undefined) {
|
|
484
486
|
assertEventName(eventName);
|
|
485
487
|
}
|
|
486
488
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emittery",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Simple and modern async event emitter",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/emittery",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": "./index.js",
|
|
15
15
|
"types": "./index.d.ts",
|
|
16
|
+
"sideEffects": false,
|
|
16
17
|
"engines": {
|
|
17
18
|
"node": ">=14.16"
|
|
18
19
|
},
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"nyc": "^15.1.0",
|
|
59
60
|
"p-event": "^5.0.1",
|
|
60
61
|
"tsd": "^0.23.0",
|
|
61
|
-
"xo": "^0.
|
|
62
|
+
"xo": "^0.55.0"
|
|
62
63
|
},
|
|
63
64
|
"nyc": {
|
|
64
65
|
"reporter": [
|