new Signal()
A Signal is used for object communication via a custom broadcaster instead of Events.
- Source - core/Signal.js, line 14
Members
-
active :boolean
-
If Signal is active and should broadcast events. 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.- Default Value:
- true
- Source - core/Signal.js, line 51
-
memorize :boolean
-
If Signal should keep record of previously dispatched parameters and automatically execute listener during
add()
/addOnce()
if Signal was already dispatched before.- Source - core/Signal.js, line 37
Methods
-
add(listener, listenerContext, priority) → {Phaser.SignalBinding}
-
Add a listener to the signal.
Parameters:
Name Type Argument Description listener
function The function to call when this Signal is dispatched.
listenerContext
object <optional>
The context under which the listener will be executed (i.e. the object that should represent the
this
variable).priority
number <optional>
The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0)
Returns:
An Object representing the binding between the Signal and listener.
- Source - core/Signal.js, line 183
-
addOnce(listener, listenerContext, priority) → {Phaser.SignalBinding}
-
Add listener to the signal that should be removed after first execution (will be executed only once).
Parameters:
Name Type Argument Description listener
function The function to call when this Signal is dispatched.
listenerContext
object <optional>
The context under which the listener will be executed (i.e. the object that should represent the
this
variable).priority
number <optional>
The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0)
Returns:
An Object representing the binding between the Signal and listener.
- Source - core/Signal.js, line 200
-
dispatch(params)
-
Dispatch/Broadcast Signal to all listeners added to the queue.
To create a bound dispatch for this Signal, use Phaser.Signal#boundDispatch.
Parameters:
Name Type Argument Description params
any <optional>
Parameters that should be passed to each handler.
- Source - core/Signal.js, line 306
-
dispose()
-
Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
- Source - core/Signal.js, line 363
-
forget()
-
Forget memorized arguments.
- Source - core/Signal.js, line 348
- See:
-
- Signal.memorize
-
getNumListeners() → {number}
-
Gets the total number of listeners attached to this Signal.
Returns:
number -Number of listeners attached to the Signal.
- Source - core/Signal.js, line 281
-
halt()
-
Stop propagation of the event, blocking the dispatch to next listener on the queue. IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
- Source - core/Signal.js, line 293
- See:
-
- Signal.prototype.disable
-
has(listener, context) → {boolean}
-
Check if listener was attached to Signal.
Parameters:
Name Type Argument Description listener
function Signal handler function.
context
object <optional>
Context on which listener will be executed (object that should represent the
this
variable inside listener function).Returns:
boolean -If Signal has the specified listener.
- Source - core/Signal.js, line 169
-
remove(listener, context) → {function}
-
Remove a single listener from the dispatch queue.
Parameters:
Name Type Argument Default Description listener
function Handler function that should be removed.
context
object <optional>
null Execution context (since you can add the same handler multiple times if executing in a different context).
Returns:
function -Listener handler function.
- Source - core/Signal.js, line 217
-
removeAll(context)
-
Remove all listeners from the Signal.
Parameters:
Name Type Argument Default Description context
object <optional>
null If specified only listeners for the given context will be removed.
- Source - core/Signal.js, line 241
-
toString() → {string}
-
Returns:
string -String representation of the object.
- Source - core/Signal.js, line 381