Constructor
new Signal()
Creates an instance of Signal
Example
const mySignal = new Signal()
mySignal.add(bar => { console.log(bar) })
mySignal.dispatch('foo')
Methods
add(cb, optionsopt) → {this}
Add a listener
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cb |
listenerCallback | Callback |
|||||||||||||||||||||
options |
Object |
<optional> |
Options Properties
|
Throws:
-
-
First argument must be a Function
- Type
- TypeError
-
-
-
Listener already exists
- Type
- Error
-
Returns:
- Type
- this
dispatch(…argsopt) → {this}
Dispatch a signal
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
any |
<optional> <repeatable> |
Arguments to dispatch |
Returns:
- Type
- this
getDispatchNb() → {number}
Get the number of dispatch
Returns:
Dispatch number
- Type
- number
getListenersNb() → {number}
Get the number of listeners
Returns:
Listeners number
- Type
- number
has(cb, contextopt) → {boolean}
Check if a listener exists
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
cb |
listenerCallback | Callback |
||
context |
any |
<optional> |
this | Context specified when the listener was added |
Returns:
True if the listener exists, false otherwise
- Type
- boolean
once(cb, optionsopt) → {this}
Add a listener once
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cb |
listenerCallback | Callback |
||||||||||||||||
options |
Object |
<optional> |
Options Properties
|
Returns:
- Type
- this
remove(cb, contextopt) → {this}
Remove a listener
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
cb |
listenerCallback | Callback |
||
context |
any |
<optional> |
this | Context specified when the listener was added |
Throws:
-
First argument must be a Function
- Type
- TypeError
Returns:
- Type
- this
removeAll() → {this}
Remove all listeners
Returns:
- Type
- this
Type Definitions
listenerCallback(…args)
Callback called when a signal is dispatched
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
args |
<repeatable> |
Arguments dispatched |