@xylabs/events 5.0.83 → 5.0.84
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 +192 -0
- 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
|
@@ -54,6 +54,9 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
54
54
|
|
|
55
55
|
***
|
|
56
56
|
|
|
57
|
+
Base class that combines the Base utility class with typed event emission capabilities.
|
|
58
|
+
Delegates all event operations to an internal Events instance.
|
|
59
|
+
|
|
57
60
|
## Extends
|
|
58
61
|
|
|
59
62
|
- `Base`\<`TParams`\>
|
|
@@ -146,6 +149,8 @@ Base.globalInstancesCountHistory
|
|
|
146
149
|
eventData: TEventData;
|
|
147
150
|
```
|
|
148
151
|
|
|
152
|
+
Type-level reference to the event data shape for external type queries.
|
|
153
|
+
|
|
149
154
|
### Implementation of
|
|
150
155
|
|
|
151
156
|
[`EventEmitter`](#../interfaces/EventEmitter).[`eventData`](../interfaces/EventEmitter.md#eventdata)
|
|
@@ -492,16 +497,22 @@ Base.stopHistory
|
|
|
492
497
|
clearListeners(eventNames): BaseEmitter<TParams, TEventData>;
|
|
493
498
|
```
|
|
494
499
|
|
|
500
|
+
Removes all listeners for the specified event name(s).
|
|
501
|
+
|
|
495
502
|
### Parameters
|
|
496
503
|
|
|
497
504
|
#### eventNames
|
|
498
505
|
|
|
506
|
+
One or more event names to clear listeners for.
|
|
507
|
+
|
|
499
508
|
keyof `TEventData` | keyof `TEventData`[]
|
|
500
509
|
|
|
501
510
|
### Returns
|
|
502
511
|
|
|
503
512
|
`BaseEmitter`\<`TParams`, `TEventData`\>
|
|
504
513
|
|
|
514
|
+
This instance for chaining.
|
|
515
|
+
|
|
505
516
|
### Implementation of
|
|
506
517
|
|
|
507
518
|
[`EventEmitter`](#../interfaces/EventEmitter).[`clearListeners`](../interfaces/EventEmitter.md#clearlisteners)
|
|
@@ -514,6 +525,8 @@ keyof `TEventData` | keyof `TEventData`[]
|
|
|
514
525
|
emit<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
515
526
|
```
|
|
516
527
|
|
|
528
|
+
Emits an event, invoking all registered listeners concurrently.
|
|
529
|
+
|
|
517
530
|
### Type Parameters
|
|
518
531
|
|
|
519
532
|
#### TEventName
|
|
@@ -530,10 +543,14 @@ emit<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
|
530
543
|
|
|
531
544
|
`TEventName`
|
|
532
545
|
|
|
546
|
+
The event to emit.
|
|
547
|
+
|
|
533
548
|
#### eventArgs
|
|
534
549
|
|
|
535
550
|
`TEventArgs`
|
|
536
551
|
|
|
552
|
+
The data to pass to listeners.
|
|
553
|
+
|
|
537
554
|
### Returns
|
|
538
555
|
|
|
539
556
|
`Promise`\<`void`\>
|
|
@@ -550,6 +567,8 @@ emit<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
|
550
567
|
emitSerial<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
551
568
|
```
|
|
552
569
|
|
|
570
|
+
Emits an event, invoking all registered listeners sequentially in order.
|
|
571
|
+
|
|
553
572
|
### Type Parameters
|
|
554
573
|
|
|
555
574
|
#### TEventName
|
|
@@ -566,10 +585,14 @@ emitSerial<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
|
566
585
|
|
|
567
586
|
`TEventName`
|
|
568
587
|
|
|
588
|
+
The event to emit.
|
|
589
|
+
|
|
569
590
|
#### eventArgs
|
|
570
591
|
|
|
571
592
|
`TEventArgs`
|
|
572
593
|
|
|
594
|
+
The data to pass to listeners.
|
|
595
|
+
|
|
573
596
|
### Returns
|
|
574
597
|
|
|
575
598
|
`Promise`\<`void`\>
|
|
@@ -586,16 +609,22 @@ emitSerial<TEventName, TEventArgs>(eventName, eventArgs): Promise<void>;
|
|
|
586
609
|
listenerCount(eventNames): number;
|
|
587
610
|
```
|
|
588
611
|
|
|
612
|
+
Returns the total number of listeners registered for the specified event name(s).
|
|
613
|
+
|
|
589
614
|
### Parameters
|
|
590
615
|
|
|
591
616
|
#### eventNames
|
|
592
617
|
|
|
618
|
+
One or more event names to count listeners for.
|
|
619
|
+
|
|
593
620
|
keyof `TEventData` | keyof `TEventData`[]
|
|
594
621
|
|
|
595
622
|
### Returns
|
|
596
623
|
|
|
597
624
|
`number`
|
|
598
625
|
|
|
626
|
+
The total listener count.
|
|
627
|
+
|
|
599
628
|
### Implementation of
|
|
600
629
|
|
|
601
630
|
[`EventEmitter`](#../interfaces/EventEmitter).[`listenerCount`](../interfaces/EventEmitter.md#listenercount)
|
|
@@ -608,6 +637,8 @@ keyof `TEventData` | keyof `TEventData`[]
|
|
|
608
637
|
off<TEventName>(eventNames, listener): void;
|
|
609
638
|
```
|
|
610
639
|
|
|
640
|
+
Removes a specific listener from the specified event name(s).
|
|
641
|
+
|
|
611
642
|
### Type Parameters
|
|
612
643
|
|
|
613
644
|
#### TEventName
|
|
@@ -618,12 +649,16 @@ off<TEventName>(eventNames, listener): void;
|
|
|
618
649
|
|
|
619
650
|
#### eventNames
|
|
620
651
|
|
|
652
|
+
One or more event names to unsubscribe from.
|
|
653
|
+
|
|
621
654
|
`TEventName` | `TEventName`[]
|
|
622
655
|
|
|
623
656
|
#### listener
|
|
624
657
|
|
|
625
658
|
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
626
659
|
|
|
660
|
+
The listener to remove.
|
|
661
|
+
|
|
627
662
|
### Returns
|
|
628
663
|
|
|
629
664
|
`void`
|
|
@@ -640,12 +675,16 @@ off<TEventName>(eventNames, listener): void;
|
|
|
640
675
|
offAny(listener): void;
|
|
641
676
|
```
|
|
642
677
|
|
|
678
|
+
Removes a wildcard listener that was receiving all events.
|
|
679
|
+
|
|
643
680
|
### Parameters
|
|
644
681
|
|
|
645
682
|
#### listener
|
|
646
683
|
|
|
647
684
|
[`EventAnyListener`](#../type-aliases/EventAnyListener)
|
|
648
685
|
|
|
686
|
+
The wildcard listener to remove.
|
|
687
|
+
|
|
649
688
|
### Returns
|
|
650
689
|
|
|
651
690
|
`void`
|
|
@@ -662,6 +701,8 @@ offAny(listener): void;
|
|
|
662
701
|
on<TEventName>(eventNames, listener): (...args) => void;
|
|
663
702
|
```
|
|
664
703
|
|
|
704
|
+
Subscribes a listener to the specified event name(s).
|
|
705
|
+
|
|
665
706
|
### Type Parameters
|
|
666
707
|
|
|
667
708
|
#### TEventName
|
|
@@ -672,14 +713,20 @@ on<TEventName>(eventNames, listener): (...args) => void;
|
|
|
672
713
|
|
|
673
714
|
#### eventNames
|
|
674
715
|
|
|
716
|
+
One or more event names to listen for.
|
|
717
|
+
|
|
675
718
|
`TEventName` | `TEventName`[]
|
|
676
719
|
|
|
677
720
|
#### listener
|
|
678
721
|
|
|
679
722
|
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
680
723
|
|
|
724
|
+
The callback to invoke when the event fires.
|
|
725
|
+
|
|
681
726
|
### Returns
|
|
682
727
|
|
|
728
|
+
An unsubscribe function.
|
|
729
|
+
|
|
683
730
|
```ts
|
|
684
731
|
(...args): void;
|
|
685
732
|
```
|
|
@@ -706,14 +753,20 @@ on<TEventName>(eventNames, listener): (...args) => void;
|
|
|
706
753
|
onAny(listener): (...args) => void;
|
|
707
754
|
```
|
|
708
755
|
|
|
756
|
+
Subscribes a wildcard listener that receives all events.
|
|
757
|
+
|
|
709
758
|
### Parameters
|
|
710
759
|
|
|
711
760
|
#### listener
|
|
712
761
|
|
|
713
762
|
[`EventAnyListener`](#../type-aliases/EventAnyListener)
|
|
714
763
|
|
|
764
|
+
The callback to invoke for any event.
|
|
765
|
+
|
|
715
766
|
### Returns
|
|
716
767
|
|
|
768
|
+
An unsubscribe function.
|
|
769
|
+
|
|
717
770
|
```ts
|
|
718
771
|
(...args): void;
|
|
719
772
|
```
|
|
@@ -740,6 +793,8 @@ onAny(listener): (...args) => void;
|
|
|
740
793
|
once<TEventName>(eventName, listener): (...args) => void;
|
|
741
794
|
```
|
|
742
795
|
|
|
796
|
+
Subscribes a listener that will be invoked only once for the specified event, then automatically removed.
|
|
797
|
+
|
|
743
798
|
### Type Parameters
|
|
744
799
|
|
|
745
800
|
#### TEventName
|
|
@@ -752,12 +807,18 @@ once<TEventName>(eventName, listener): (...args) => void;
|
|
|
752
807
|
|
|
753
808
|
`TEventName`
|
|
754
809
|
|
|
810
|
+
The event to listen for.
|
|
811
|
+
|
|
755
812
|
#### listener
|
|
756
813
|
|
|
757
814
|
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
758
815
|
|
|
816
|
+
The callback to invoke once.
|
|
817
|
+
|
|
759
818
|
### Returns
|
|
760
819
|
|
|
820
|
+
An unsubscribe function.
|
|
821
|
+
|
|
761
822
|
```ts
|
|
762
823
|
(...args): void;
|
|
763
824
|
```
|
|
@@ -782,6 +843,9 @@ once<TEventName>(eventName, listener): (...args) => void;
|
|
|
782
843
|
|
|
783
844
|
***
|
|
784
845
|
|
|
846
|
+
Core typed event emitter implementation supporting named events, wildcard listeners,
|
|
847
|
+
serial and concurrent emission, listener filtering, and debug logging.
|
|
848
|
+
|
|
785
849
|
## Extends
|
|
786
850
|
|
|
787
851
|
- `Base`\<[`EventsParams`](#../type-aliases/EventsParams)\>
|
|
@@ -886,6 +950,8 @@ protected static eventsMap: WeakMap<object, Map<PropertyKey, Set<EventListenerIn
|
|
|
886
950
|
eventData: TEventData;
|
|
887
951
|
```
|
|
888
952
|
|
|
953
|
+
Type-level reference to the event data shape for external type queries.
|
|
954
|
+
|
|
889
955
|
### Implementation of
|
|
890
956
|
|
|
891
957
|
[`EventEmitter`](#../interfaces/EventEmitter).[`eventData`](../interfaces/EventEmitter.md#eventdata)
|
|
@@ -1108,6 +1174,8 @@ Base.tracer
|
|
|
1108
1174
|
get static isDebugEnabled(): boolean;
|
|
1109
1175
|
```
|
|
1110
1176
|
|
|
1177
|
+
Whether debug mode is enabled globally or via the DEBUG environment variable.
|
|
1178
|
+
|
|
1111
1179
|
#### Returns
|
|
1112
1180
|
|
|
1113
1181
|
`boolean`
|
|
@@ -1138,6 +1206,8 @@ set static isDebugEnabled(newValue): void;
|
|
|
1138
1206
|
get debug(): DebugOptions | undefined;
|
|
1139
1207
|
```
|
|
1140
1208
|
|
|
1209
|
+
The debug configuration for this instance, if provided.
|
|
1210
|
+
|
|
1141
1211
|
#### Returns
|
|
1142
1212
|
|
|
1143
1213
|
[`DebugOptions`](#../type-aliases/DebugOptions) \| `undefined`
|
|
@@ -1276,10 +1346,14 @@ Base.stopHistory
|
|
|
1276
1346
|
clearListeners(eventNames): void;
|
|
1277
1347
|
```
|
|
1278
1348
|
|
|
1349
|
+
Removes all listeners for the specified event name(s).
|
|
1350
|
+
|
|
1279
1351
|
### Parameters
|
|
1280
1352
|
|
|
1281
1353
|
#### eventNames
|
|
1282
1354
|
|
|
1355
|
+
One or more event names to clear listeners for.
|
|
1356
|
+
|
|
1283
1357
|
keyof `TEventData` | keyof `TEventData`[]
|
|
1284
1358
|
|
|
1285
1359
|
### Returns
|
|
@@ -1298,6 +1372,8 @@ keyof `TEventData` | keyof `TEventData`[]
|
|
|
1298
1372
|
emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
1299
1373
|
```
|
|
1300
1374
|
|
|
1375
|
+
Emits an event, invoking all registered listeners concurrently.
|
|
1376
|
+
|
|
1301
1377
|
### Type Parameters
|
|
1302
1378
|
|
|
1303
1379
|
#### TEventName
|
|
@@ -1310,10 +1386,14 @@ emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1310
1386
|
|
|
1311
1387
|
`TEventName`
|
|
1312
1388
|
|
|
1389
|
+
The event to emit.
|
|
1390
|
+
|
|
1313
1391
|
#### eventArgs
|
|
1314
1392
|
|
|
1315
1393
|
`TEventData`\[`TEventName`\]
|
|
1316
1394
|
|
|
1395
|
+
The data to pass to listeners.
|
|
1396
|
+
|
|
1317
1397
|
### Returns
|
|
1318
1398
|
|
|
1319
1399
|
`Promise`\<`void`\>
|
|
@@ -1330,6 +1410,8 @@ emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1330
1410
|
emitMetaEvent<TEventName>(eventName, eventArgs): Promise<boolean | undefined>;
|
|
1331
1411
|
```
|
|
1332
1412
|
|
|
1413
|
+
Emits an internal meta event (listenerAdded or listenerRemoved).
|
|
1414
|
+
|
|
1333
1415
|
### Type Parameters
|
|
1334
1416
|
|
|
1335
1417
|
#### TEventName
|
|
@@ -1342,14 +1424,20 @@ emitMetaEvent<TEventName>(eventName, eventArgs): Promise<boolean | undefined>;
|
|
|
1342
1424
|
|
|
1343
1425
|
`TEventName`
|
|
1344
1426
|
|
|
1427
|
+
The meta event name.
|
|
1428
|
+
|
|
1345
1429
|
#### eventArgs
|
|
1346
1430
|
|
|
1347
1431
|
[`MetaEventData`](#../type-aliases/MetaEventData)\<`TEventData`\>\[`TEventName`\]
|
|
1348
1432
|
|
|
1433
|
+
The meta event data containing listener and event information.
|
|
1434
|
+
|
|
1349
1435
|
### Returns
|
|
1350
1436
|
|
|
1351
1437
|
`Promise`\<`boolean` \| `undefined`\>
|
|
1352
1438
|
|
|
1439
|
+
True if the meta event was emitted successfully.
|
|
1440
|
+
|
|
1353
1441
|
***
|
|
1354
1442
|
|
|
1355
1443
|
### emitSerial()
|
|
@@ -1358,6 +1446,8 @@ emitMetaEvent<TEventName>(eventName, eventArgs): Promise<boolean | undefined>;
|
|
|
1358
1446
|
emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
1359
1447
|
```
|
|
1360
1448
|
|
|
1449
|
+
Emits an event, invoking all registered listeners sequentially in order.
|
|
1450
|
+
|
|
1361
1451
|
### Type Parameters
|
|
1362
1452
|
|
|
1363
1453
|
#### TEventName
|
|
@@ -1370,10 +1460,14 @@ emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1370
1460
|
|
|
1371
1461
|
`TEventName`
|
|
1372
1462
|
|
|
1463
|
+
The event to emit.
|
|
1464
|
+
|
|
1373
1465
|
#### eventArgs
|
|
1374
1466
|
|
|
1375
1467
|
`TEventData`\[`TEventName`\]
|
|
1376
1468
|
|
|
1469
|
+
The data to pass to listeners.
|
|
1470
|
+
|
|
1377
1471
|
### Returns
|
|
1378
1472
|
|
|
1379
1473
|
`Promise`\<`void`\>
|
|
@@ -1390,16 +1484,22 @@ emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1390
1484
|
listenerCount(eventNames?): number;
|
|
1391
1485
|
```
|
|
1392
1486
|
|
|
1487
|
+
Returns the total number of listeners registered for the specified event name(s).
|
|
1488
|
+
|
|
1393
1489
|
### Parameters
|
|
1394
1490
|
|
|
1395
1491
|
#### eventNames?
|
|
1396
1492
|
|
|
1493
|
+
One or more event names to count listeners for.
|
|
1494
|
+
|
|
1397
1495
|
keyof `TEventData` | keyof `TEventData`[]
|
|
1398
1496
|
|
|
1399
1497
|
### Returns
|
|
1400
1498
|
|
|
1401
1499
|
`number`
|
|
1402
1500
|
|
|
1501
|
+
The total listener count.
|
|
1502
|
+
|
|
1403
1503
|
### Implementation of
|
|
1404
1504
|
|
|
1405
1505
|
[`EventEmitter`](#../interfaces/EventEmitter).[`listenerCount`](../interfaces/EventEmitter.md#listenercount)
|
|
@@ -1415,6 +1515,8 @@ logIfDebugEnabled<TEventName>(
|
|
|
1415
1515
|
eventArgs?): void;
|
|
1416
1516
|
```
|
|
1417
1517
|
|
|
1518
|
+
Logs debug information if debug mode is enabled.
|
|
1519
|
+
|
|
1418
1520
|
### Type Parameters
|
|
1419
1521
|
|
|
1420
1522
|
#### TEventName
|
|
@@ -1427,14 +1529,20 @@ logIfDebugEnabled<TEventName>(
|
|
|
1427
1529
|
|
|
1428
1530
|
`string`
|
|
1429
1531
|
|
|
1532
|
+
The type of operation being logged.
|
|
1533
|
+
|
|
1430
1534
|
#### eventName?
|
|
1431
1535
|
|
|
1432
1536
|
`TEventName`
|
|
1433
1537
|
|
|
1538
|
+
The event name, if applicable.
|
|
1539
|
+
|
|
1434
1540
|
#### eventArgs?
|
|
1435
1541
|
|
|
1436
1542
|
[`EventArgs`](#../type-aliases/EventArgs)
|
|
1437
1543
|
|
|
1544
|
+
The event data, if applicable.
|
|
1545
|
+
|
|
1438
1546
|
### Returns
|
|
1439
1547
|
|
|
1440
1548
|
`void`
|
|
@@ -1447,6 +1555,8 @@ logIfDebugEnabled<TEventName>(
|
|
|
1447
1555
|
off<TEventName, TEventListener>(eventNames, listener): void;
|
|
1448
1556
|
```
|
|
1449
1557
|
|
|
1558
|
+
Removes a specific listener from the specified event name(s).
|
|
1559
|
+
|
|
1450
1560
|
### Type Parameters
|
|
1451
1561
|
|
|
1452
1562
|
#### TEventName
|
|
@@ -1461,12 +1571,16 @@ off<TEventName, TEventListener>(eventNames, listener): void;
|
|
|
1461
1571
|
|
|
1462
1572
|
#### eventNames
|
|
1463
1573
|
|
|
1574
|
+
One or more event names to unsubscribe from.
|
|
1575
|
+
|
|
1464
1576
|
`TEventName` | `TEventName`[]
|
|
1465
1577
|
|
|
1466
1578
|
#### listener
|
|
1467
1579
|
|
|
1468
1580
|
`TEventListener`
|
|
1469
1581
|
|
|
1582
|
+
The listener to remove.
|
|
1583
|
+
|
|
1470
1584
|
### Returns
|
|
1471
1585
|
|
|
1472
1586
|
`void`
|
|
@@ -1483,12 +1597,16 @@ off<TEventName, TEventListener>(eventNames, listener): void;
|
|
|
1483
1597
|
offAny(listener): void;
|
|
1484
1598
|
```
|
|
1485
1599
|
|
|
1600
|
+
Removes a wildcard listener that was receiving all events.
|
|
1601
|
+
|
|
1486
1602
|
### Parameters
|
|
1487
1603
|
|
|
1488
1604
|
#### listener
|
|
1489
1605
|
|
|
1490
1606
|
[`EventAnyListener`](#../type-aliases/EventAnyListener)
|
|
1491
1607
|
|
|
1608
|
+
The wildcard listener to remove.
|
|
1609
|
+
|
|
1492
1610
|
### Returns
|
|
1493
1611
|
|
|
1494
1612
|
`void`
|
|
@@ -1508,6 +1626,8 @@ on<TEventName>(
|
|
|
1508
1626
|
filter?): (...args) => void;
|
|
1509
1627
|
```
|
|
1510
1628
|
|
|
1629
|
+
Subscribes a listener to the specified event name(s).
|
|
1630
|
+
|
|
1511
1631
|
### Type Parameters
|
|
1512
1632
|
|
|
1513
1633
|
#### TEventName
|
|
@@ -1518,18 +1638,26 @@ on<TEventName>(
|
|
|
1518
1638
|
|
|
1519
1639
|
#### eventNames
|
|
1520
1640
|
|
|
1641
|
+
One or more event names to listen for.
|
|
1642
|
+
|
|
1521
1643
|
`TEventName` | `TEventName`[]
|
|
1522
1644
|
|
|
1523
1645
|
#### listener
|
|
1524
1646
|
|
|
1525
1647
|
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
1526
1648
|
|
|
1649
|
+
The callback to invoke when the event fires.
|
|
1650
|
+
|
|
1527
1651
|
#### filter?
|
|
1528
1652
|
|
|
1529
1653
|
`TEventData`\[`TEventName`\]
|
|
1530
1654
|
|
|
1655
|
+
Optional filter to selectively invoke the listener based on event data.
|
|
1656
|
+
|
|
1531
1657
|
### Returns
|
|
1532
1658
|
|
|
1659
|
+
An unsubscribe function.
|
|
1660
|
+
|
|
1533
1661
|
```ts
|
|
1534
1662
|
(...args): void;
|
|
1535
1663
|
```
|
|
@@ -1556,14 +1684,20 @@ on<TEventName>(
|
|
|
1556
1684
|
onAny(listener): (...args) => void;
|
|
1557
1685
|
```
|
|
1558
1686
|
|
|
1687
|
+
Subscribes a wildcard listener that receives all events.
|
|
1688
|
+
|
|
1559
1689
|
### Parameters
|
|
1560
1690
|
|
|
1561
1691
|
#### listener
|
|
1562
1692
|
|
|
1563
1693
|
[`EventAnyListener`](#../type-aliases/EventAnyListener)
|
|
1564
1694
|
|
|
1695
|
+
The callback to invoke for any event.
|
|
1696
|
+
|
|
1565
1697
|
### Returns
|
|
1566
1698
|
|
|
1699
|
+
An unsubscribe function.
|
|
1700
|
+
|
|
1567
1701
|
```ts
|
|
1568
1702
|
(...args): void;
|
|
1569
1703
|
```
|
|
@@ -1590,6 +1724,8 @@ onAny(listener): (...args) => void;
|
|
|
1590
1724
|
once<TEventName>(eventName, listener): (...args) => void;
|
|
1591
1725
|
```
|
|
1592
1726
|
|
|
1727
|
+
Subscribes a listener that will be invoked only once for the specified event, then automatically removed.
|
|
1728
|
+
|
|
1593
1729
|
### Type Parameters
|
|
1594
1730
|
|
|
1595
1731
|
#### TEventName
|
|
@@ -1602,12 +1738,18 @@ once<TEventName>(eventName, listener): (...args) => void;
|
|
|
1602
1738
|
|
|
1603
1739
|
`TEventName`
|
|
1604
1740
|
|
|
1741
|
+
The event to listen for.
|
|
1742
|
+
|
|
1605
1743
|
#### listener
|
|
1606
1744
|
|
|
1607
1745
|
[`EventListener`](#../type-aliases/EventListener)\<`TEventData`\[`TEventName`\]\>
|
|
1608
1746
|
|
|
1747
|
+
The callback to invoke once.
|
|
1748
|
+
|
|
1609
1749
|
### Returns
|
|
1610
1750
|
|
|
1751
|
+
An unsubscribe function.
|
|
1752
|
+
|
|
1611
1753
|
```ts
|
|
1612
1754
|
(...args): void;
|
|
1613
1755
|
```
|
|
@@ -1634,12 +1776,16 @@ once<TEventName>(eventName, listener): (...args) => void;
|
|
|
1634
1776
|
|
|
1635
1777
|
***
|
|
1636
1778
|
|
|
1779
|
+
Fields specific to BaseEmitter configuration parameters.
|
|
1780
|
+
|
|
1637
1781
|
### <a id="EventEmitter"></a>EventEmitter
|
|
1638
1782
|
|
|
1639
1783
|
[**@xylabs/events**](#../README)
|
|
1640
1784
|
|
|
1641
1785
|
***
|
|
1642
1786
|
|
|
1787
|
+
Interface for a typed event emitter that supports subscribing, unsubscribing, and emitting events.
|
|
1788
|
+
|
|
1643
1789
|
## Type Parameters
|
|
1644
1790
|
|
|
1645
1791
|
### T
|
|
@@ -1654,6 +1800,8 @@ once<TEventName>(eventName, listener): (...args) => void;
|
|
|
1654
1800
|
eventData: T;
|
|
1655
1801
|
```
|
|
1656
1802
|
|
|
1803
|
+
Type-level reference to the event data shape for external type queries.
|
|
1804
|
+
|
|
1657
1805
|
## Methods
|
|
1658
1806
|
|
|
1659
1807
|
### clearListeners()
|
|
@@ -1662,6 +1810,8 @@ eventData: T;
|
|
|
1662
1810
|
clearListeners(eventNames): void;
|
|
1663
1811
|
```
|
|
1664
1812
|
|
|
1813
|
+
Removes all listeners for the specified event name(s).
|
|
1814
|
+
|
|
1665
1815
|
### Parameters
|
|
1666
1816
|
|
|
1667
1817
|
#### eventNames
|
|
@@ -1680,6 +1830,8 @@ keyof `T` | keyof `T`[]
|
|
|
1680
1830
|
emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
1681
1831
|
```
|
|
1682
1832
|
|
|
1833
|
+
Emits an event, invoking all registered listeners concurrently.
|
|
1834
|
+
|
|
1683
1835
|
### Type Parameters
|
|
1684
1836
|
|
|
1685
1837
|
#### TEventName
|
|
@@ -1708,6 +1860,8 @@ emit<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1708
1860
|
emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
1709
1861
|
```
|
|
1710
1862
|
|
|
1863
|
+
Emits an event, invoking all registered listeners sequentially in order.
|
|
1864
|
+
|
|
1711
1865
|
### Type Parameters
|
|
1712
1866
|
|
|
1713
1867
|
#### TEventName
|
|
@@ -1736,6 +1890,8 @@ emitSerial<TEventName>(eventName, eventArgs): Promise<void>;
|
|
|
1736
1890
|
listenerCount(eventNames): number;
|
|
1737
1891
|
```
|
|
1738
1892
|
|
|
1893
|
+
Returns the total number of listeners registered for the specified event name(s).
|
|
1894
|
+
|
|
1739
1895
|
### Parameters
|
|
1740
1896
|
|
|
1741
1897
|
#### eventNames
|
|
@@ -1754,6 +1910,8 @@ keyof `T` | keyof `T`[]
|
|
|
1754
1910
|
off<TEventName>(eventNames, listener): void;
|
|
1755
1911
|
```
|
|
1756
1912
|
|
|
1913
|
+
Removes a specific listener from the specified event name(s).
|
|
1914
|
+
|
|
1757
1915
|
### Type Parameters
|
|
1758
1916
|
|
|
1759
1917
|
#### TEventName
|
|
@@ -1782,6 +1940,8 @@ off<TEventName>(eventNames, listener): void;
|
|
|
1782
1940
|
offAny(listener): void;
|
|
1783
1941
|
```
|
|
1784
1942
|
|
|
1943
|
+
Removes a wildcard listener that was receiving all events.
|
|
1944
|
+
|
|
1785
1945
|
### Parameters
|
|
1786
1946
|
|
|
1787
1947
|
#### listener
|
|
@@ -1800,6 +1960,8 @@ offAny(listener): void;
|
|
|
1800
1960
|
on<TEventName>(eventNames, listener): EventUnsubscribeFunction;
|
|
1801
1961
|
```
|
|
1802
1962
|
|
|
1963
|
+
Subscribes a listener to the specified event name(s) and returns an unsubscribe function.
|
|
1964
|
+
|
|
1803
1965
|
### Type Parameters
|
|
1804
1966
|
|
|
1805
1967
|
#### TEventName
|
|
@@ -1828,6 +1990,8 @@ on<TEventName>(eventNames, listener): EventUnsubscribeFunction;
|
|
|
1828
1990
|
onAny(listener): EventUnsubscribeFunction;
|
|
1829
1991
|
```
|
|
1830
1992
|
|
|
1993
|
+
Subscribes a wildcard listener that receives all events and returns an unsubscribe function.
|
|
1994
|
+
|
|
1831
1995
|
### Parameters
|
|
1832
1996
|
|
|
1833
1997
|
#### listener
|
|
@@ -1846,6 +2010,8 @@ onAny(listener): EventUnsubscribeFunction;
|
|
|
1846
2010
|
once<TEventName>(eventName, listener): EventUnsubscribeFunction;
|
|
1847
2011
|
```
|
|
1848
2012
|
|
|
2013
|
+
Subscribes a listener that will be invoked only once for the specified event, then automatically removed.
|
|
2014
|
+
|
|
1849
2015
|
### Type Parameters
|
|
1850
2016
|
|
|
1851
2017
|
#### TEventName
|
|
@@ -1878,6 +2044,8 @@ once<TEventName>(eventName, listener): EventUnsubscribeFunction;
|
|
|
1878
2044
|
type BaseEmitterParams<T> = BaseParams<T & BaseEmitterParamsFields & T>;
|
|
1879
2045
|
```
|
|
1880
2046
|
|
|
2047
|
+
Parameters type for configuring a BaseEmitter instance.
|
|
2048
|
+
|
|
1881
2049
|
## Type Parameters
|
|
1882
2050
|
|
|
1883
2051
|
### T
|
|
@@ -1969,6 +2137,8 @@ readonly name: string;
|
|
|
1969
2137
|
type EventAnyListener<TEventArgs> = (eventName, eventData) => Promisable<void>;
|
|
1970
2138
|
```
|
|
1971
2139
|
|
|
2140
|
+
A listener that receives all events regardless of name.
|
|
2141
|
+
|
|
1972
2142
|
## Type Parameters
|
|
1973
2143
|
|
|
1974
2144
|
### TEventArgs
|
|
@@ -1981,10 +2151,14 @@ type EventAnyListener<TEventArgs> = (eventName, eventData) => Promisable<void>;
|
|
|
1981
2151
|
|
|
1982
2152
|
[`EventName`](#EventName)
|
|
1983
2153
|
|
|
2154
|
+
The name of the emitted event.
|
|
2155
|
+
|
|
1984
2156
|
### eventData
|
|
1985
2157
|
|
|
1986
2158
|
`TEventArgs`
|
|
1987
2159
|
|
|
2160
|
+
The data associated with the event.
|
|
2161
|
+
|
|
1988
2162
|
## Returns
|
|
1989
2163
|
|
|
1990
2164
|
`Promisable`\<`void`\>
|
|
@@ -1999,6 +2173,8 @@ type EventAnyListener<TEventArgs> = (eventName, eventData) => Promisable<void>;
|
|
|
1999
2173
|
type EventArgs = string | number | object;
|
|
2000
2174
|
```
|
|
2001
2175
|
|
|
2176
|
+
The allowed types for event argument payloads.
|
|
2177
|
+
|
|
2002
2178
|
### <a id="EventData"></a>EventData
|
|
2003
2179
|
|
|
2004
2180
|
[**@xylabs/events**](#../README)
|
|
@@ -2009,6 +2185,8 @@ type EventArgs = string | number | object;
|
|
|
2009
2185
|
type EventData = object;
|
|
2010
2186
|
```
|
|
2011
2187
|
|
|
2188
|
+
A mapping of event names to their corresponding event argument types.
|
|
2189
|
+
|
|
2012
2190
|
## Index Signature
|
|
2013
2191
|
|
|
2014
2192
|
```ts
|
|
@@ -2025,6 +2203,8 @@ type EventData = object;
|
|
|
2025
2203
|
type EventListener<TEventArgs> = (eventData) => Promisable<void>;
|
|
2026
2204
|
```
|
|
2027
2205
|
|
|
2206
|
+
A listener for a specific event type.
|
|
2207
|
+
|
|
2028
2208
|
## Type Parameters
|
|
2029
2209
|
|
|
2030
2210
|
### TEventArgs
|
|
@@ -2037,6 +2217,8 @@ type EventListener<TEventArgs> = (eventData) => Promisable<void>;
|
|
|
2037
2217
|
|
|
2038
2218
|
`TEventArgs`
|
|
2039
2219
|
|
|
2220
|
+
The data associated with the event.
|
|
2221
|
+
|
|
2040
2222
|
## Returns
|
|
2041
2223
|
|
|
2042
2224
|
`Promisable`\<`void`\>
|
|
@@ -2051,6 +2233,8 @@ type EventListener<TEventArgs> = (eventData) => Promisable<void>;
|
|
|
2051
2233
|
type EventListenerInfo<TEventArgs> = object;
|
|
2052
2234
|
```
|
|
2053
2235
|
|
|
2236
|
+
Information about a registered event listener, including an optional filter for selective invocation.
|
|
2237
|
+
|
|
2054
2238
|
## Type Parameters
|
|
2055
2239
|
|
|
2056
2240
|
### TEventArgs
|
|
@@ -2083,6 +2267,8 @@ listener: EventListener<TEventArgs>;
|
|
|
2083
2267
|
type EventName = PropertyKey;
|
|
2084
2268
|
```
|
|
2085
2269
|
|
|
2270
|
+
A valid event name, which can be any property key (string, number, or symbol).
|
|
2271
|
+
|
|
2086
2272
|
### <a id="EventUnsubscribeFunction"></a>EventUnsubscribeFunction
|
|
2087
2273
|
|
|
2088
2274
|
[**@xylabs/events**](#../README)
|
|
@@ -2093,6 +2279,8 @@ type EventName = PropertyKey;
|
|
|
2093
2279
|
type EventUnsubscribeFunction = () => void;
|
|
2094
2280
|
```
|
|
2095
2281
|
|
|
2282
|
+
A function returned by event subscription methods that unsubscribes the listener when called.
|
|
2283
|
+
|
|
2096
2284
|
## Returns
|
|
2097
2285
|
|
|
2098
2286
|
`void`
|
|
@@ -2109,6 +2297,8 @@ type EventsParams = BaseParams<{
|
|
|
2109
2297
|
}>;
|
|
2110
2298
|
```
|
|
2111
2299
|
|
|
2300
|
+
Parameters for constructing an Events instance, with optional debug configuration.
|
|
2301
|
+
|
|
2112
2302
|
### <a id="MetaEventData"></a>MetaEventData
|
|
2113
2303
|
|
|
2114
2304
|
[**@xylabs/events**](#../README)
|
|
@@ -2119,6 +2309,8 @@ type EventsParams = BaseParams<{
|
|
|
2119
2309
|
type MetaEventData<TEventData> = object;
|
|
2120
2310
|
```
|
|
2121
2311
|
|
|
2312
|
+
Data shape for internal meta events that fire when listeners are added or removed.
|
|
2313
|
+
|
|
2122
2314
|
## Type Parameters
|
|
2123
2315
|
|
|
2124
2316
|
### TEventData
|