1
1
package io .scalajs .nodejs .events
2
2
3
+ import com .thoughtworks .enableIf
4
+
3
5
import scala .scalajs .js
4
6
import scala .scalajs .js .annotation .JSImport
5
7
@@ -48,7 +50,9 @@ trait IEventEmitter extends js.Object {
48
50
* @param args the event arguments
49
51
* @example emitter.emit(name[, arg1][, arg2][, ...])
50
52
*/
51
- def emit (name : String , args : js.Any * ): Any = js.native
53
+ def emit (name : String , args : js.Any * ): Boolean = js.native
54
+
55
+ def eventNames (): js.Array [String ] = js.native
52
56
53
57
/**
54
58
* Returns the current max listener value for the EventEmitter which is either set by
@@ -70,6 +74,9 @@ trait IEventEmitter extends js.Object {
70
74
*/
71
75
def listeners (eventName : String ): js.Array [js.Function ] = js.native
72
76
77
+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs10)
78
+ def off (eventName : String , listner : js.Function ): this .type = js.native
79
+
73
80
/**
74
81
* Adds the listener function to the end of the listeners array for the event named eventName.
75
82
* No checks are made to see if the listener has already been added. Multiple calls passing
@@ -87,15 +94,9 @@ trait IEventEmitter extends js.Object {
87
94
*/
88
95
def once (eventName : String , listener : js.Function ): this .type = js.native
89
96
90
- /**
91
- * Removes all listeners, or those of the specified eventName.
92
- * <p/><b>Note</b> that it is bad practice to remove listeners added elsewhere in the code,
93
- * particularly when the EventEmitter instance was created by some other component or
94
- * module (e.g. sockets or file streams).
95
- * <p/>Returns a reference to the EventEmitter so calls can be chained.
96
- * @example emitter.removeAllListeners([eventName])
97
- */
98
- def removeAllListeners (eventName : String ): this .type = js.native
97
+ def prependListener (eventName : String , listener : js.Function ): this .type = js.native
98
+
99
+ def prependOnceListener (eventName : String , listener : js.Function ): this .type = js.native
99
100
100
101
/**
101
102
* Removes all listeners, or those of the specified eventName.
@@ -105,7 +106,7 @@ trait IEventEmitter extends js.Object {
105
106
* <p/>Returns a reference to the EventEmitter so calls can be chained.
106
107
* @example emitter.removeAllListeners([eventName])
107
108
*/
108
- def removeAllListeners (): this .type = js.native
109
+ def removeAllListeners (eventName : String = js.native ): this .type = js.native
109
110
110
111
/**
111
112
* Removes the specified listener from the listener array for the event named eventName.
@@ -131,6 +132,8 @@ trait IEventEmitter extends js.Object {
131
132
*/
132
133
def setMaxListeners (n : Int ): this .type = js.native
133
134
135
+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs10)
136
+ def rawListeners (eventName : String ): js.Array [js.Function ] = js.native
134
137
}
135
138
136
139
/**
@@ -155,4 +158,6 @@ object EventEmitter extends IEventEmitter {
155
158
@ deprecated(" Use emitter.listenerCount() instead." , since = " 4.0.0" )
156
159
def listenerCount (emitter : IEventEmitter , eventName : String ): Unit = js.native
157
160
161
+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs12)
162
+ def once (emitter : IEventEmitter , eventName : String ): js.Promise [js.Array [js.Any ]] = js.native
158
163
}
0 commit comments