Signal

A Signal is like a proxy function that can have multiple "listeners" assigned to it, such that when the Signal is executed (or "emitted"), it executes each of its associated listeners. A listener is a callback function, object method, or another Signal.

Signals are used extensively throughout Loki3D. They are similar to Javascript events, with the advantage of being bound to an object rather than a string, so they are very explicit about what signals are provided and reduce errors from mis-spelling event names.

Constructor

new L3D.Signal(name)

Parameters
name String ""

Optional name for the signal, usually used for debugging purposes.

Properties

static enabled bool

Returns true if signals are allowed to be emitted. If false, calling the Signal's emit method will do nothing.

hasListeners bool

True if this signal has at least one listener.

Methods

static disable()

Disables all signals from being emitted. This can be called multiple times, but an equal number of calls to enable should be used to re-enable signals. This is often used to disable any callbacks while doing heavy operations, like file loading, so a single signal will be emitted at the end.

static disconnect(object, callback, instance)

Disconnect the listener from all signals of the given object.

Parameters
object Object

The object to disconnect from.

callback function | Signal | Object

The listener to disconnect

instance Object null

The optional listener instance that owns callback.

static enable(force)

Enable signals to be emitted, having been previously disabled.

Parameters
force bool false

If true, signals will be forced to the enabled state, even if there were an unbalanced number of calls to disable..

static getSignals(object, out) → Array

Return all signals that belong to the object.

Parameters
object Object

The object to get the signals from.

out Array

Optional storage for the results. A new array will be created if null.

Returns
Array

The list of signals that belong to the object.

addListener(callback, object)

Connect a listener to the signal. This can be a function, object method, class static method, or another signal. There is no type-checking to ensure the listener function can successfully receive the arguments that will be emitted by the signal, which will result in an exception of you connect an incompatible listener and emit the signal. To have an object method listen to a signal, pass in the object, too.

listen(Function)
listen(Signal)
listen(method, object)
Parameters
callback function | Signal
object Object null

disconnect(callback, object)

Disconnect a listener from the signal.

disconnect(Object) -- Disconnect all method listeners of the given object.
disconnect(Function) -- Disconnect the function listener.
disconnect(Signal) -- Disconnect the signal listener.
disconnect(method, object) -- Disconnect the method listener.
disconnect() -- Disconnect all listeners from the signal.
Parameters
callback *
object Object

emit(…arguments)

Emit a signal, calling all listeners.

Parameters
arguments* *

Optional arguments to call the listeners with.

isListening(callback, object) → bool

Checks if there is a binded listener that matches the criteria.

isListening(Signal)
isListening(callback)
isListening(object)
isListening(method, object)
Parameters
callback function | Signal | Object
object Object null
Returns
bool