Kiwi.Signal Class
A TypeScript conversion of JS Signals by Miller Medeiros. Released under the MIT license http://millermedeiros.github.com/js-signals/
Constructor
Kiwi.Signal
()
Item Index
Methods
Properties
Methods
_addBinding
-
binding
Handles the process of adding a new SignalBinding to the bindings list by the new Bindings priority.
Parameters:
-
binding
Kiwi.SignalBinding
_indexOfListener
-
listener
-
context
Returns the index of any Binding which matches the listener and context that is passed. If none match then this method returns -1.
Parameters:
-
listener
FunctionThe method that we are checking to see.
-
context
AnyThe context of the method we are checking.
Returns:
The index of listener/context.
_registerListener
-
listener
-
isOnce
-
listenerContext
-
priority
Internal Code which handles the registeration of a new callback (known as a "listener"). Creates a new SignalBinding for the Signal and then adds the binding to the list by its priority level.
Parameters:
-
listener
FunctionThe method that is to be dispatched.
-
isOnce
BooleanIf the method should only be dispatched a single time or not.
-
listenerContext
ObjectThe context that the callback should be executed with when called.
-
priority
NumberThe priority of this callback when Bindings are dispatched.
Returns:
The new SignalBinding that was created.
add
-
listener
-
[listenerContext=null]
-
[priority=0]
Adds a new listener/callback to this Signal. The listener attached will be executed whenever this Signal dispatches an event.
Parameters:
-
listener
FunctionSignal handler function.
-
[listenerContext=null]
Any optionalContext on which listener will be executed. (object that should represent the
this
variable inside listener function). -
[priority=0]
Number optionalThe 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.
addOnce
-
listener
-
[listenerContext=null]
-
[priority=0]
Add listener to the signal that should be removed after first execution (will be executed only once).
Parameters:
-
listener
FunctionSignal handler function.
-
[listenerContext=null]
Any optionalContext on which listener will be executed (object that should represent the
this
variable inside listener function). -
[priority=0]
Number optionalThe 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.
dispatch
-
[params]
Dispatch/Broadcast to all listeners added to this Signal. Parameters passed to this method will also be passed to each handler.
Parameters:
-
[params]
Any optional multipleParameters that should be passed to each handler.
dispose
()
public
Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). Note: calling any method on the signal instance after calling dispose will throw errors.
forget
()
public
Forget memorized arguments. See the 'memorize' property.
getNumListeners
()
Number
public
Returns the number of listeners that have been attached to this Signal.
Returns:
Number of listeners attached to the Signal.
halt
()
public
Stop propagation of the event, blocking the dispatch to next listeners on the queue. Note: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
has
-
listener
-
[context=null]
Accepts a function and returns a boolean indicating if the function has already been attached to this Signal.
Parameters:
-
listener
FunctionThe method you are checking for.
-
[context=null]
Any optionalThe context of the listener.
Returns:
If this Signal already has the specified listener.
objType
()
String
public
Returns the type of this object
Returns:
"Signal"
remove
-
listener
-
[context=null]
Remove a single listener from the dispatch queue.
Parameters:
-
listener
FunctionHandler function that should be removed.
-
[context=null]
Any optionalExecution context (since you can add the same handler multiple times if executing in a different context).
Returns:
Listener handler function.
removeAll
()
public
Remove all listeners from the Signal.
resume
()
public
Resume propagation of the event, resuming the dispatch to next listeners on the queue. Note: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
validateListener
-
listener
-
fnName
Validates a event listener an is used to check to see if it is valid or not. An event listener is not valid if it is not a function. If a event listener is not valid, then a Error is thrown.
Parameters:
-
listener
AnyThe event listener to be validated.
-
fnName
AnyThe name of the function.
Properties
_bindings
Array
private
A list of all of the signal bindings that have been attached.
_prevParams
Any
private
_shouldPropagate
Boolean
private
If the callbacks should propagate or not.
Default: true
active
Boolean
public
If Signal is active and should broadcast events.
Note: 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: true
memorize
Boolean
public
If Signal should keep record of previously dispatched parameters.
Default: false
VERSION
String
public
final
static
Signals Version Number
Default: '1.0.0'