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