You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/core/Signal.js
+36-22Lines changed: 36 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,9 @@
6
6
*/
7
7
8
8
/**
9
-
* A Signal is used for object communication via a custom broadcaster instead of Events.
9
+
* A Signal is an event dispatch mechansim than supports broadcasting to multiple listeners.
10
+
*
11
+
* Event listeners are uniquely identified by the listener/callback function and the context.
10
12
*
11
13
* @class Phaser.Signal
12
14
* @constructor
@@ -29,9 +31,11 @@ Phaser.Signal.prototype = {
29
31
_prevParams: null,
30
32
31
33
/**
32
-
* If Signal should keep record of previously dispatched parameters and
33
-
* automatically execute listener during `add()`/`addOnce()` if Signal was
34
-
* already dispatched before.
34
+
* Memorize the previously dispatched event?
35
+
*
36
+
* If an event has been memorized it is automatically dispatched when a new listener is added with {@link #add} or {@link #addOnce}.
37
+
* Use {@link #forget} to clear any currently memorized event.
38
+
*
35
39
* @property {boolean} memorize
36
40
*/
37
41
memorize: false,
@@ -43,8 +47,10 @@ Phaser.Signal.prototype = {
43
47
_shouldPropagate: true,
44
48
45
49
/**
46
-
* If Signal is active and should broadcast events.
47
-
* IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
50
+
* Is the Signal active? Only active signal will broadcast dispatched events.
51
+
*
52
+
* Setting this property during a dispatch will only affect the next dispatch. To stop the propagation of a signal from a listener use {@link #halt}.
53
+
*
48
54
* @property {boolean} active
49
55
* @default
50
56
*/
@@ -167,7 +173,7 @@ Phaser.Signal.prototype = {
167
173
},
168
174
169
175
/**
170
-
* Check if listener was attached to Signal.
176
+
* Check if a specific listener is attached.
171
177
*
172
178
* @method Phaser.Signal#has
173
179
* @param {function} listener - Signal handler function.
@@ -181,7 +187,7 @@ Phaser.Signal.prototype = {
181
187
},
182
188
183
189
/**
184
-
* Add a listener to the signal.
190
+
* Add an event listener.
185
191
*
186
192
* @method Phaser.Signal#add
187
193
* @param {function} listener - The function to call when this Signal is dispatched.
@@ -198,7 +204,10 @@ Phaser.Signal.prototype = {
198
204
},
199
205
200
206
/**
201
-
* Add listener to the signal that should be removed after first execution (will be executed only once).
207
+
* Add a one-time listener - the listener is automatically removed after the first execution.
208
+
*
209
+
* If there is as {@link Phaser.Signal#memorize memorized} event then it will be dispatched and
210
+
* the listener will be removed immediately.
202
211
*
203
212
* @method Phaser.Signal#addOnce
204
213
* @param {function} listener - The function to call when this Signal is dispatched.
@@ -215,7 +224,7 @@ Phaser.Signal.prototype = {
215
224
},
216
225
217
226
/**
218
-
* Remove a single listener from the dispatch queue.
227
+
* Remove a single event listener.
219
228
*
220
229
* @method Phaser.Signal#remove
221
230
* @param {function} listener - Handler function that should be removed.
@@ -239,7 +248,7 @@ Phaser.Signal.prototype = {
239
248
},
240
249
241
250
/**
242
-
* Remove all listeners from the Signal.
251
+
* Remove all event listeners.
243
252
*
244
253
* @method Phaser.Signal#removeAll
245
254
* @param {object} [context=null] - If specified only listeners for the given context will be removed.
@@ -282,7 +291,7 @@ Phaser.Signal.prototype = {
282
291
* Gets the total number of listeners attached to this Signal.
283
292
*
284
293
* @method Phaser.Signal#getNumListeners
285
-
* @return {number} Number of listeners attached to the Signal.
294
+
* @return {integer} Number of listeners attached to the Signal.
286
295
*/
287
296
getNumListeners: function(){
288
297
@@ -292,8 +301,9 @@ Phaser.Signal.prototype = {
292
301
293
302
/**
294
303
* Stop propagation of the event, blocking the dispatch to next listener on the queue.
295
-
* IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
296
-
* @see Signal.prototype.disable
304
+
*
305
+
* This should be called only during event dispatch as calling it before/after dispatch won't affect other broadcast.
306
+
* See {@link #active} to enable/disable the signal entirely.
297
307
*
298
308
* @method Phaser.Signal#halt
299
309
*/
@@ -304,9 +314,9 @@ Phaser.Signal.prototype = {
304
314
},
305
315
306
316
/**
307
-
* Dispatch/Broadcast Signal to all listeners added to the queue.
317
+
* Dispatch / broadcast the event to all listeners.
308
318
*
309
-
* To create a bound dispatch for this Signal, use {@linkPhaser.Signal#boundDispatch}.
319
+
* To create an instance-bound dispatch for this Signal, use {@link #boundDispatch}.
310
320
*
311
321
* @method Phaser.Signal#dispatch
312
322
* @param {any} [params] - Parameters that should be passed to each handler.
@@ -346,8 +356,7 @@ Phaser.Signal.prototype = {
346
356
},
347
357
348
358
/**
349
-
* Forget memorized arguments.
350
-
* @see Signal.memorize
359
+
* Forget the currently {@link Phaser.Signal#memorize memorized} event, if any.
351
360
*
352
361
* @method Phaser.Signal#forget
353
362
*/
@@ -361,8 +370,10 @@ Phaser.Signal.prototype = {
361
370
},
362
371
363
372
/**
364
-
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
365
-
* IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
373
+
* Dispose the signal - no more events can be dispatched.
374
+
*
375
+
* This removes all event listeners and clears references to external objects.
376
+
* Calling methods on a disposed objects results in undefined behavior.
366
377
*
367
378
* @method Phaser.Signal#dispose
368
379
*/
@@ -379,6 +390,7 @@ Phaser.Signal.prototype = {
379
390
},
380
391
381
392
/**
393
+
* A string representation of the object.
382
394
*
383
395
* @method Phaser.Signal#toString
384
396
* @return {string} String representation of the object.
@@ -392,8 +404,10 @@ Phaser.Signal.prototype = {
392
404
};
393
405
394
406
/**
395
-
* If the dispatch function needs to be passed somewhere, or called independently
396
-
* of the Signal object, use this function.
407
+
* Create a `dispatch` function that maintains a binding to the original Signal context.
408
+
*
409
+
* Use the resulting value if the dispatch function needs to be passed somewhere
0 commit comments