Channel

Channel

Provides a convenient way to listen for and emit messags on a Bus channel.
Channel objects provide versions of the Bus addListener, removeListener, and
emit functions that don't require the channel to be specified.

Constructor

new Channel(bus, channelName)

Initialize a Channel object.

Parameters:
Name Type Description
bus Bus

The bus associated with the channel.

channelName string

The channel name.

See:
  • Bus.makeChannel

Methods

addListener(callback, retrieveLatestEmit)

Adds a callback function to the channel.

Parameters:
Name Type Default Description
callback function

A function that is called when emit is
called for the channel.

retrieveLatestEmit boolean false

If true, the callback function is
immediately called with the last emitted value for which storeEmit was
true.

emit(data, storeEmit)

Calls all the callback functions that have been added to the channel.

Parameters:
Name Type Default Description
data *

A value passed to the callback functions.

storeEmit boolean false

If true, data is saved and passed to callback
functions added with retreiveLastedEmit set to true.

removeListener(callback)

Removes a callback function from the channel.

Parameters:
Name Type Description
callback function

The function to remove.