Signal

Signal

Signal class

Constructor

new Signal()

Creates an instance of Signal

Author:
License:
Source:
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
Name Type Attributes Default Description
priority string <optional>
0

Higher priority listener will be called earlier

once string <optional>
false

Listener called once

context any <optional>
this

Bind the listener with a specific context

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

Source:
Returns:
Type
this

getDispatchNb() → {number}

Get the number of dispatch

Source:
Returns:

Dispatch number

Type
number

getListenersNb() → {number}

Get the number of listeners

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

Source:
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
Name Type Attributes Default Description
priority string <optional>
0

Higher priority listener will be called earlier

context any <optional>
this

Bind the listener with a specific context

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

Source:
Throws:

First argument must be a Function

Type
TypeError
Returns:
Type
this

removeAll() → {this}

Remove all listeners

Source:
Returns:
Type
this

Type Definitions

listenerCallback(…args)

Callback called when a signal is dispatched

Parameters:
Name Type Attributes Description
args args <repeatable>

Arguments dispatched

Source: