Skip to main content

Signal

Signal

Signal is a type of event bus. You can subscribe to events using add method and dispatch using sendN method where N is the number of arguments you wish to pass Signal is different from a normal event bus in that 1 signal corresponds to 1 event type. For example, in HTML you have addEventListener which lets you subscribe to any kind of event, let's use "mousedown" as a reference. Using a Signal you would instead have a signal corresponding to "mousedown" and dispatch this signal only for this event.

Kind: global class

signal.generation : number

Used to track dispatches, handlers that have the same generation ID as the signal will not be dispatched

Kind: instance property of Signal

signal.silent ⇒ boolean

Kind: instance property of Signal

signal.silent

Kind: instance property of Signal

ParamType
vboolean

signal.isSignal : boolean

Kind: instance property of Signal
Read only: true

signal.setFlag(flag) ⇒ void

Kind: instance method of Signal

ParamType
flagnumber | SignalFlags

signal.clearFlag(flag) ⇒ void

Kind: instance method of Signal

ParamType
flagnumber | SignalFlags

signal.writeFlag(flag, value)

Kind: instance method of Signal

ParamType
flagnumber | SignalFlags
valueboolean

signal.getFlag(flag) ⇒ boolean

Kind: instance method of Signal

ParamType
flagnumber | SignalFlags

signal.contains(handler, [thisArg]) ⇒ boolean

Checks if a given signal handler is present or not

Kind: instance method of Signal

ParamTypeDescription
handlerfunction
[thisArg]*if not present, will not be considered

signal.hasHandlers() ⇒ boolean

Tells if there are any handlers attached to the signal or not

Kind: instance method of Signal

signal.addOne(h, [context])

Handler will only be run once, it will be removed automatically after the first execution

Kind: instance method of Signal

ParamType
hfunction
[context]*

signal.add(h, [context])

Kind: instance method of Signal

ParamType
hfunction
[context]*

signal.remove(h, [thisArg]) ⇒ boolean

Kind: instance method of Signal
Returns: boolean - true if a handler was removed, false otherwise

ParamTypeDescription
hfunction
[thisArg]*if supplied, will match handlers with a specific context only

signal.removeAll()

Deprecated

Remove all handlers. Please note that this will remove even all handlers, irrespective of where they were added from. If another script is attaching to the same signal, using this method will potentially break that code. For most use cases, prefer to use remove method instead, or make use of SignalBinding if you need to keep track of multiple handlers NOTE: Consider this method to be unsafe, only use it when you understand the implications

Kind: instance method of Signal

signal.dispatch(...args)

NOTE: because of polymorphic call-site nature of this method, it's always better for performance to use monomorphic methods like send0, send1 etc.

Kind: instance method of Signal

ParamType
...args*

signal.send0()

dispatch without a value. Allows JS engine to optimize for monomorphic call sites

Kind: instance method of Signal

signal.send1(arg)

dispatch with a single value. Allows JS engine to optimize for monomorphic call sites

Kind: instance method of Signal

ParamType
arg*

signal.send2(a, b)

Kind: instance method of Signal

ParamType
a*
b*

signal.send3(a, b, c)

Kind: instance method of Signal

ParamType
a*
b*
c*

signal.send4(a, b, c, d)

Kind: instance method of Signal

ParamType
a*
b*
c*
d*

signal.send6(a, b, c, d, e, f)

Kind: instance method of Signal

ParamType
a*
b*
c*
d*
e*
f*

signal.send8(a, b, c, d, e, f, g, h)

Kind: instance method of Signal

ParamType
a*
b*
c*
d*
e*
f*
g*
h*

signal.merge(other) ⇒ Signal

Kind: instance method of Signal
Returns: Signal - merged signal combining events from this and other

ParamType
otherSignal