Skip to content

Commit bedab93

Browse files
committed
Documentation - Signal
1 parent b66a32e commit bedab93

1 file changed

Lines changed: 36 additions & 22 deletions

File tree

src/core/Signal.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77

88
/**
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.
1012
*
1113
* @class Phaser.Signal
1214
* @constructor
@@ -29,9 +31,11 @@ Phaser.Signal.prototype = {
2931
_prevParams: null,
3032

3133
/**
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+
*
3539
* @property {boolean} memorize
3640
*/
3741
memorize: false,
@@ -43,8 +47,10 @@ Phaser.Signal.prototype = {
4347
_shouldPropagate: true,
4448

4549
/**
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+
*
4854
* @property {boolean} active
4955
* @default
5056
*/
@@ -167,7 +173,7 @@ Phaser.Signal.prototype = {
167173
},
168174

169175
/**
170-
* Check if listener was attached to Signal.
176+
* Check if a specific listener is attached.
171177
*
172178
* @method Phaser.Signal#has
173179
* @param {function} listener - Signal handler function.
@@ -181,7 +187,7 @@ Phaser.Signal.prototype = {
181187
},
182188

183189
/**
184-
* Add a listener to the signal.
190+
* Add an event listener.
185191
*
186192
* @method Phaser.Signal#add
187193
* @param {function} listener - The function to call when this Signal is dispatched.
@@ -198,7 +204,10 @@ Phaser.Signal.prototype = {
198204
},
199205

200206
/**
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.
202211
*
203212
* @method Phaser.Signal#addOnce
204213
* @param {function} listener - The function to call when this Signal is dispatched.
@@ -215,7 +224,7 @@ Phaser.Signal.prototype = {
215224
},
216225

217226
/**
218-
* Remove a single listener from the dispatch queue.
227+
* Remove a single event listener.
219228
*
220229
* @method Phaser.Signal#remove
221230
* @param {function} listener - Handler function that should be removed.
@@ -239,7 +248,7 @@ Phaser.Signal.prototype = {
239248
},
240249

241250
/**
242-
* Remove all listeners from the Signal.
251+
* Remove all event listeners.
243252
*
244253
* @method Phaser.Signal#removeAll
245254
* @param {object} [context=null] - If specified only listeners for the given context will be removed.
@@ -282,7 +291,7 @@ Phaser.Signal.prototype = {
282291
* Gets the total number of listeners attached to this Signal.
283292
*
284293
* @method Phaser.Signal#getNumListeners
285-
* @return {number} Number of listeners attached to the Signal.
294+
* @return {integer} Number of listeners attached to the Signal.
286295
*/
287296
getNumListeners: function () {
288297

@@ -292,8 +301,9 @@ Phaser.Signal.prototype = {
292301

293302
/**
294303
* 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.
297307
*
298308
* @method Phaser.Signal#halt
299309
*/
@@ -304,9 +314,9 @@ Phaser.Signal.prototype = {
304314
},
305315

306316
/**
307-
* Dispatch/Broadcast Signal to all listeners added to the queue.
317+
* Dispatch / broadcast the event to all listeners.
308318
*
309-
* To create a bound dispatch for this Signal, use {@link Phaser.Signal#boundDispatch}.
319+
* To create an instance-bound dispatch for this Signal, use {@link #boundDispatch}.
310320
*
311321
* @method Phaser.Signal#dispatch
312322
* @param {any} [params] - Parameters that should be passed to each handler.
@@ -346,8 +356,7 @@ Phaser.Signal.prototype = {
346356
},
347357

348358
/**
349-
* Forget memorized arguments.
350-
* @see Signal.memorize
359+
* Forget the currently {@link Phaser.Signal#memorize memorized} event, if any.
351360
*
352361
* @method Phaser.Signal#forget
353362
*/
@@ -361,8 +370,10 @@ Phaser.Signal.prototype = {
361370
},
362371

363372
/**
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.
366377
*
367378
* @method Phaser.Signal#dispose
368379
*/
@@ -379,6 +390,7 @@ Phaser.Signal.prototype = {
379390
},
380391

381392
/**
393+
* A string representation of the object.
382394
*
383395
* @method Phaser.Signal#toString
384396
* @return {string} String representation of the object.
@@ -392,8 +404,10 @@ Phaser.Signal.prototype = {
392404
};
393405

394406
/**
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
410+
* or called independently of the Signal object.
397411
*
398412
* @memberof Phaser.Signal
399413
* @property {function} boundDispatch

0 commit comments

Comments
 (0)