API Docs for: 1.4.0
Show:

Kiwi.Signal Class

Defined in: src\core\Signal.ts:9
Module: Kiwi

A TypeScript conversion of JS Signals by Miller Medeiros. Released under the MIT license http://millermedeiros.github.com/js-signals/

Constructor

Kiwi.Signal

()

Methods

_addBinding

(
  • binding
)
private

Handles the process of adding a new SignalBinding to the bindings list by the new Bindings priority.

Parameters:

_indexOfListener

(
  • listener
  • context
)
Number private

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 Function

    The method that we are checking to see.

  • context Any

    The context of the method we are checking.

Returns:

Number:

The index of listener/context.

_registerListener

(
  • listener
  • isOnce
  • listenerContext
  • priority
)
Kiwi.SignalBinding private

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 Function

    The method that is to be dispatched.

  • isOnce Boolean

    If the method should only be dispatched a single time or not.

  • listenerContext Object

    The context that the callback should be executed with when called.

  • priority Number

    The priority of this callback when Bindings are dispatched.

Returns:

Kiwi.SignalBinding:

The new SignalBinding that was created.

add

(
  • listener
  • [listenerContext=null]
  • [priority=0]
)
Kiwi.SignalBinding public

Adds a new listener/callback to this Signal. The listener attached will be executed whenever this Signal dispatches an event.

Parameters:

  • listener Function

    Signal handler function.

  • [listenerContext=null] Any optional

    Context on which listener will be executed. (object that should represent the this variable inside listener function).

  • [priority=0] 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:

Kiwi.SignalBinding:

An Object representing the binding between the Signal and listener.

addOnce

(
  • listener
  • [listenerContext=null]
  • [priority=0]
)
Kiwi.SignalBinding public

Add listener to the signal that should be removed after first execution (will be executed only once).

Parameters:

  • listener Function

    Signal handler function.

  • [listenerContext=null] Any optional

    Context on which listener will be executed (object that should represent the this variable inside listener function).

  • [priority=0] 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:

Kiwi.SignalBinding:

An Object representing the binding between the Signal and listener.

dispatch

(
  • [params]
)
public

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 multiple

    Parameters 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:

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]
)
Boolean public

Accepts a function and returns a boolean indicating if the function has already been attached to this Signal.

Parameters:

  • listener Function

    The method you are checking for.

  • [context=null] Any optional

    The context of the listener.

Returns:

Boolean:

If this Signal already has the specified listener.

objType

() String public

Returns the type of this object

Returns:

String:

"Signal"

remove

(
  • listener
  • [context=null]
)
Function public

Remove a single listener from the dispatch queue.

Parameters:

  • listener Function

    Handler function that should be removed.

  • [context=null] Any optional

    Execution context (since you can add the same handler multiple times if executing in a different context).

Returns:

Function:

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
)
public

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 Any

    The event listener to be validated.

  • fnName Any

    The 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'