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
- .silent ⇒
boolean
- .silent
- .isSignal :
boolean
- .setFlag(flag) ⇒
void
- .clearFlag(flag) ⇒
void
- .writeFlag(flag, value)
- .getFlag(flag) ⇒
boolean
- .contains(handler, [thisArg]) ⇒
boolean
- .hasHandlers() ⇒
boolean
- .addOne(h, [context])
- .add(h, [context])
- .remove(h, [thisArg]) ⇒
boolean
.removeAll()- .dispatch(...args)
- .send0()
- .send1(arg)
- .send2(a, b)
- .send3(a, b, c)
- .send4(a, b, c, d)
- .send6(a, b, c, d, e, f)
- .send8(a, b, c, d, e, f, g, h)
- .merge(other) ⇒
Signal
- .generation :
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
Param | Type |
---|---|
v | boolean |
signal.isSignal : boolean
Kind: instance property of Signal
Read only: true
signal.setFlag(flag) ⇒ void
Kind: instance method of Signal
Param | Type |
---|---|
flag | number | SignalFlags |
signal.clearFlag(flag) ⇒ void
Kind: instance method of Signal
Param | Type |
---|---|
flag | number | SignalFlags |
signal.writeFlag(flag, value)
Kind: instance method of Signal
Param | Type |
---|---|
flag | number | SignalFlags |
value | boolean |
signal.getFlag(flag) ⇒ boolean
Kind: instance method of Signal
Param | Type |
---|---|
flag | number | SignalFlags |
signal.contains(handler, [thisArg]) ⇒ boolean
Checks if a given signal handler is present or not
Kind: instance method of Signal
Param | Type | Description |
---|---|---|
handler | function | |
[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
Param | Type |
---|---|
h | function |
[context] | * |
signal.add(h, [context])
Kind: instance method of Signal
Param | Type |
---|---|
h | function |
[context] | * |
signal.remove(h, [thisArg]) ⇒ boolean
Kind: instance method of Signal
Returns: boolean
- true if a handler was removed, false otherwise
Param | Type | Description |
---|---|---|
h | function | |
[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
Param | Type |
---|---|
...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
Param | Type |
---|---|
arg | * |
signal.send2(a, b)
Kind: instance method of Signal
Param | Type |
---|---|
a | * |
b | * |
signal.send3(a, b, c)
Kind: instance method of Signal
Param | Type |
---|---|
a | * |
b | * |
c | * |
signal.send4(a, b, c, d)
Kind: instance method of Signal
Param | Type |
---|---|
a | * |
b | * |
c | * |
d | * |
signal.send6(a, b, c, d, e, f)
Kind: instance method of Signal
Param | Type |
---|---|
a | * |
b | * |
c | * |
d | * |
e | * |
f | * |
signal.send8(a, b, c, d, e, f, g, h)
Kind: instance method of Signal
Param | Type |
---|---|
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
Param | Type |
---|---|
other | Signal |