File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ import EventEmitter from "node:events"
2
+
3
+
4
+
5
+ class ExtendedEventEmitter extends EventEmitter {
6
+ constructor ( ) {
7
+ super ( )
8
+ this . emittedEventNames ( )
9
+ this . eventNames ( )
10
+ }
11
+ /**
12
+ *
13
+ * @returns {any[] }
14
+ */
15
+ emittedEventNames ( ) {
16
+ return [ ]
17
+ }
18
+ /**
19
+ *
20
+ * @returns {any[] }
21
+ */
22
+ emittedEvents ( ) {
23
+ return [ ]
24
+ }
25
+ /**
26
+ *
27
+ * @param {string | symbol } eventName
28
+ * @returns
29
+ */
30
+ hasListener ( eventName ) {
31
+ return super . eventNames ( ) . some ( ( e ) => e === eventName )
32
+ }
33
+ /**
34
+ *
35
+ * @param {string | symbol } eventName
36
+ * @returns
37
+ */
38
+ emit ( eventName , ...args ) {
39
+ this . emittedEventNames . push ( event )
40
+ this . emittedEvents . push ( {
41
+ eventName,
42
+ args : args
43
+ } )
44
+ return super . emit ( eventName , ...args )
45
+ }
46
+ /**
47
+ *
48
+ * @param {string | symbol } eventName
49
+ * @returns
50
+ */
51
+ hasEmit ( eventName ) {
52
+ return this . emittedEventNames . some ( eName => eName === eventName )
53
+ }
54
+ }
55
+
56
+ export default ExtendedEventEmitter
You can’t perform that action at this time.
0 commit comments