/
EventEmitter.js
178 lines (158 loc) · 4.07 KB
/
EventEmitter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../utils/Class');
var EE = require('eventemitter3');
var PluginCache = require('../plugins/PluginCache');
/**
* @classdesc
* EventEmitter is a Scene Systems plugin compatible version of eventemitter3.
*
* @class EventEmitter
* @memberof Phaser.Events
* @constructor
* @since 3.0.0
*/
var EventEmitter = new Class({
Extends: EE,
initialize:
function EventEmitter ()
{
EE.call(this);
},
/**
* Removes all listeners.
*
* @method Phaser.Events.EventEmitter#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
this.removeAllListeners();
},
/**
* Removes all listeners.
*
* @method Phaser.Events.EventEmitter#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.removeAllListeners();
}
});
/**
* Return an array listing the events for which the emitter has registered listeners.
*
* @method Phaser.Events.EventEmitter#eventNames
* @since 3.0.0
*
* @return {Array.<string|symbol>}
*/
/**
* Return the listeners registered for a given event.
*
* @method Phaser.Events.EventEmitter#listeners
* @since 3.0.0
*
* @param {(string|symbol)} event - The event name.
*
* @return {Function[]} The registered listeners.
*/
/**
* Return the number of listeners listening to a given event.
*
* @method Phaser.Events.EventEmitter#listenerCount
* @since 3.0.0
*
* @param {(string|symbol)} event - The event name.
*
* @return {number} The number of listeners.
*/
/**
* Calls each of the listeners registered for a given event.
*
* @method Phaser.Events.EventEmitter#emit
* @since 3.0.0
*
* @param {(string|symbol)} event - The event name.
* @param {...*} [args] - Additional arguments that will be passed to the event handler.
*
* @return {boolean} `true` if the event had listeners, else `false`.
*/
/**
* Add a listener for a given event.
*
* @method Phaser.Events.EventEmitter#on
* @since 3.0.0
*
* @param {(string|symbol)} event - The event name.
* @param {function} fn - The listener function.
* @param {*} [context=this] - The context to invoke the listener with.
*
* @return {this} `this`.
*/
/**
* Add a listener for a given event.
*
* @method Phaser.Events.EventEmitter#addListener
* @since 3.0.0
*
* @param {(string|symbol)} event - The event name.
* @param {function} fn - The listener function.
* @param {*} [context=this] - The context to invoke the listener with.
*
* @return {this} `this`.
*/
/**
* Add a one-time listener for a given event.
*
* @method Phaser.Events.EventEmitter#once
* @since 3.0.0
*
* @param {(string|symbol)} event - The event name.
* @param {function} fn - The listener function.
* @param {*} [context=this] - The context to invoke the listener with.
*
* @return {this} `this`.
*/
/**
* Remove the listeners of a given event.
*
* @method Phaser.Events.EventEmitter#removeListener
* @since 3.0.0
*
* @param {(string|symbol)} event - The event name.
* @param {function} [fn] - Only remove the listeners that match this function.
* @param {*} [context] - Only remove the listeners that have this context.
* @param {boolean} [once] - Only remove one-time listeners.
*
* @return {this} `this`.
*/
/**
* Remove the listeners of a given event.
*
* @method Phaser.Events.EventEmitter#off
* @since 3.0.0
*
* @param {(string|symbol)} event - The event name.
* @param {function} [fn] - Only remove the listeners that match this function.
* @param {*} [context] - Only remove the listeners that have this context.
* @param {boolean} [once] - Only remove one-time listeners.
*
* @return {this} `this`.
*/
/**
* Remove all listeners, or those of the specified event.
*
* @method Phaser.Events.EventEmitter#removeAllListeners
* @since 3.0.0
*
* @param {(string|symbol)} [event] - The event name.
*
* @return {this} `this`.
*/
PluginCache.register('EventEmitter', EventEmitter, 'events');
module.exports = EventEmitter;