emittery 0.9.2 → 0.10.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.d.ts +9 -7
- package/index.js +6 -1
- package/package.json +2 -2
- package/readme.md +1 -1
package/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ type DatalessEventNames<EventData> = {
|
|
|
14
14
|
|
|
15
15
|
declare const listenerAdded: unique symbol;
|
|
16
16
|
declare const listenerRemoved: unique symbol;
|
|
17
|
-
type
|
|
17
|
+
type _OmnipresentEventData = {[listenerAdded]: Emittery.ListenerChangedData; [listenerRemoved]: Emittery.ListenerChangedData};
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
Emittery can collect and log debug information.
|
|
@@ -165,7 +165,7 @@ emitter.emit('other');
|
|
|
165
165
|
*/
|
|
166
166
|
declare class Emittery<
|
|
167
167
|
EventData = Record<string, any>, // When https://github.com/microsoft/TypeScript/issues/1863 ships, we can switch this to have an index signature including Symbols. If you want to use symbol keys right now, you need to pass an interface with those symbol keys explicitly listed.
|
|
168
|
-
AllEventData = EventData &
|
|
168
|
+
AllEventData = EventData & _OmnipresentEventData,
|
|
169
169
|
DatalessEvents = DatalessEventNames<EventData>
|
|
170
170
|
> {
|
|
171
171
|
/**
|
|
@@ -313,7 +313,7 @@ declare class Emittery<
|
|
|
313
313
|
```
|
|
314
314
|
*/
|
|
315
315
|
on<Name extends keyof AllEventData>(
|
|
316
|
-
eventName: Name,
|
|
316
|
+
eventName: Name | Name[],
|
|
317
317
|
listener: (eventData: AllEventData[Name]) => void | Promise<void>
|
|
318
318
|
): Emittery.UnsubscribeFn;
|
|
319
319
|
|
|
@@ -428,7 +428,7 @@ declare class Emittery<
|
|
|
428
428
|
```
|
|
429
429
|
*/
|
|
430
430
|
off<Name extends keyof AllEventData>(
|
|
431
|
-
eventName: Name,
|
|
431
|
+
eventName: Name | Name[],
|
|
432
432
|
listener: (eventData: AllEventData[Name]) => void | Promise<void>
|
|
433
433
|
): void;
|
|
434
434
|
|
|
@@ -457,7 +457,7 @@ declare class Emittery<
|
|
|
457
457
|
emitter.emit('🐶', '🍖'); // Nothing happens
|
|
458
458
|
```
|
|
459
459
|
*/
|
|
460
|
-
once<Name extends keyof AllEventData>(eventName: Name): Promise<AllEventData[Name]>;
|
|
460
|
+
once<Name extends keyof AllEventData>(eventName: Name | Name[]): Promise<AllEventData[Name]>;
|
|
461
461
|
|
|
462
462
|
/**
|
|
463
463
|
Trigger an event asynchronously, optionally with some data. Listeners are called in the order they were added, but executed concurrently.
|
|
@@ -548,12 +548,12 @@ declare class Emittery<
|
|
|
548
548
|
|
|
549
549
|
If `eventName` is given, only the listeners for that event are cleared.
|
|
550
550
|
*/
|
|
551
|
-
clearListeners(eventName?:
|
|
551
|
+
clearListeners<Name extends keyof EventData>(eventName?: Name | Name[]): void;
|
|
552
552
|
|
|
553
553
|
/**
|
|
554
554
|
The number of listeners for the `eventName` or all events if not specified.
|
|
555
555
|
*/
|
|
556
|
-
listenerCount(eventName?:
|
|
556
|
+
listenerCount<Name extends keyof EventData>(eventName?: Name | Name[]): number;
|
|
557
557
|
|
|
558
558
|
/**
|
|
559
559
|
Bind the given `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the `target` object.
|
|
@@ -592,6 +592,8 @@ declare namespace Emittery {
|
|
|
592
592
|
*/
|
|
593
593
|
eventName?: EventName;
|
|
594
594
|
}
|
|
595
|
+
|
|
596
|
+
type OmnipresentEventData = _OmnipresentEventData;
|
|
595
597
|
}
|
|
596
598
|
|
|
597
599
|
export = Emittery;
|
package/index.js
CHANGED
|
@@ -216,7 +216,12 @@ class Emittery {
|
|
|
216
216
|
|
|
217
217
|
if (!this.debug.logger) {
|
|
218
218
|
this.debug.logger = (type, debugName, eventName, eventData) => {
|
|
219
|
-
|
|
219
|
+
try {
|
|
220
|
+
// TODO: Use https://github.com/sindresorhus/safe-stringify when the package is more mature. Just copy-paste the code.
|
|
221
|
+
eventData = JSON.stringify(eventData);
|
|
222
|
+
} catch {
|
|
223
|
+
eventData = `Object with the following keys failed to stringify: ${Object.keys(eventData).join(',')}`;
|
|
224
|
+
}
|
|
220
225
|
|
|
221
226
|
if (typeof eventName === 'symbol') {
|
|
222
227
|
eventName = eventName.toString();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emittery",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "Simple and modern async event emitter",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/emittery",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"delay": "^4.3.0",
|
|
54
54
|
"nyc": "^15.0.0",
|
|
55
55
|
"p-event": "^4.1.0",
|
|
56
|
-
"tsd": "^0.
|
|
56
|
+
"tsd": "^0.19.1",
|
|
57
57
|
"xo": "^0.39.0"
|
|
58
58
|
},
|
|
59
59
|
"nyc": {
|