@xylabs/events 5.0.83 → 5.0.86
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/README.md +514 -617
- package/dist/neutral/BaseEmitter.d.ts +52 -0
- package/dist/neutral/BaseEmitter.d.ts.map +1 -1
- package/dist/neutral/Events/Events.d.ts +67 -0
- package/dist/neutral/Events/Events.d.ts.map +1 -1
- package/dist/neutral/index.mjs +106 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/model/Event.d.ts +13 -0
- package/dist/neutral/model/Event.d.ts.map +1 -1
- package/dist/neutral/model/EventEmitter.d.ts +11 -0
- package/dist/neutral/model/EventEmitter.d.ts.map +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/events**
|
|
@@ -23,28 +25,34 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Classes
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
| Class | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [BaseEmitter](#classes/BaseEmitter) | Base class that combines the Base utility class with typed event emission capabilities. Delegates all event operations to an internal Events instance. |
|
|
31
|
+
| [Events](#classes/Events) | Core typed event emitter implementation supporting named events, wildcard listeners, serial and concurrent emission, listener filtering, and debug logging. |
|
|
28
32
|
|
|
29
33
|
## Interfaces
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
| Interface | Description |
|
|
36
|
+
| ------ | ------ |
|
|
37
|
+
| [BaseEmitterParamsFields](#interfaces/BaseEmitterParamsFields) | Fields specific to BaseEmitter configuration parameters. |
|
|
38
|
+
| [EventEmitter](#interfaces/EventEmitter) | Interface for a typed event emitter that supports subscribing, unsubscribing, and emitting events. |
|
|
33
39
|
|
|
34
40
|
## Type Aliases
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
| Type Alias | Description |
|
|
43
|
+
| ------ | ------ |
|
|
44
|
+
| [BaseEmitterParams](#type-aliases/BaseEmitterParams) | Parameters type for configuring a BaseEmitter instance. |
|
|
45
|
+
| [DebugLogger](#type-aliases/DebugLogger) | Emittery can collect and log debug information. |
|
|
46
|
+
| [EventListenerInfo](#type-aliases/EventListenerInfo) | Information about a registered event listener, including an optional filter for selective invocation. |
|
|
47
|
+
| [DebugOptions](#type-aliases/DebugOptions) | Configure debug options of an instance. |
|
|
48
|
+
| [MetaEventData](#type-aliases/MetaEventData) | Data shape for internal meta events that fire when listeners are added or removed. |
|
|
49
|
+
| [EventsParams](#type-aliases/EventsParams) | Parameters for constructing an Events instance, with optional debug configuration. |
|
|
50
|
+
| [EventName](#type-aliases/EventName) | A valid event name, which can be any property key (string, number, or symbol). |
|
|
51
|
+
| [EventArgs](#type-aliases/EventArgs) | The allowed types for event argument payloads. |
|
|
52
|
+
| [EventData](#type-aliases/EventData) | A mapping of event names to their corresponding event argument types. |
|
|
53
|
+
| [EventUnsubscribeFunction](#type-aliases/EventUnsubscribeFunction) | A function returned by event subscription methods that unsubscribes the listener when called. |
|
|
54
|
+
| [EventAnyListener](#type-aliases/EventAnyListener) | A listener that receives all events regardless of name. |
|
|
55
|
+
| [EventListener](#type-aliases/EventListener) | A listener for a specific event type. |
|
|
48
56
|
|
|
49
57
|
### classes
|
|
50
58
|
|
|
@@ -54,19 +62,19 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
54
62
|
|
|
55
63
|
***
|
|
56
64
|
|
|
65
|
+
Base class that combines the Base utility class with typed event emission capabilities.
|
|
66
|
+
Delegates all event operations to an internal Events instance.
|
|
67
|
+
|
|
57
68
|
## Extends
|
|
58
69
|
|
|
59
70
|
- `Base`\<`TParams`\>
|
|
60
71
|
|
|
61
72
|
## Type Parameters
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
`TParams` *extends* `BaseParams`
|
|
66
|
-
|
|
67
|
-
### TEventData
|
|
68
|
-
|
|
69
|
-
`TEventData` *extends* [`EventData`](#../type-aliases/EventData) = [`EventData`](#../type-aliases/EventData)
|
|
74
|
+
| Type Parameter | Default type |
|
|
75
|
+
| ------ | ------ |
|
|
76
|
+
| `TParams` *extends* `BaseParams` | `BaseParams` |
|
|
77
|
+
| `TEventData` *extends* [`EventData`](#../type-aliases/EventData) | [`EventData`](#../type-aliases/EventData) |
|
|
70
78
|
|
|
71
79
|
## Implements
|
|
72
80
|
|
|
@@ -77,14 +85,14 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
77
85
|
### Constructor
|
|
78
86
|
|
|
79
87
|
```ts
|
|
80
|
-
new BaseEmitter<TParams, TEventData>(params): BaseEmitter<TParams, TEventData>;
|
|
88
|
+
new BaseEmitter<TParams, TEventData>(params: BaseParams<TParams>): BaseEmitter<TParams, TEventData>;
|
|
81
89
|
```
|
|
82
90
|
|
|
83
91
|
### Parameters
|
|
84
92
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
`BaseParams`\<`TParams`\>
|
|
93
|
+
| Parameter | Type |
|
|
94
|
+
| ------ | ------ |
|
|
95
|
+
| `params` | `BaseParams`\<`TParams`\> |
|
|
88
96
|
|
|
89
97
|
### Returns
|
|
90
98
|
|
|
@@ -98,57 +106,12 @@ Base<TParams>.constructor
|
|
|
98
106
|
|
|
99
107
|
## Properties
|
|
100
108
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
### Inherited from
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
Base.defaultLogger
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
***
|
|
114
|
-
|
|
115
|
-
### globalInstances
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]>;
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Inherited from
|
|
122
|
-
|
|
123
|
-
```ts
|
|
124
|
-
Base.globalInstances
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
***
|
|
128
|
-
|
|
129
|
-
### globalInstancesCountHistory
|
|
130
|
-
|
|
131
|
-
```ts
|
|
132
|
-
readonly static globalInstancesCountHistory: Record<BaseClassName, number[]>;
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Inherited from
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
Base.globalInstancesCountHistory
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
***
|
|
142
|
-
|
|
143
|
-
### eventData
|
|
144
|
-
|
|
145
|
-
```ts
|
|
146
|
-
eventData: TEventData;
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Implementation of
|
|
150
|
-
|
|
151
|
-
[`EventEmitter`](#../interfaces/EventEmitter).[`eventData`](../interfaces/EventEmitter.md#eventdata)
|
|
109
|
+
| Property | Modifier | Type | Description | Inherited from |
|
|
110
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
111
|
+
| <a id="defaultlogger"></a> `defaultLogger?` | `static` | `Logger` | - | `Base.defaultLogger` |
|
|
112
|
+
| <a id="globalinstances"></a> `globalInstances` | `readonly` | `Record`\<`BaseClassName`, `WeakRef`\<`Base`\>[]\> | - | `Base.globalInstances` |
|
|
113
|
+
| <a id="globalinstancescounthistory"></a> `globalInstancesCountHistory` | `readonly` | `Record`\<`BaseClassName`, `number`[]\> | - | `Base.globalInstancesCountHistory` |
|
|
114
|
+
| <a id="eventdata"></a> `eventData` | `public` | `TEventData` | Type-level reference to the event data shape for external type queries. | - |
|
|
152
115
|
|
|
153
116
|
## Accessors
|
|
154
117
|
|
|
@@ -167,14 +130,14 @@ get static historyInterval(): number;
|
|
|
167
130
|
### Set Signature
|
|
168
131
|
|
|
169
132
|
```ts
|
|
170
|
-
set static historyInterval(value): void;
|
|
133
|
+
set static historyInterval(value: number): void;
|
|
171
134
|
```
|
|
172
135
|
|
|
173
136
|
#### Parameters
|
|
174
137
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
`number`
|
|
138
|
+
| Parameter | Type |
|
|
139
|
+
| ------ | ------ |
|
|
140
|
+
| `value` | `number` |
|
|
178
141
|
|
|
179
142
|
#### Returns
|
|
180
143
|
|
|
@@ -203,14 +166,14 @@ get static historyTime(): number;
|
|
|
203
166
|
### Set Signature
|
|
204
167
|
|
|
205
168
|
```ts
|
|
206
|
-
set static historyTime(value): void;
|
|
169
|
+
set static historyTime(value: number): void;
|
|
207
170
|
```
|
|
208
171
|
|
|
209
172
|
#### Parameters
|
|
210
173
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
`number`
|
|
174
|
+
| Parameter | Type |
|
|
175
|
+
| ------ | ------ |
|
|
176
|
+
| `value` | `number` |
|
|
214
177
|
|
|
215
178
|
#### Returns
|
|
216
179
|
|
|
@@ -239,14 +202,14 @@ get static maxGcFrequency(): number;
|
|
|
239
202
|
### Set Signature
|
|
240
203
|
|
|
241
204
|
```ts
|
|
242
|
-
set static maxGcFrequency(value): void;
|
|
205
|
+
set static maxGcFrequency(value: number): void;
|
|
243
206
|
```
|
|
244
207
|
|
|
245
208
|
#### Parameters
|
|
246
209
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
`number`
|
|
210
|
+
| Parameter | Type |
|
|
211
|
+
| ------ | ------ |
|
|
212
|
+
| `value` | `number` |
|
|
250
213
|
|
|
251
214
|
#### Returns
|
|
252
215
|
|
|
@@ -365,14 +328,14 @@ Base.tracer
|
|
|
365
328
|
### Call Signature
|
|
366
329
|
|
|
367
330
|
```ts
|
|
368
|
-
static gc(force
|
|
331
|
+
static gc(force?: boolean): void;
|
|
369
332
|
```
|
|
370
333
|
|
|
371
334
|
#### Parameters
|
|
372
335
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
`boolean`
|
|
336
|
+
| Parameter | Type |
|
|
337
|
+
| ------ | ------ |
|
|
338
|
+
| `force?` | `boolean` |
|
|
376
339
|
|
|
377
340
|
#### Returns
|
|
378
341
|
|
|
@@ -387,14 +350,14 @@ Base.gc
|
|
|
387
350
|
### Call Signature
|
|
388
351
|
|
|
389
352
|
```ts
|
|
390
|
-
static gc(className): void;
|
|
353
|
+
static gc(className: BaseClassName): void;
|
|
391
354
|
```
|
|
392
355
|
|
|
393
356
|
#### Parameters
|
|
394
357
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
`BaseClassName`
|
|
358
|
+
| Parameter | Type |
|
|
359
|
+
| ------ | ------ |
|
|
360
|
+
| `className` | `BaseClassName` |
|
|
398
361
|
|
|
399
362
|
#### Returns
|
|
400
363
|
|
|
@@ -411,14 +374,14 @@ Base.gc
|
|
|
411
374
|
### instanceCount()
|
|
412
375
|
|
|
413
376
|
```ts
|
|
414
|
-
static instanceCount(className): number;
|
|
377
|
+
static instanceCount(className: BaseClassName): number;
|
|
415
378
|
```
|
|
416
379
|
|
|
417
380
|
### Parameters
|
|
418
381
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
`BaseClassName`
|
|
382
|
+
| Parameter | Type |
|
|
383
|
+
| ------ | ------ |
|
|
384
|
+
| `className` | `BaseClassName` |
|
|
422
385
|
|
|
423
386
|
### Returns
|
|
424
387
|
|
|
@@ -489,19 +452,23 @@ Base.stopHistory
|
|
|
489
452
|
### clearListeners()
|
|
490
453
|
|
|
491
454
|
```ts
|
|
492
|
-
clearListeners(eventNames): BaseEmitter<TParams, TEventData>;
|
|
455
|
+
clearListeners(eventNames: keyof TEventData | keyof TEventData[]): BaseEmitter<TParams, TEventData>;
|
|
493
456
|
```
|
|
494
457
|
|
|
495
|
-
|
|
458
|
+
Removes all listeners for the specified event name(s).
|
|
496
459
|
|
|
497
|
-
|
|
460
|
+
### Parameters
|
|
498
461
|
|
|
499
|
-
|
|
462
|
+
| Parameter | Type | Description |
|
|
463
|
+
| ------ | ------ | ------ |
|
|
464
|
+
| `eventNames` | keyof `TEventData` \| keyof `TEventData`[] | One or more event names to clear listeners for. |
|
|
500
465
|
|
|
501
466
|
### Returns
|
|
502
467
|
|
|
503
468
|
`BaseEmitter`\<`TParams`, `TEventData`\>
|
|
504
469
|
|
|
470
|
+
This instance for chaining.
|
|
471
|
+
|
|
505
472
|
### Implementation of
|
|
506
473
|
|
|
507
474
|
[`EventEmitter`](#../interfaces/EventEmitter).[`clearListeners`](../interfaces/EventEmitter.md#clearlisteners)
|
|
@@ -511,28 +478,24 @@ keyof `TEventData` | keyof `TEventData`[]
|
|
|
511
478
|
### emit()
|
|
512
479
|
|
|
513
480
|
```ts
|
|
514
|
-
emit<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
481
|
+
emit<TEventName, TEventArgs>(eventName: TEventName, eventArgs: TEventArgs): Promise<void>;
|
|
515
482
|
```
|
|
516
483
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
#### TEventName
|
|
520
|
-
|
|
521
|
-
`TEventName` *extends* `string` \| `number` \| `symbol` = keyof `TEventData`
|
|
484
|
+
Emits an event, invoking all registered listeners concurrently.
|
|
522
485
|
|
|
523
|
-
|
|
486
|
+
### Type Parameters
|
|
524
487
|
|
|
525
|
-
|
|
488
|
+
| Type Parameter | Default type |
|
|
489
|
+
| ------ | ------ |
|
|
490
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` | keyof `TEventData` |
|
|
491
|
+
| `TEventArgs` *extends* [`EventArgs`](#../type-aliases/EventArgs) | `TEventData`\[`TEventName`\] |
|
|
526
492
|
|
|
527
493
|
### Parameters
|
|
528
494
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
`TEventName`
|
|
532
|
-
|
|
533
|
-
#### eventArgs
|
|
534
|
-
|
|
535
|
-
`TEventArgs`
|
|
495
|
+
| Parameter | Type | Description |
|
|
496
|
+
| ------ | ------ | ------ |
|
|
497
|
+
| `eventName` | `TEventName` | The event to emit. |
|
|
498
|
+
| `eventArgs` | `TEventArgs` | The data to pass to listeners. |
|
|
536
499
|
|
|
537
500
|
### Returns
|
|
538
501
|
|
|
@@ -547,28 +510,24 @@ emit<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
|
547
510
|
### emitSerial()
|
|
548
511
|
|
|
549
512
|
```ts
|
|
550
|
-
emitSerial<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
513
|
+
emitSerial<TEventName, TEventArgs>(eventName: TEventName, eventArgs: TEventArgs): Promise<void>;
|
|
551
514
|
```
|
|
552
515
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
#### TEventName
|
|
556
|
-
|
|
557
|
-
`TEventName` *extends* `string` \| `number` \| `symbol` = keyof `TEventData`
|
|
516
|
+
Emits an event, invoking all registered listeners sequentially in order.
|
|
558
517
|
|
|
559
|
-
|
|
518
|
+
### Type Parameters
|
|
560
519
|
|
|
561
|
-
|
|
520
|
+
| Type Parameter | Default type |
|
|
521
|
+
| ------ | ------ |
|
|
522
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` | keyof `TEventData` |
|
|
523
|
+
| `TEventArgs` *extends* [`EventArgs`](#../type-aliases/EventArgs) | `TEventData`\[`TEventName`\] |
|
|
562
524
|
|
|
563
525
|
### Parameters
|
|
564
526
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
`TEventName`
|
|
568
|
-
|
|
569
|
-
#### eventArgs
|
|
570
|
-
|
|
571
|
-
`TEventArgs`
|
|
527
|
+
| Parameter | Type | Description |
|
|
528
|
+
| ------ | ------ | ------ |
|
|
529
|
+
| `eventName` | `TEventName` | The event to emit. |
|
|
530
|
+
| `eventArgs` | `TEventArgs` | The data to pass to listeners. |
|
|
572
531
|
|
|
573
532
|
### Returns
|
|
574
533
|
|
|
@@ -583,19 +542,23 @@ emitSerial<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
|
583
542
|
### listenerCount()
|
|
584
543
|
|
|
585
544
|
```ts
|
|
586
|
-
listenerCount(eventNames): number;
|
|
545
|
+
listenerCount(eventNames: keyof TEventData | keyof TEventData[]): number;
|
|
587
546
|
```
|
|
588
547
|
|
|
589
|
-
|
|
548
|
+
Returns the total number of listeners registered for the specified event name(s).
|
|
590
549
|
|
|
591
|
-
|
|
550
|
+
### Parameters
|
|
592
551
|
|
|
593
|
-
|
|
552
|
+
| Parameter | Type | Description |
|
|
553
|
+
| ------ | ------ | ------ |
|
|
554
|
+
| `eventNames` | keyof `TEventData` \| keyof `TEventData`[] | One or more event names to count listeners for. |
|
|
594
555
|
|
|
595
556
|
### Returns
|
|
596
557
|
|
|
597
558
|
`number`
|
|
598
559
|
|
|
560
|
+
The total listener count.
|
|
561
|
+
|
|
599
562
|
### Implementation of
|
|
600
563
|
|
|
601
564
|
[`EventEmitter`](#../interfaces/EventEmitter).[`listenerCount`](../interfaces/EventEmitter.md#listenercount)
|
|
@@ -605,24 +568,23 @@ keyof `TEventData` | keyof `TEventData`[]
|
|
|
605
568
|
### off()
|
|
606
569
|
|
|
607
570
|
```ts
|
|
608
|
-
off<TEventName>(eventNames, listener): void;
|
|
571
|
+
off<TEventName>(eventNames: TEventName | TEventName[], listener: EventListener<TEventData[TEventName]>): void;
|
|
609
572
|
```
|
|
610
573
|
|
|
611
|
-
|
|
574
|
+
Removes a specific listener from the specified event name(s).
|
|
612
575
|
|
|
613
|
-
|
|
576
|
+
### Type Parameters
|
|
614
577
|
|
|
615
|
-
|
|
578
|
+
| Type Parameter |
|
|
579
|
+
| ------ |
|
|
580
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
616
581
|
|
|
617
582
|
### Parameters
|
|
618
583
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
`
|
|
622
|
-
|
|
623
|
-
#### listener
|
|
624
|
-
|
|
625
|
-
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
584
|
+
| Parameter | Type | Description |
|
|
585
|
+
| ------ | ------ | ------ |
|
|
586
|
+
| `eventNames` | `TEventName` \| `TEventName`[] | One or more event names to unsubscribe from. |
|
|
587
|
+
| `listener` | [`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\> | The listener to remove. |
|
|
626
588
|
|
|
627
589
|
### Returns
|
|
628
590
|
|
|
@@ -637,14 +599,16 @@ off<TEventName>(eventNames, listener): void;
|
|
|
637
599
|
### offAny()
|
|
638
600
|
|
|
639
601
|
```ts
|
|
640
|
-
offAny(listener): void;
|
|
602
|
+
offAny(listener: EventAnyListener): void;
|
|
641
603
|
```
|
|
642
604
|
|
|
643
|
-
|
|
605
|
+
Removes a wildcard listener that was receiving all events.
|
|
644
606
|
|
|
645
|
-
|
|
607
|
+
### Parameters
|
|
646
608
|
|
|
647
|
-
|
|
609
|
+
| Parameter | Type | Description |
|
|
610
|
+
| ------ | ------ | ------ |
|
|
611
|
+
| `listener` | [`EventAnyListener`](#../type-aliases/EventAnyListener) | The wildcard listener to remove. |
|
|
648
612
|
|
|
649
613
|
### Returns
|
|
650
614
|
|
|
@@ -659,36 +623,37 @@ offAny(listener): void;
|
|
|
659
623
|
### on()
|
|
660
624
|
|
|
661
625
|
```ts
|
|
662
|
-
on<TEventName>(eventNames, listener): (...args) => void;
|
|
626
|
+
on<TEventName>(eventNames: TEventName | TEventName[], listener: EventListener<TEventData[TEventName]>): (...args: []) => void;
|
|
663
627
|
```
|
|
664
628
|
|
|
665
|
-
|
|
629
|
+
Subscribes a listener to the specified event name(s).
|
|
666
630
|
|
|
667
|
-
|
|
631
|
+
### Type Parameters
|
|
668
632
|
|
|
669
|
-
|
|
633
|
+
| Type Parameter |
|
|
634
|
+
| ------ |
|
|
635
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
670
636
|
|
|
671
637
|
### Parameters
|
|
672
638
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
`
|
|
676
|
-
|
|
677
|
-
#### listener
|
|
678
|
-
|
|
679
|
-
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
639
|
+
| Parameter | Type | Description |
|
|
640
|
+
| ------ | ------ | ------ |
|
|
641
|
+
| `eventNames` | `TEventName` \| `TEventName`[] | One or more event names to listen for. |
|
|
642
|
+
| `listener` | [`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\> | The callback to invoke when the event fires. |
|
|
680
643
|
|
|
681
644
|
### Returns
|
|
682
645
|
|
|
646
|
+
An unsubscribe function.
|
|
647
|
+
|
|
683
648
|
```ts
|
|
684
|
-
(...args): void;
|
|
649
|
+
(...args: []): void;
|
|
685
650
|
```
|
|
686
651
|
|
|
687
652
|
#### Parameters
|
|
688
653
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
654
|
+
| Parameter | Type |
|
|
655
|
+
| ------ | ------ |
|
|
656
|
+
| ...`args` | \[\] |
|
|
692
657
|
|
|
693
658
|
#### Returns
|
|
694
659
|
|
|
@@ -703,26 +668,30 @@ on<TEventName>(eventNames, listener): (...args) => void;
|
|
|
703
668
|
### onAny()
|
|
704
669
|
|
|
705
670
|
```ts
|
|
706
|
-
onAny(listener): (...args) => void;
|
|
671
|
+
onAny(listener: EventAnyListener): (...args: []) => void;
|
|
707
672
|
```
|
|
708
673
|
|
|
709
|
-
|
|
674
|
+
Subscribes a wildcard listener that receives all events.
|
|
710
675
|
|
|
711
|
-
|
|
676
|
+
### Parameters
|
|
712
677
|
|
|
713
|
-
|
|
678
|
+
| Parameter | Type | Description |
|
|
679
|
+
| ------ | ------ | ------ |
|
|
680
|
+
| `listener` | [`EventAnyListener`](#../type-aliases/EventAnyListener) | The callback to invoke for any event. |
|
|
714
681
|
|
|
715
682
|
### Returns
|
|
716
683
|
|
|
684
|
+
An unsubscribe function.
|
|
685
|
+
|
|
717
686
|
```ts
|
|
718
|
-
(...args): void;
|
|
687
|
+
(...args: []): void;
|
|
719
688
|
```
|
|
720
689
|
|
|
721
690
|
#### Parameters
|
|
722
691
|
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
692
|
+
| Parameter | Type |
|
|
693
|
+
| ------ | ------ |
|
|
694
|
+
| ...`args` | \[\] |
|
|
726
695
|
|
|
727
696
|
#### Returns
|
|
728
697
|
|
|
@@ -737,36 +706,37 @@ onAny(listener): (...args) => void;
|
|
|
737
706
|
### once()
|
|
738
707
|
|
|
739
708
|
```ts
|
|
740
|
-
once<TEventName>(eventName, listener): (...args) => void;
|
|
709
|
+
once<TEventName>(eventName: TEventName, listener: EventListener<TEventData[TEventName]>): (...args: []) => void;
|
|
741
710
|
```
|
|
742
711
|
|
|
743
|
-
|
|
712
|
+
Subscribes a listener that will be invoked only once for the specified event, then automatically removed.
|
|
744
713
|
|
|
745
|
-
|
|
714
|
+
### Type Parameters
|
|
746
715
|
|
|
747
|
-
|
|
716
|
+
| Type Parameter |
|
|
717
|
+
| ------ |
|
|
718
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
748
719
|
|
|
749
720
|
### Parameters
|
|
750
721
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
`TEventName`
|
|
754
|
-
|
|
755
|
-
#### listener
|
|
756
|
-
|
|
757
|
-
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
722
|
+
| Parameter | Type | Description |
|
|
723
|
+
| ------ | ------ | ------ |
|
|
724
|
+
| `eventName` | `TEventName` | The event to listen for. |
|
|
725
|
+
| `listener` | [`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\> | The callback to invoke once. |
|
|
758
726
|
|
|
759
727
|
### Returns
|
|
760
728
|
|
|
729
|
+
An unsubscribe function.
|
|
730
|
+
|
|
761
731
|
```ts
|
|
762
|
-
(...args): void;
|
|
732
|
+
(...args: []): void;
|
|
763
733
|
```
|
|
764
734
|
|
|
765
735
|
#### Parameters
|
|
766
736
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
737
|
+
| Parameter | Type |
|
|
738
|
+
| ------ | ------ |
|
|
739
|
+
| ...`args` | \[\] |
|
|
770
740
|
|
|
771
741
|
#### Returns
|
|
772
742
|
|
|
@@ -782,15 +752,18 @@ once<TEventName>(eventName, listener): (...args) => void;
|
|
|
782
752
|
|
|
783
753
|
***
|
|
784
754
|
|
|
755
|
+
Core typed event emitter implementation supporting named events, wildcard listeners,
|
|
756
|
+
serial and concurrent emission, listener filtering, and debug logging.
|
|
757
|
+
|
|
785
758
|
## Extends
|
|
786
759
|
|
|
787
760
|
- `Base`\<[`EventsParams`](#../type-aliases/EventsParams)\>
|
|
788
761
|
|
|
789
762
|
## Type Parameters
|
|
790
763
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
`TEventData` *extends* [`EventData`](#../type-aliases/EventData)
|
|
764
|
+
| Type Parameter | Default type |
|
|
765
|
+
| ------ | ------ |
|
|
766
|
+
| `TEventData` *extends* [`EventData`](#../type-aliases/EventData) | [`EventData`](#../type-aliases/EventData) |
|
|
794
767
|
|
|
795
768
|
## Implements
|
|
796
769
|
|
|
@@ -801,14 +774,14 @@ once<TEventName>(eventName, listener): (...args) => void;
|
|
|
801
774
|
### Constructor
|
|
802
775
|
|
|
803
776
|
```ts
|
|
804
|
-
new Events<TEventData>(params
|
|
777
|
+
new Events<TEventData>(params?: EventsParams): Events<TEventData>;
|
|
805
778
|
```
|
|
806
779
|
|
|
807
780
|
### Parameters
|
|
808
781
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
[`EventsParams`](#../type-aliases/EventsParams)
|
|
782
|
+
| Parameter | Type |
|
|
783
|
+
| ------ | ------ |
|
|
784
|
+
| `params` | [`EventsParams`](#../type-aliases/EventsParams) |
|
|
812
785
|
|
|
813
786
|
### Returns
|
|
814
787
|
|
|
@@ -822,73 +795,14 @@ Base<EventsParams>.constructor
|
|
|
822
795
|
|
|
823
796
|
## Properties
|
|
824
797
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
```ts
|
|
834
|
-
Base.defaultLogger
|
|
835
|
-
```
|
|
836
|
-
|
|
837
|
-
***
|
|
838
|
-
|
|
839
|
-
### globalInstances
|
|
840
|
-
|
|
841
|
-
```ts
|
|
842
|
-
readonly static globalInstances: Record<BaseClassName, WeakRef<Base>[]>;
|
|
843
|
-
```
|
|
844
|
-
|
|
845
|
-
### Inherited from
|
|
846
|
-
|
|
847
|
-
```ts
|
|
848
|
-
Base.globalInstances
|
|
849
|
-
```
|
|
850
|
-
|
|
851
|
-
***
|
|
852
|
-
|
|
853
|
-
### globalInstancesCountHistory
|
|
854
|
-
|
|
855
|
-
```ts
|
|
856
|
-
readonly static globalInstancesCountHistory: Record<BaseClassName, number[]>;
|
|
857
|
-
```
|
|
858
|
-
|
|
859
|
-
### Inherited from
|
|
860
|
-
|
|
861
|
-
```ts
|
|
862
|
-
Base.globalInstancesCountHistory
|
|
863
|
-
```
|
|
864
|
-
|
|
865
|
-
***
|
|
866
|
-
|
|
867
|
-
### anyMap
|
|
868
|
-
|
|
869
|
-
```ts
|
|
870
|
-
protected static anyMap: WeakMap<object, Set<EventAnyListener>>;
|
|
871
|
-
```
|
|
872
|
-
|
|
873
|
-
***
|
|
874
|
-
|
|
875
|
-
### eventsMap
|
|
876
|
-
|
|
877
|
-
```ts
|
|
878
|
-
protected static eventsMap: WeakMap<object, Map<PropertyKey, Set<EventListenerInfo<EventArgs>>>>;
|
|
879
|
-
```
|
|
880
|
-
|
|
881
|
-
***
|
|
882
|
-
|
|
883
|
-
### eventData
|
|
884
|
-
|
|
885
|
-
```ts
|
|
886
|
-
eventData: TEventData;
|
|
887
|
-
```
|
|
888
|
-
|
|
889
|
-
### Implementation of
|
|
890
|
-
|
|
891
|
-
[`EventEmitter`](#../interfaces/EventEmitter).[`eventData`](../interfaces/EventEmitter.md#eventdata)
|
|
798
|
+
| Property | Modifier | Type | Description | Inherited from |
|
|
799
|
+
| ------ | ------ | ------ | ------ | ------ |
|
|
800
|
+
| <a id="defaultlogger"></a> `defaultLogger?` | `static` | `Logger` | - | `Base.defaultLogger` |
|
|
801
|
+
| <a id="globalinstances"></a> `globalInstances` | `readonly` | `Record`\<`BaseClassName`, `WeakRef`\<`Base`\>[]\> | - | `Base.globalInstances` |
|
|
802
|
+
| <a id="globalinstancescounthistory"></a> `globalInstancesCountHistory` | `readonly` | `Record`\<`BaseClassName`, `number`[]\> | - | `Base.globalInstancesCountHistory` |
|
|
803
|
+
| <a id="anymap"></a> `anyMap` | `static` | `WeakMap`\<`object`, `Set`\<[`EventAnyListener`](#../type-aliases/EventAnyListener)\>\> | - | - |
|
|
804
|
+
| <a id="eventsmap"></a> `eventsMap` | `static` | `WeakMap`\<`object`, `Map`\<`PropertyKey`, `Set`\<[`EventListenerInfo`](#../type-aliases/EventListenerInfo)\<[`EventArgs`](#../type-aliases/EventArgs)\>\>\>\> | - | - |
|
|
805
|
+
| <a id="eventdata"></a> `eventData` | `public` | `TEventData` | Type-level reference to the event data shape for external type queries. | - |
|
|
892
806
|
|
|
893
807
|
## Accessors
|
|
894
808
|
|
|
@@ -907,14 +821,14 @@ get static historyInterval(): number;
|
|
|
907
821
|
### Set Signature
|
|
908
822
|
|
|
909
823
|
```ts
|
|
910
|
-
set static historyInterval(value): void;
|
|
824
|
+
set static historyInterval(value: number): void;
|
|
911
825
|
```
|
|
912
826
|
|
|
913
827
|
#### Parameters
|
|
914
828
|
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
`number`
|
|
829
|
+
| Parameter | Type |
|
|
830
|
+
| ------ | ------ |
|
|
831
|
+
| `value` | `number` |
|
|
918
832
|
|
|
919
833
|
#### Returns
|
|
920
834
|
|
|
@@ -943,14 +857,14 @@ get static historyTime(): number;
|
|
|
943
857
|
### Set Signature
|
|
944
858
|
|
|
945
859
|
```ts
|
|
946
|
-
set static historyTime(value): void;
|
|
860
|
+
set static historyTime(value: number): void;
|
|
947
861
|
```
|
|
948
862
|
|
|
949
863
|
#### Parameters
|
|
950
864
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
`number`
|
|
865
|
+
| Parameter | Type |
|
|
866
|
+
| ------ | ------ |
|
|
867
|
+
| `value` | `number` |
|
|
954
868
|
|
|
955
869
|
#### Returns
|
|
956
870
|
|
|
@@ -979,14 +893,14 @@ get static maxGcFrequency(): number;
|
|
|
979
893
|
### Set Signature
|
|
980
894
|
|
|
981
895
|
```ts
|
|
982
|
-
set static maxGcFrequency(value): void;
|
|
896
|
+
set static maxGcFrequency(value: number): void;
|
|
983
897
|
```
|
|
984
898
|
|
|
985
899
|
#### Parameters
|
|
986
900
|
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
`number`
|
|
901
|
+
| Parameter | Type |
|
|
902
|
+
| ------ | ------ |
|
|
903
|
+
| `value` | `number` |
|
|
990
904
|
|
|
991
905
|
#### Returns
|
|
992
906
|
|
|
@@ -1108,6 +1022,8 @@ Base.tracer
|
|
|
1108
1022
|
get static isDebugEnabled(): boolean;
|
|
1109
1023
|
```
|
|
1110
1024
|
|
|
1025
|
+
Whether debug mode is enabled globally or via the DEBUG environment variable.
|
|
1026
|
+
|
|
1111
1027
|
#### Returns
|
|
1112
1028
|
|
|
1113
1029
|
`boolean`
|
|
@@ -1115,14 +1031,14 @@ get static isDebugEnabled(): boolean;
|
|
|
1115
1031
|
### Set Signature
|
|
1116
1032
|
|
|
1117
1033
|
```ts
|
|
1118
|
-
set static isDebugEnabled(newValue): void;
|
|
1034
|
+
set static isDebugEnabled(newValue: boolean): void;
|
|
1119
1035
|
```
|
|
1120
1036
|
|
|
1121
1037
|
#### Parameters
|
|
1122
1038
|
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
`boolean`
|
|
1039
|
+
| Parameter | Type |
|
|
1040
|
+
| ------ | ------ |
|
|
1041
|
+
| `newValue` | `boolean` |
|
|
1126
1042
|
|
|
1127
1043
|
#### Returns
|
|
1128
1044
|
|
|
@@ -1138,6 +1054,8 @@ set static isDebugEnabled(newValue): void;
|
|
|
1138
1054
|
get debug(): DebugOptions | undefined;
|
|
1139
1055
|
```
|
|
1140
1056
|
|
|
1057
|
+
The debug configuration for this instance, if provided.
|
|
1058
|
+
|
|
1141
1059
|
#### Returns
|
|
1142
1060
|
|
|
1143
1061
|
[`DebugOptions`](#../type-aliases/DebugOptions) \| `undefined`
|
|
@@ -1149,14 +1067,14 @@ get debug(): DebugOptions | undefined;
|
|
|
1149
1067
|
### Call Signature
|
|
1150
1068
|
|
|
1151
1069
|
```ts
|
|
1152
|
-
static gc(force
|
|
1070
|
+
static gc(force?: boolean): void;
|
|
1153
1071
|
```
|
|
1154
1072
|
|
|
1155
1073
|
#### Parameters
|
|
1156
1074
|
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
`boolean`
|
|
1075
|
+
| Parameter | Type |
|
|
1076
|
+
| ------ | ------ |
|
|
1077
|
+
| `force?` | `boolean` |
|
|
1160
1078
|
|
|
1161
1079
|
#### Returns
|
|
1162
1080
|
|
|
@@ -1171,14 +1089,14 @@ Base.gc
|
|
|
1171
1089
|
### Call Signature
|
|
1172
1090
|
|
|
1173
1091
|
```ts
|
|
1174
|
-
static gc(className): void;
|
|
1092
|
+
static gc(className: BaseClassName): void;
|
|
1175
1093
|
```
|
|
1176
1094
|
|
|
1177
1095
|
#### Parameters
|
|
1178
1096
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
`BaseClassName`
|
|
1097
|
+
| Parameter | Type |
|
|
1098
|
+
| ------ | ------ |
|
|
1099
|
+
| `className` | `BaseClassName` |
|
|
1182
1100
|
|
|
1183
1101
|
#### Returns
|
|
1184
1102
|
|
|
@@ -1195,14 +1113,14 @@ Base.gc
|
|
|
1195
1113
|
### instanceCount()
|
|
1196
1114
|
|
|
1197
1115
|
```ts
|
|
1198
|
-
static instanceCount(className): number;
|
|
1116
|
+
static instanceCount(className: BaseClassName): number;
|
|
1199
1117
|
```
|
|
1200
1118
|
|
|
1201
1119
|
### Parameters
|
|
1202
1120
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
`BaseClassName`
|
|
1121
|
+
| Parameter | Type |
|
|
1122
|
+
| ------ | ------ |
|
|
1123
|
+
| `className` | `BaseClassName` |
|
|
1206
1124
|
|
|
1207
1125
|
### Returns
|
|
1208
1126
|
|
|
@@ -1273,14 +1191,16 @@ Base.stopHistory
|
|
|
1273
1191
|
### clearListeners()
|
|
1274
1192
|
|
|
1275
1193
|
```ts
|
|
1276
|
-
clearListeners(eventNames): void;
|
|
1194
|
+
clearListeners(eventNames: keyof TEventData | keyof TEventData[]): void;
|
|
1277
1195
|
```
|
|
1278
1196
|
|
|
1279
|
-
|
|
1197
|
+
Removes all listeners for the specified event name(s).
|
|
1280
1198
|
|
|
1281
|
-
|
|
1199
|
+
### Parameters
|
|
1282
1200
|
|
|
1283
|
-
|
|
1201
|
+
| Parameter | Type | Description |
|
|
1202
|
+
| ------ | ------ | ------ |
|
|
1203
|
+
| `eventNames` | keyof `TEventData` \| keyof `TEventData`[] | One or more event names to clear listeners for. |
|
|
1284
1204
|
|
|
1285
1205
|
### Returns
|
|
1286
1206
|
|
|
@@ -1295,24 +1215,23 @@ keyof `TEventData` | keyof `TEventData`[]
|
|
|
1295
1215
|
### emit()
|
|
1296
1216
|
|
|
1297
1217
|
```ts
|
|
1298
|
-
emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
1218
|
+
emit<TEventName>(eventName: TEventName, eventArgs: TEventData[TEventName]): Promise<void>;
|
|
1299
1219
|
```
|
|
1300
1220
|
|
|
1301
|
-
|
|
1221
|
+
Emits an event, invoking all registered listeners concurrently.
|
|
1302
1222
|
|
|
1303
|
-
|
|
1223
|
+
### Type Parameters
|
|
1304
1224
|
|
|
1305
|
-
|
|
1225
|
+
| Type Parameter |
|
|
1226
|
+
| ------ |
|
|
1227
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
1306
1228
|
|
|
1307
1229
|
### Parameters
|
|
1308
1230
|
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
`TEventName`
|
|
1312
|
-
|
|
1313
|
-
#### eventArgs
|
|
1314
|
-
|
|
1315
|
-
`TEventData`\[`TEventName`\]
|
|
1231
|
+
| Parameter | Type | Description |
|
|
1232
|
+
| ------ | ------ | ------ |
|
|
1233
|
+
| `eventName` | `TEventName` | The event to emit. |
|
|
1234
|
+
| `eventArgs` | `TEventData`\[`TEventName`\] | The data to pass to listeners. |
|
|
1316
1235
|
|
|
1317
1236
|
### Returns
|
|
1318
1237
|
|
|
@@ -1327,52 +1246,52 @@ emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1327
1246
|
### emitMetaEvent()
|
|
1328
1247
|
|
|
1329
1248
|
```ts
|
|
1330
|
-
emitMetaEvent<TEventName>(eventName, eventArgs): Promise<boolean | undefined>;
|
|
1249
|
+
emitMetaEvent<TEventName>(eventName: TEventName, eventArgs: MetaEventData<TEventData>[TEventName]): Promise<boolean | undefined>;
|
|
1331
1250
|
```
|
|
1332
1251
|
|
|
1333
|
-
|
|
1252
|
+
Emits an internal meta event (listenerAdded or listenerRemoved).
|
|
1334
1253
|
|
|
1335
|
-
|
|
1254
|
+
### Type Parameters
|
|
1336
1255
|
|
|
1337
|
-
|
|
1256
|
+
| Type Parameter |
|
|
1257
|
+
| ------ |
|
|
1258
|
+
| `TEventName` *extends* keyof [`MetaEventData`](#../type-aliases/MetaEventData)\<`TEventData`\> |
|
|
1338
1259
|
|
|
1339
1260
|
### Parameters
|
|
1340
1261
|
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
`TEventName`
|
|
1344
|
-
|
|
1345
|
-
#### eventArgs
|
|
1346
|
-
|
|
1347
|
-
[`MetaEventData`](#../type-aliases/MetaEventData)\<`TEventData`\>\[`TEventName`\]
|
|
1262
|
+
| Parameter | Type | Description |
|
|
1263
|
+
| ------ | ------ | ------ |
|
|
1264
|
+
| `eventName` | `TEventName` | The meta event name. |
|
|
1265
|
+
| `eventArgs` | [`MetaEventData`](#../type-aliases/MetaEventData)\<`TEventData`\>\[`TEventName`\] | The meta event data containing listener and event information. |
|
|
1348
1266
|
|
|
1349
1267
|
### Returns
|
|
1350
1268
|
|
|
1351
1269
|
`Promise`\<`boolean` \| `undefined`\>
|
|
1352
1270
|
|
|
1271
|
+
True if the meta event was emitted successfully.
|
|
1272
|
+
|
|
1353
1273
|
***
|
|
1354
1274
|
|
|
1355
1275
|
### emitSerial()
|
|
1356
1276
|
|
|
1357
1277
|
```ts
|
|
1358
|
-
emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
1278
|
+
emitSerial<TEventName>(eventName: TEventName, eventArgs: TEventData[TEventName]): Promise<void>;
|
|
1359
1279
|
```
|
|
1360
1280
|
|
|
1361
|
-
|
|
1281
|
+
Emits an event, invoking all registered listeners sequentially in order.
|
|
1362
1282
|
|
|
1363
|
-
|
|
1283
|
+
### Type Parameters
|
|
1364
1284
|
|
|
1365
|
-
|
|
1285
|
+
| Type Parameter |
|
|
1286
|
+
| ------ |
|
|
1287
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
1366
1288
|
|
|
1367
1289
|
### Parameters
|
|
1368
1290
|
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
`TEventName`
|
|
1372
|
-
|
|
1373
|
-
#### eventArgs
|
|
1374
|
-
|
|
1375
|
-
`TEventData`\[`TEventName`\]
|
|
1291
|
+
| Parameter | Type | Description |
|
|
1292
|
+
| ------ | ------ | ------ |
|
|
1293
|
+
| `eventName` | `TEventName` | The event to emit. |
|
|
1294
|
+
| `eventArgs` | `TEventData`\[`TEventName`\] | The data to pass to listeners. |
|
|
1376
1295
|
|
|
1377
1296
|
### Returns
|
|
1378
1297
|
|
|
@@ -1387,19 +1306,23 @@ emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1387
1306
|
### listenerCount()
|
|
1388
1307
|
|
|
1389
1308
|
```ts
|
|
1390
|
-
listenerCount(eventNames
|
|
1309
|
+
listenerCount(eventNames?: keyof TEventData | keyof TEventData[]): number;
|
|
1391
1310
|
```
|
|
1392
1311
|
|
|
1393
|
-
|
|
1312
|
+
Returns the total number of listeners registered for the specified event name(s).
|
|
1394
1313
|
|
|
1395
|
-
|
|
1314
|
+
### Parameters
|
|
1396
1315
|
|
|
1397
|
-
|
|
1316
|
+
| Parameter | Type | Description |
|
|
1317
|
+
| ------ | ------ | ------ |
|
|
1318
|
+
| `eventNames?` | keyof `TEventData` \| keyof `TEventData`[] | One or more event names to count listeners for. |
|
|
1398
1319
|
|
|
1399
1320
|
### Returns
|
|
1400
1321
|
|
|
1401
1322
|
`number`
|
|
1402
1323
|
|
|
1324
|
+
The total listener count.
|
|
1325
|
+
|
|
1403
1326
|
### Implementation of
|
|
1404
1327
|
|
|
1405
1328
|
[`EventEmitter`](#../interfaces/EventEmitter).[`listenerCount`](../interfaces/EventEmitter.md#listenercount)
|
|
@@ -1410,30 +1333,26 @@ keyof `TEventData` | keyof `TEventData`[]
|
|
|
1410
1333
|
|
|
1411
1334
|
```ts
|
|
1412
1335
|
logIfDebugEnabled<TEventName>(
|
|
1413
|
-
type,
|
|
1414
|
-
eventName
|
|
1415
|
-
eventArgs
|
|
1336
|
+
type: string,
|
|
1337
|
+
eventName?: TEventName,
|
|
1338
|
+
eventArgs?: EventArgs): void;
|
|
1416
1339
|
```
|
|
1417
1340
|
|
|
1418
|
-
|
|
1341
|
+
Logs debug information if debug mode is enabled.
|
|
1419
1342
|
|
|
1420
|
-
|
|
1343
|
+
### Type Parameters
|
|
1421
1344
|
|
|
1422
|
-
|
|
1345
|
+
| Type Parameter |
|
|
1346
|
+
| ------ |
|
|
1347
|
+
| `TEventName` *extends* `PropertyKey` |
|
|
1423
1348
|
|
|
1424
1349
|
### Parameters
|
|
1425
1350
|
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
`string`
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
`TEventName`
|
|
1433
|
-
|
|
1434
|
-
#### eventArgs?
|
|
1435
|
-
|
|
1436
|
-
[`EventArgs`](#../type-aliases/EventArgs)
|
|
1351
|
+
| Parameter | Type | Description |
|
|
1352
|
+
| ------ | ------ | ------ |
|
|
1353
|
+
| `type` | `string` | The type of operation being logged. |
|
|
1354
|
+
| `eventName?` | `TEventName` | The event name, if applicable. |
|
|
1355
|
+
| `eventArgs?` | [`EventArgs`](#../type-aliases/EventArgs) | The event data, if applicable. |
|
|
1437
1356
|
|
|
1438
1357
|
### Returns
|
|
1439
1358
|
|
|
@@ -1444,28 +1363,24 @@ logIfDebugEnabled<TEventName>(
|
|
|
1444
1363
|
### off()
|
|
1445
1364
|
|
|
1446
1365
|
```ts
|
|
1447
|
-
off<TEventName, TEventListener>(eventNames, listener): void;
|
|
1366
|
+
off<TEventName, TEventListener>(eventNames: TEventName | TEventName[], listener: TEventListener): void;
|
|
1448
1367
|
```
|
|
1449
1368
|
|
|
1450
|
-
|
|
1369
|
+
Removes a specific listener from the specified event name(s).
|
|
1451
1370
|
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
`TEventName` *extends* `string` \| `number` \| `symbol`
|
|
1455
|
-
|
|
1456
|
-
#### TEventListener
|
|
1371
|
+
### Type Parameters
|
|
1457
1372
|
|
|
1458
|
-
|
|
1373
|
+
| Type Parameter | Default type |
|
|
1374
|
+
| ------ | ------ |
|
|
1375
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` | - |
|
|
1376
|
+
| `TEventListener` | [`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\> |
|
|
1459
1377
|
|
|
1460
1378
|
### Parameters
|
|
1461
1379
|
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
`
|
|
1465
|
-
|
|
1466
|
-
#### listener
|
|
1467
|
-
|
|
1468
|
-
`TEventListener`
|
|
1380
|
+
| Parameter | Type | Description |
|
|
1381
|
+
| ------ | ------ | ------ |
|
|
1382
|
+
| `eventNames` | `TEventName` \| `TEventName`[] | One or more event names to unsubscribe from. |
|
|
1383
|
+
| `listener` | `TEventListener` | The listener to remove. |
|
|
1469
1384
|
|
|
1470
1385
|
### Returns
|
|
1471
1386
|
|
|
@@ -1480,14 +1395,16 @@ off<TEventName, TEventListener>(eventNames, listener): void;
|
|
|
1480
1395
|
### offAny()
|
|
1481
1396
|
|
|
1482
1397
|
```ts
|
|
1483
|
-
offAny(listener): void;
|
|
1398
|
+
offAny(listener: EventAnyListener): void;
|
|
1484
1399
|
```
|
|
1485
1400
|
|
|
1486
|
-
|
|
1401
|
+
Removes a wildcard listener that was receiving all events.
|
|
1487
1402
|
|
|
1488
|
-
|
|
1403
|
+
### Parameters
|
|
1489
1404
|
|
|
1490
|
-
|
|
1405
|
+
| Parameter | Type | Description |
|
|
1406
|
+
| ------ | ------ | ------ |
|
|
1407
|
+
| `listener` | [`EventAnyListener`](#../type-aliases/EventAnyListener) | The wildcard listener to remove. |
|
|
1491
1408
|
|
|
1492
1409
|
### Returns
|
|
1493
1410
|
|
|
@@ -1503,42 +1420,40 @@ offAny(listener): void;
|
|
|
1503
1420
|
|
|
1504
1421
|
```ts
|
|
1505
1422
|
on<TEventName>(
|
|
1506
|
-
eventNames,
|
|
1507
|
-
listener
|
|
1508
|
-
filter
|
|
1423
|
+
eventNames: TEventName | TEventName[],
|
|
1424
|
+
listener: EventListener<TEventData[TEventName]>,
|
|
1425
|
+
filter?: TEventData[TEventName]): (...args: []) => void;
|
|
1509
1426
|
```
|
|
1510
1427
|
|
|
1511
|
-
|
|
1428
|
+
Subscribes a listener to the specified event name(s).
|
|
1512
1429
|
|
|
1513
|
-
|
|
1430
|
+
### Type Parameters
|
|
1514
1431
|
|
|
1515
|
-
|
|
1432
|
+
| Type Parameter | Default type |
|
|
1433
|
+
| ------ | ------ |
|
|
1434
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` | keyof `TEventData` |
|
|
1516
1435
|
|
|
1517
1436
|
### Parameters
|
|
1518
1437
|
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
`
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
1526
|
-
|
|
1527
|
-
#### filter?
|
|
1528
|
-
|
|
1529
|
-
`TEventData`\[`TEventName`\]
|
|
1438
|
+
| Parameter | Type | Description |
|
|
1439
|
+
| ------ | ------ | ------ |
|
|
1440
|
+
| `eventNames` | `TEventName` \| `TEventName`[] | One or more event names to listen for. |
|
|
1441
|
+
| `listener` | [`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\> | The callback to invoke when the event fires. |
|
|
1442
|
+
| `filter?` | `TEventData`\[`TEventName`\] | Optional filter to selectively invoke the listener based on event data. |
|
|
1530
1443
|
|
|
1531
1444
|
### Returns
|
|
1532
1445
|
|
|
1446
|
+
An unsubscribe function.
|
|
1447
|
+
|
|
1533
1448
|
```ts
|
|
1534
|
-
(...args): void;
|
|
1449
|
+
(...args: []): void;
|
|
1535
1450
|
```
|
|
1536
1451
|
|
|
1537
1452
|
#### Parameters
|
|
1538
1453
|
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1454
|
+
| Parameter | Type |
|
|
1455
|
+
| ------ | ------ |
|
|
1456
|
+
| ...`args` | \[\] |
|
|
1542
1457
|
|
|
1543
1458
|
#### Returns
|
|
1544
1459
|
|
|
@@ -1553,26 +1468,30 @@ on<TEventName>(
|
|
|
1553
1468
|
### onAny()
|
|
1554
1469
|
|
|
1555
1470
|
```ts
|
|
1556
|
-
onAny(listener): (...args) => void;
|
|
1471
|
+
onAny(listener: EventAnyListener): (...args: []) => void;
|
|
1557
1472
|
```
|
|
1558
1473
|
|
|
1559
|
-
|
|
1474
|
+
Subscribes a wildcard listener that receives all events.
|
|
1560
1475
|
|
|
1561
|
-
|
|
1476
|
+
### Parameters
|
|
1562
1477
|
|
|
1563
|
-
|
|
1478
|
+
| Parameter | Type | Description |
|
|
1479
|
+
| ------ | ------ | ------ |
|
|
1480
|
+
| `listener` | [`EventAnyListener`](#../type-aliases/EventAnyListener) | The callback to invoke for any event. |
|
|
1564
1481
|
|
|
1565
1482
|
### Returns
|
|
1566
1483
|
|
|
1484
|
+
An unsubscribe function.
|
|
1485
|
+
|
|
1567
1486
|
```ts
|
|
1568
|
-
(...args): void;
|
|
1487
|
+
(...args: []): void;
|
|
1569
1488
|
```
|
|
1570
1489
|
|
|
1571
1490
|
#### Parameters
|
|
1572
1491
|
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1492
|
+
| Parameter | Type |
|
|
1493
|
+
| ------ | ------ |
|
|
1494
|
+
| ...`args` | \[\] |
|
|
1576
1495
|
|
|
1577
1496
|
#### Returns
|
|
1578
1497
|
|
|
@@ -1587,36 +1506,37 @@ onAny(listener): (...args) => void;
|
|
|
1587
1506
|
### once()
|
|
1588
1507
|
|
|
1589
1508
|
```ts
|
|
1590
|
-
once<TEventName>(eventName, listener): (...args) => void;
|
|
1509
|
+
once<TEventName>(eventName: TEventName, listener: EventListener<TEventData[TEventName]>): (...args: []) => void;
|
|
1591
1510
|
```
|
|
1592
1511
|
|
|
1593
|
-
|
|
1512
|
+
Subscribes a listener that will be invoked only once for the specified event, then automatically removed.
|
|
1594
1513
|
|
|
1595
|
-
|
|
1514
|
+
### Type Parameters
|
|
1596
1515
|
|
|
1597
|
-
|
|
1516
|
+
| Type Parameter |
|
|
1517
|
+
| ------ |
|
|
1518
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
1598
1519
|
|
|
1599
1520
|
### Parameters
|
|
1600
1521
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
`TEventName`
|
|
1604
|
-
|
|
1605
|
-
#### listener
|
|
1606
|
-
|
|
1607
|
-
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
1522
|
+
| Parameter | Type | Description |
|
|
1523
|
+
| ------ | ------ | ------ |
|
|
1524
|
+
| `eventName` | `TEventName` | The event to listen for. |
|
|
1525
|
+
| `listener` | [`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\> | The callback to invoke once. |
|
|
1608
1526
|
|
|
1609
1527
|
### Returns
|
|
1610
1528
|
|
|
1529
|
+
An unsubscribe function.
|
|
1530
|
+
|
|
1611
1531
|
```ts
|
|
1612
|
-
(...args): void;
|
|
1532
|
+
(...args: []): void;
|
|
1613
1533
|
```
|
|
1614
1534
|
|
|
1615
1535
|
#### Parameters
|
|
1616
1536
|
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1537
|
+
| Parameter | Type |
|
|
1538
|
+
| ------ | ------ |
|
|
1539
|
+
| ...`args` | \[\] |
|
|
1620
1540
|
|
|
1621
1541
|
#### Returns
|
|
1622
1542
|
|
|
@@ -1634,39 +1554,43 @@ once<TEventName>(eventName, listener): (...args) => void;
|
|
|
1634
1554
|
|
|
1635
1555
|
***
|
|
1636
1556
|
|
|
1557
|
+
Fields specific to BaseEmitter configuration parameters.
|
|
1558
|
+
|
|
1637
1559
|
### <a id="EventEmitter"></a>EventEmitter
|
|
1638
1560
|
|
|
1639
1561
|
[**@xylabs/events**](#../README)
|
|
1640
1562
|
|
|
1641
1563
|
***
|
|
1642
1564
|
|
|
1643
|
-
|
|
1565
|
+
Interface for a typed event emitter that supports subscribing, unsubscribing, and emitting events.
|
|
1644
1566
|
|
|
1645
|
-
|
|
1567
|
+
## Type Parameters
|
|
1646
1568
|
|
|
1647
|
-
|
|
1569
|
+
| Type Parameter |
|
|
1570
|
+
| ------ |
|
|
1571
|
+
| `T` *extends* [`EventData`](#../type-aliases/EventData) |
|
|
1648
1572
|
|
|
1649
1573
|
## Properties
|
|
1650
1574
|
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
eventData: T;
|
|
1655
|
-
```
|
|
1575
|
+
| Property | Type | Description |
|
|
1576
|
+
| ------ | ------ | ------ |
|
|
1577
|
+
| <a id="eventdata"></a> `eventData` | `T` | Type-level reference to the event data shape for external type queries. |
|
|
1656
1578
|
|
|
1657
1579
|
## Methods
|
|
1658
1580
|
|
|
1659
1581
|
### clearListeners()
|
|
1660
1582
|
|
|
1661
1583
|
```ts
|
|
1662
|
-
clearListeners(eventNames): void;
|
|
1584
|
+
clearListeners(eventNames: keyof T | keyof T[]): void;
|
|
1663
1585
|
```
|
|
1664
1586
|
|
|
1665
|
-
|
|
1587
|
+
Removes all listeners for the specified event name(s).
|
|
1666
1588
|
|
|
1667
|
-
|
|
1589
|
+
### Parameters
|
|
1668
1590
|
|
|
1669
|
-
|
|
1591
|
+
| Parameter | Type |
|
|
1592
|
+
| ------ | ------ |
|
|
1593
|
+
| `eventNames` | keyof `T` \| keyof `T`[] |
|
|
1670
1594
|
|
|
1671
1595
|
### Returns
|
|
1672
1596
|
|
|
@@ -1677,24 +1601,23 @@ keyof `T` | keyof `T`[]
|
|
|
1677
1601
|
### emit()
|
|
1678
1602
|
|
|
1679
1603
|
```ts
|
|
1680
|
-
emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
1604
|
+
emit<TEventName>(eventName: TEventName, eventArgs: T[TEventName]): Promise<void>;
|
|
1681
1605
|
```
|
|
1682
1606
|
|
|
1683
|
-
|
|
1607
|
+
Emits an event, invoking all registered listeners concurrently.
|
|
1684
1608
|
|
|
1685
|
-
|
|
1609
|
+
### Type Parameters
|
|
1686
1610
|
|
|
1687
|
-
|
|
1611
|
+
| Type Parameter |
|
|
1612
|
+
| ------ |
|
|
1613
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
1688
1614
|
|
|
1689
1615
|
### Parameters
|
|
1690
1616
|
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
`TEventName`
|
|
1694
|
-
|
|
1695
|
-
#### eventArgs
|
|
1696
|
-
|
|
1697
|
-
`T`\[`TEventName`\]
|
|
1617
|
+
| Parameter | Type |
|
|
1618
|
+
| ------ | ------ |
|
|
1619
|
+
| `eventName` | `TEventName` |
|
|
1620
|
+
| `eventArgs` | `T`\[`TEventName`\] |
|
|
1698
1621
|
|
|
1699
1622
|
### Returns
|
|
1700
1623
|
|
|
@@ -1705,24 +1628,23 @@ emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1705
1628
|
### emitSerial()
|
|
1706
1629
|
|
|
1707
1630
|
```ts
|
|
1708
|
-
emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
1631
|
+
emitSerial<TEventName>(eventName: TEventName, eventArgs: T[TEventName]): Promise<void>;
|
|
1709
1632
|
```
|
|
1710
1633
|
|
|
1711
|
-
|
|
1634
|
+
Emits an event, invoking all registered listeners sequentially in order.
|
|
1712
1635
|
|
|
1713
|
-
|
|
1636
|
+
### Type Parameters
|
|
1714
1637
|
|
|
1715
|
-
|
|
1638
|
+
| Type Parameter |
|
|
1639
|
+
| ------ |
|
|
1640
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
1716
1641
|
|
|
1717
1642
|
### Parameters
|
|
1718
1643
|
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
`TEventName`
|
|
1722
|
-
|
|
1723
|
-
#### eventArgs
|
|
1724
|
-
|
|
1725
|
-
`T`\[`TEventName`\]
|
|
1644
|
+
| Parameter | Type |
|
|
1645
|
+
| ------ | ------ |
|
|
1646
|
+
| `eventName` | `TEventName` |
|
|
1647
|
+
| `eventArgs` | `T`\[`TEventName`\] |
|
|
1726
1648
|
|
|
1727
1649
|
### Returns
|
|
1728
1650
|
|
|
@@ -1733,14 +1655,16 @@ emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1733
1655
|
### listenerCount()
|
|
1734
1656
|
|
|
1735
1657
|
```ts
|
|
1736
|
-
listenerCount(eventNames): number;
|
|
1658
|
+
listenerCount(eventNames: keyof T | keyof T[]): number;
|
|
1737
1659
|
```
|
|
1738
1660
|
|
|
1739
|
-
|
|
1661
|
+
Returns the total number of listeners registered for the specified event name(s).
|
|
1740
1662
|
|
|
1741
|
-
|
|
1663
|
+
### Parameters
|
|
1742
1664
|
|
|
1743
|
-
|
|
1665
|
+
| Parameter | Type |
|
|
1666
|
+
| ------ | ------ |
|
|
1667
|
+
| `eventNames` | keyof `T` \| keyof `T`[] |
|
|
1744
1668
|
|
|
1745
1669
|
### Returns
|
|
1746
1670
|
|
|
@@ -1751,24 +1675,23 @@ keyof `T` | keyof `T`[]
|
|
|
1751
1675
|
### off()
|
|
1752
1676
|
|
|
1753
1677
|
```ts
|
|
1754
|
-
off<TEventName>(eventNames, listener): void;
|
|
1678
|
+
off<TEventName>(eventNames: TEventName | TEventName[], listener: EventListener<T[TEventName]>): void;
|
|
1755
1679
|
```
|
|
1756
1680
|
|
|
1757
|
-
|
|
1681
|
+
Removes a specific listener from the specified event name(s).
|
|
1758
1682
|
|
|
1759
|
-
|
|
1683
|
+
### Type Parameters
|
|
1760
1684
|
|
|
1761
|
-
|
|
1685
|
+
| Type Parameter |
|
|
1686
|
+
| ------ |
|
|
1687
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
1762
1688
|
|
|
1763
1689
|
### Parameters
|
|
1764
1690
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
`
|
|
1768
|
-
|
|
1769
|
-
#### listener
|
|
1770
|
-
|
|
1771
|
-
[`EventListener`](#../type-aliases/EventListener)\<`T`\[`TEventName`\]\>
|
|
1691
|
+
| Parameter | Type |
|
|
1692
|
+
| ------ | ------ |
|
|
1693
|
+
| `eventNames` | `TEventName` \| `TEventName`[] |
|
|
1694
|
+
| `listener` | [`EventListener`](#../type-aliases/EventListener)\<`T`\[`TEventName`\]\> |
|
|
1772
1695
|
|
|
1773
1696
|
### Returns
|
|
1774
1697
|
|
|
@@ -1779,14 +1702,18 @@ off<TEventName>(eventNames, listener): void;
|
|
|
1779
1702
|
### offAny()
|
|
1780
1703
|
|
|
1781
1704
|
```ts
|
|
1782
|
-
offAny(listener
|
|
1705
|
+
offAny(listener:
|
|
1706
|
+
| Promise<void>
|
|
1707
|
+
| EventAnyListener): void;
|
|
1783
1708
|
```
|
|
1784
1709
|
|
|
1785
|
-
|
|
1710
|
+
Removes a wildcard listener that was receiving all events.
|
|
1786
1711
|
|
|
1787
|
-
|
|
1712
|
+
### Parameters
|
|
1788
1713
|
|
|
1789
|
-
|
|
1714
|
+
| Parameter | Type |
|
|
1715
|
+
| ------ | ------ |
|
|
1716
|
+
| `listener` | \| `Promise`\<`void`\> \| [`EventAnyListener`](#../type-aliases/EventAnyListener) |
|
|
1790
1717
|
|
|
1791
1718
|
### Returns
|
|
1792
1719
|
|
|
@@ -1797,24 +1724,23 @@ offAny(listener): void;
|
|
|
1797
1724
|
### on()
|
|
1798
1725
|
|
|
1799
1726
|
```ts
|
|
1800
|
-
on<TEventName>(eventNames, listener): EventUnsubscribeFunction;
|
|
1727
|
+
on<TEventName>(eventNames: TEventName | TEventName[], listener: EventListener<T[TEventName]>): EventUnsubscribeFunction;
|
|
1801
1728
|
```
|
|
1802
1729
|
|
|
1803
|
-
|
|
1730
|
+
Subscribes a listener to the specified event name(s) and returns an unsubscribe function.
|
|
1804
1731
|
|
|
1805
|
-
|
|
1732
|
+
### Type Parameters
|
|
1806
1733
|
|
|
1807
|
-
|
|
1734
|
+
| Type Parameter |
|
|
1735
|
+
| ------ |
|
|
1736
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
1808
1737
|
|
|
1809
1738
|
### Parameters
|
|
1810
1739
|
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
`
|
|
1814
|
-
|
|
1815
|
-
#### listener
|
|
1816
|
-
|
|
1817
|
-
[`EventListener`](#../type-aliases/EventListener)\<`T`\[`TEventName`\]\>
|
|
1740
|
+
| Parameter | Type |
|
|
1741
|
+
| ------ | ------ |
|
|
1742
|
+
| `eventNames` | `TEventName` \| `TEventName`[] |
|
|
1743
|
+
| `listener` | [`EventListener`](#../type-aliases/EventListener)\<`T`\[`TEventName`\]\> |
|
|
1818
1744
|
|
|
1819
1745
|
### Returns
|
|
1820
1746
|
|
|
@@ -1825,14 +1751,16 @@ on<TEventName>(eventNames, listener): EventUnsubscribeFunction;
|
|
|
1825
1751
|
### onAny()
|
|
1826
1752
|
|
|
1827
1753
|
```ts
|
|
1828
|
-
onAny(listener): EventUnsubscribeFunction;
|
|
1754
|
+
onAny(listener: EventAnyListener): EventUnsubscribeFunction;
|
|
1829
1755
|
```
|
|
1830
1756
|
|
|
1831
|
-
|
|
1757
|
+
Subscribes a wildcard listener that receives all events and returns an unsubscribe function.
|
|
1832
1758
|
|
|
1833
|
-
|
|
1759
|
+
### Parameters
|
|
1834
1760
|
|
|
1835
|
-
|
|
1761
|
+
| Parameter | Type |
|
|
1762
|
+
| ------ | ------ |
|
|
1763
|
+
| `listener` | [`EventAnyListener`](#../type-aliases/EventAnyListener) |
|
|
1836
1764
|
|
|
1837
1765
|
### Returns
|
|
1838
1766
|
|
|
@@ -1843,24 +1771,23 @@ onAny(listener): EventUnsubscribeFunction;
|
|
|
1843
1771
|
### once()
|
|
1844
1772
|
|
|
1845
1773
|
```ts
|
|
1846
|
-
once<TEventName>(eventName, listener): EventUnsubscribeFunction;
|
|
1774
|
+
once<TEventName>(eventName: TEventName, listener: EventListener<T[TEventName]>): EventUnsubscribeFunction;
|
|
1847
1775
|
```
|
|
1848
1776
|
|
|
1849
|
-
|
|
1777
|
+
Subscribes a listener that will be invoked only once for the specified event, then automatically removed.
|
|
1850
1778
|
|
|
1851
|
-
|
|
1779
|
+
### Type Parameters
|
|
1852
1780
|
|
|
1853
|
-
|
|
1781
|
+
| Type Parameter |
|
|
1782
|
+
| ------ |
|
|
1783
|
+
| `TEventName` *extends* `string` \| `number` \| `symbol` |
|
|
1854
1784
|
|
|
1855
1785
|
### Parameters
|
|
1856
1786
|
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
`TEventName`
|
|
1860
|
-
|
|
1861
|
-
#### listener
|
|
1862
|
-
|
|
1863
|
-
[`EventListener`](#../type-aliases/EventListener)\<`T`\[`TEventName`\]\>
|
|
1787
|
+
| Parameter | Type |
|
|
1788
|
+
| ------ | ------ |
|
|
1789
|
+
| `eventName` | `TEventName` |
|
|
1790
|
+
| `listener` | [`EventListener`](#../type-aliases/EventListener)\<`T`\[`TEventName`\]\> |
|
|
1864
1791
|
|
|
1865
1792
|
### Returns
|
|
1866
1793
|
|
|
@@ -1878,11 +1805,13 @@ once<TEventName>(eventName, listener): EventUnsubscribeFunction;
|
|
|
1878
1805
|
type BaseEmitterParams<T> = BaseParams<T & BaseEmitterParamsFields & T>;
|
|
1879
1806
|
```
|
|
1880
1807
|
|
|
1881
|
-
|
|
1808
|
+
Parameters type for configuring a BaseEmitter instance.
|
|
1882
1809
|
|
|
1883
|
-
|
|
1810
|
+
## Type Parameters
|
|
1884
1811
|
|
|
1885
|
-
|
|
1812
|
+
| Type Parameter | Default type |
|
|
1813
|
+
| ------ | ------ |
|
|
1814
|
+
| `T` *extends* `EmptyObject` | `EmptyObject` |
|
|
1886
1815
|
|
|
1887
1816
|
### <a id="DebugLogger"></a>DebugLogger
|
|
1888
1817
|
|
|
@@ -1891,7 +1820,7 @@ type BaseEmitterParams<T> = BaseParams<T & BaseEmitterParamsFields & T>;
|
|
|
1891
1820
|
***
|
|
1892
1821
|
|
|
1893
1822
|
```ts
|
|
1894
|
-
type DebugLogger = (type, debugName, eventName
|
|
1823
|
+
type DebugLogger = (type: string, debugName: string, eventName?: EventName, eventData?: EventArgs) => void;
|
|
1895
1824
|
```
|
|
1896
1825
|
|
|
1897
1826
|
Emittery can collect and log debug information.
|
|
@@ -1903,21 +1832,12 @@ See API for more information on how debugging works.
|
|
|
1903
1832
|
|
|
1904
1833
|
## Parameters
|
|
1905
1834
|
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
`string`
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
`string`
|
|
1913
|
-
|
|
1914
|
-
### eventName?
|
|
1915
|
-
|
|
1916
|
-
[`EventName`](#EventName)
|
|
1917
|
-
|
|
1918
|
-
### eventData?
|
|
1919
|
-
|
|
1920
|
-
[`EventArgs`](#EventArgs)
|
|
1835
|
+
| Parameter | Type |
|
|
1836
|
+
| ------ | ------ |
|
|
1837
|
+
| `type` | `string` |
|
|
1838
|
+
| `debugName` | `string` |
|
|
1839
|
+
| `eventName?` | [`EventName`](#EventName) |
|
|
1840
|
+
| `eventData?` | [`EventArgs`](#EventArgs) |
|
|
1921
1841
|
|
|
1922
1842
|
## Returns
|
|
1923
1843
|
|
|
@@ -1930,34 +1850,22 @@ See API for more information on how debugging works.
|
|
|
1930
1850
|
***
|
|
1931
1851
|
|
|
1932
1852
|
```ts
|
|
1933
|
-
type DebugOptions =
|
|
1853
|
+
type DebugOptions = {
|
|
1854
|
+
enabled?: boolean;
|
|
1855
|
+
logger?: DebugLogger;
|
|
1856
|
+
name: string;
|
|
1857
|
+
};
|
|
1934
1858
|
```
|
|
1935
1859
|
|
|
1936
1860
|
Configure debug options of an instance.
|
|
1937
1861
|
|
|
1938
1862
|
## Properties
|
|
1939
1863
|
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
***
|
|
1947
|
-
|
|
1948
|
-
### logger?
|
|
1949
|
-
|
|
1950
|
-
```ts
|
|
1951
|
-
optional logger: DebugLogger;
|
|
1952
|
-
```
|
|
1953
|
-
|
|
1954
|
-
***
|
|
1955
|
-
|
|
1956
|
-
### name
|
|
1957
|
-
|
|
1958
|
-
```ts
|
|
1959
|
-
readonly name: string;
|
|
1960
|
-
```
|
|
1864
|
+
| Property | Modifier | Type |
|
|
1865
|
+
| ------ | ------ | ------ |
|
|
1866
|
+
| <a id="enabled"></a> `enabled?` | `public` | `boolean` |
|
|
1867
|
+
| <a id="logger"></a> `logger?` | `public` | [`DebugLogger`](#DebugLogger) |
|
|
1868
|
+
| <a id="name"></a> `name` | `readonly` | `string` |
|
|
1961
1869
|
|
|
1962
1870
|
### <a id="EventAnyListener"></a>EventAnyListener
|
|
1963
1871
|
|
|
@@ -1966,24 +1874,23 @@ readonly name: string;
|
|
|
1966
1874
|
***
|
|
1967
1875
|
|
|
1968
1876
|
```ts
|
|
1969
|
-
type EventAnyListener<TEventArgs> = (eventName, eventData) => Promisable<void>;
|
|
1877
|
+
type EventAnyListener<TEventArgs> = (eventName: EventName, eventData: TEventArgs) => Promisable<void>;
|
|
1970
1878
|
```
|
|
1971
1879
|
|
|
1972
|
-
|
|
1880
|
+
A listener that receives all events regardless of name.
|
|
1973
1881
|
|
|
1974
|
-
|
|
1882
|
+
## Type Parameters
|
|
1975
1883
|
|
|
1976
|
-
|
|
1884
|
+
| Type Parameter | Default type |
|
|
1885
|
+
| ------ | ------ |
|
|
1886
|
+
| `TEventArgs` *extends* [`EventArgs`](#EventArgs) | [`EventArgs`](#EventArgs) |
|
|
1977
1887
|
|
|
1978
1888
|
## Parameters
|
|
1979
1889
|
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
[`EventName`](#EventName)
|
|
1983
|
-
|
|
1984
|
-
### eventData
|
|
1985
|
-
|
|
1986
|
-
`TEventArgs`
|
|
1890
|
+
| Parameter | Type | Description |
|
|
1891
|
+
| ------ | ------ | ------ |
|
|
1892
|
+
| `eventName` | [`EventName`](#EventName) | The name of the emitted event. |
|
|
1893
|
+
| `eventData` | `TEventArgs` | The data associated with the event. |
|
|
1987
1894
|
|
|
1988
1895
|
## Returns
|
|
1989
1896
|
|
|
@@ -1999,6 +1906,8 @@ type EventAnyListener<TEventArgs> = (eventName, eventData) => Promisable<void>;
|
|
|
1999
1906
|
type EventArgs = string | number | object;
|
|
2000
1907
|
```
|
|
2001
1908
|
|
|
1909
|
+
The allowed types for event argument payloads.
|
|
1910
|
+
|
|
2002
1911
|
### <a id="EventData"></a>EventData
|
|
2003
1912
|
|
|
2004
1913
|
[**@xylabs/events**](#../README)
|
|
@@ -2006,9 +1915,13 @@ type EventArgs = string | number | object;
|
|
|
2006
1915
|
***
|
|
2007
1916
|
|
|
2008
1917
|
```ts
|
|
2009
|
-
type EventData =
|
|
1918
|
+
type EventData = {
|
|
1919
|
+
[key: string | number | symbol]: EventArgs;
|
|
1920
|
+
};
|
|
2010
1921
|
```
|
|
2011
1922
|
|
|
1923
|
+
A mapping of event names to their corresponding event argument types.
|
|
1924
|
+
|
|
2012
1925
|
## Index Signature
|
|
2013
1926
|
|
|
2014
1927
|
```ts
|
|
@@ -2022,20 +1935,22 @@ type EventData = object;
|
|
|
2022
1935
|
***
|
|
2023
1936
|
|
|
2024
1937
|
```ts
|
|
2025
|
-
type EventListener<TEventArgs> = (eventData) => Promisable<void>;
|
|
1938
|
+
type EventListener<TEventArgs> = (eventData: TEventArgs) => Promisable<void>;
|
|
2026
1939
|
```
|
|
2027
1940
|
|
|
2028
|
-
|
|
1941
|
+
A listener for a specific event type.
|
|
2029
1942
|
|
|
2030
|
-
|
|
1943
|
+
## Type Parameters
|
|
2031
1944
|
|
|
2032
|
-
|
|
1945
|
+
| Type Parameter | Default type |
|
|
1946
|
+
| ------ | ------ |
|
|
1947
|
+
| `TEventArgs` *extends* [`EventArgs`](#EventArgs) | [`EventArgs`](#EventArgs) |
|
|
2033
1948
|
|
|
2034
1949
|
## Parameters
|
|
2035
1950
|
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
`TEventArgs`
|
|
1951
|
+
| Parameter | Type | Description |
|
|
1952
|
+
| ------ | ------ | ------ |
|
|
1953
|
+
| `eventData` | `TEventArgs` | The data associated with the event. |
|
|
2039
1954
|
|
|
2040
1955
|
## Returns
|
|
2041
1956
|
|
|
@@ -2048,30 +1963,26 @@ type EventListener<TEventArgs> = (eventData) => Promisable<void>;
|
|
|
2048
1963
|
***
|
|
2049
1964
|
|
|
2050
1965
|
```ts
|
|
2051
|
-
type EventListenerInfo<TEventArgs> =
|
|
1966
|
+
type EventListenerInfo<TEventArgs> = {
|
|
1967
|
+
filter?: TEventArgs;
|
|
1968
|
+
listener: EventListener<TEventArgs>;
|
|
1969
|
+
};
|
|
2052
1970
|
```
|
|
2053
1971
|
|
|
2054
|
-
|
|
1972
|
+
Information about a registered event listener, including an optional filter for selective invocation.
|
|
2055
1973
|
|
|
2056
|
-
|
|
1974
|
+
## Type Parameters
|
|
2057
1975
|
|
|
2058
|
-
|
|
1976
|
+
| Type Parameter | Default type |
|
|
1977
|
+
| ------ | ------ |
|
|
1978
|
+
| `TEventArgs` *extends* [`EventArgs`](#EventArgs) | [`EventArgs`](#EventArgs) |
|
|
2059
1979
|
|
|
2060
1980
|
## Properties
|
|
2061
1981
|
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
```
|
|
2067
|
-
|
|
2068
|
-
***
|
|
2069
|
-
|
|
2070
|
-
### listener
|
|
2071
|
-
|
|
2072
|
-
```ts
|
|
2073
|
-
listener: EventListener<TEventArgs>;
|
|
2074
|
-
```
|
|
1982
|
+
| Property | Type |
|
|
1983
|
+
| ------ | ------ |
|
|
1984
|
+
| <a id="filter"></a> `filter?` | `TEventArgs` |
|
|
1985
|
+
| <a id="listener"></a> `listener` | [`EventListener`](#EventListener)\<`TEventArgs`\> |
|
|
2075
1986
|
|
|
2076
1987
|
### <a id="EventName"></a>EventName
|
|
2077
1988
|
|
|
@@ -2083,6 +1994,8 @@ listener: EventListener<TEventArgs>;
|
|
|
2083
1994
|
type EventName = PropertyKey;
|
|
2084
1995
|
```
|
|
2085
1996
|
|
|
1997
|
+
A valid event name, which can be any property key (string, number, or symbol).
|
|
1998
|
+
|
|
2086
1999
|
### <a id="EventUnsubscribeFunction"></a>EventUnsubscribeFunction
|
|
2087
2000
|
|
|
2088
2001
|
[**@xylabs/events**](#../README)
|
|
@@ -2093,6 +2006,8 @@ type EventName = PropertyKey;
|
|
|
2093
2006
|
type EventUnsubscribeFunction = () => void;
|
|
2094
2007
|
```
|
|
2095
2008
|
|
|
2009
|
+
A function returned by event subscription methods that unsubscribes the listener when called.
|
|
2010
|
+
|
|
2096
2011
|
## Returns
|
|
2097
2012
|
|
|
2098
2013
|
`void`
|
|
@@ -2109,6 +2024,8 @@ type EventsParams = BaseParams<{
|
|
|
2109
2024
|
}>;
|
|
2110
2025
|
```
|
|
2111
2026
|
|
|
2027
|
+
Parameters for constructing an Events instance, with optional debug configuration.
|
|
2028
|
+
|
|
2112
2029
|
### <a id="MetaEventData"></a>MetaEventData
|
|
2113
2030
|
|
|
2114
2031
|
[**@xylabs/events**](#../README)
|
|
@@ -2116,58 +2033,38 @@ type EventsParams = BaseParams<{
|
|
|
2116
2033
|
***
|
|
2117
2034
|
|
|
2118
2035
|
```ts
|
|
2119
|
-
type MetaEventData<TEventData> =
|
|
2036
|
+
type MetaEventData<TEventData> = {
|
|
2037
|
+
listenerAdded: {
|
|
2038
|
+
eventName?: keyof TEventData;
|
|
2039
|
+
listener: | EventListener<TEventData[keyof TEventData]>
|
|
2040
|
+
| EventAnyListener<TEventData[keyof TEventData]>;
|
|
2041
|
+
};
|
|
2042
|
+
listenerRemoved: {
|
|
2043
|
+
eventName?: keyof TEventData;
|
|
2044
|
+
listener: | EventListener<TEventData[keyof TEventData]>
|
|
2045
|
+
| EventAnyListener<TEventData[keyof TEventData]>;
|
|
2046
|
+
};
|
|
2047
|
+
};
|
|
2120
2048
|
```
|
|
2121
2049
|
|
|
2122
|
-
|
|
2050
|
+
Data shape for internal meta events that fire when listeners are added or removed.
|
|
2123
2051
|
|
|
2124
|
-
|
|
2052
|
+
## Type Parameters
|
|
2125
2053
|
|
|
2126
|
-
|
|
2054
|
+
| Type Parameter |
|
|
2055
|
+
| ------ |
|
|
2056
|
+
| `TEventData` *extends* [`EventData`](#EventData) |
|
|
2127
2057
|
|
|
2128
2058
|
## Properties
|
|
2129
2059
|
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
listenerAdded
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
```ts
|
|
2139
|
-
optional eventName: keyof TEventData;
|
|
2140
|
-
```
|
|
2141
|
-
|
|
2142
|
-
### listener
|
|
2143
|
-
|
|
2144
|
-
```ts
|
|
2145
|
-
listener:
|
|
2146
|
-
| EventListener<TEventData[keyof TEventData]>
|
|
2147
|
-
| EventAnyListener<TEventData[keyof TEventData]>;
|
|
2148
|
-
```
|
|
2149
|
-
|
|
2150
|
-
***
|
|
2151
|
-
|
|
2152
|
-
### listenerRemoved
|
|
2153
|
-
|
|
2154
|
-
```ts
|
|
2155
|
-
listenerRemoved: object;
|
|
2156
|
-
```
|
|
2157
|
-
|
|
2158
|
-
### eventName?
|
|
2159
|
-
|
|
2160
|
-
```ts
|
|
2161
|
-
optional eventName: keyof TEventData;
|
|
2162
|
-
```
|
|
2163
|
-
|
|
2164
|
-
### listener
|
|
2165
|
-
|
|
2166
|
-
```ts
|
|
2167
|
-
listener:
|
|
2168
|
-
| EventListener<TEventData[keyof TEventData]>
|
|
2169
|
-
| EventAnyListener<TEventData[keyof TEventData]>;
|
|
2170
|
-
```
|
|
2060
|
+
| Property | Type |
|
|
2061
|
+
| ------ | ------ |
|
|
2062
|
+
| <a id="listeneradded"></a> `listenerAdded` | \{ `eventName?`: keyof `TEventData`; `listener`: \| [`EventListener`](#EventListener)\<`TEventData`\[keyof `TEventData`\]\> \| [`EventAnyListener`](#EventAnyListener)\<`TEventData`\[keyof `TEventData`\]\>; \} |
|
|
2063
|
+
| `listenerAdded.eventName?` | keyof `TEventData` |
|
|
2064
|
+
| `listenerAdded.listener` | \| [`EventListener`](#EventListener)\<`TEventData`\[keyof `TEventData`\]\> \| [`EventAnyListener`](#EventAnyListener)\<`TEventData`\[keyof `TEventData`\]\> |
|
|
2065
|
+
| <a id="listenerremoved"></a> `listenerRemoved` | \{ `eventName?`: keyof `TEventData`; `listener`: \| [`EventListener`](#EventListener)\<`TEventData`\[keyof `TEventData`\]\> \| [`EventAnyListener`](#EventAnyListener)\<`TEventData`\[keyof `TEventData`\]\>; \} |
|
|
2066
|
+
| `listenerRemoved.eventName?` | keyof `TEventData` |
|
|
2067
|
+
| `listenerRemoved.listener` | \| [`EventListener`](#EventListener)\<`TEventData`\[keyof `TEventData`\]\> \| [`EventAnyListener`](#EventAnyListener)\<`TEventData`\[keyof `TEventData`\]\> |
|
|
2171
2068
|
|
|
2172
2069
|
|
|
2173
2070
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|