Class: core/Messenger

core/Messenger(idopt)

Class that can execute functions when local messages are received. Local messages
are prefixed with the instance's id.

Constructor

new core/Messenger(idopt)

Parameters:
Name Type Attributes Description
id any <optional>

Id for the object. If none is provided a new id will
be created. Id should be able to be represented as a string.

Properties:
Name Type Description
GlobalMessenger core/Messenger

A messenger that can be used for
global messaging. When using static listen and emit methods they are executed
on this messenger.

EVENTS Object

Built-in events that the Messenger emits.

Members

(readonly) id :string

Gets the string id of the object.

Type:
  • string

Methods

(static) emit(message, valueopt)

Send a message, causing listener functions for the message on the global Messenger
instance to be executed.

Parameters:
Name Type Attributes Description
message string

The message to emit.

value any <optional>

Optional argument to pass to listener callbacks.

(static) listenTo(message, callback)

Execute a function when a message is received for the global Messenger instance.

Parameters:
Name Type Description
message string

The message to listen for.

callback function

Function to execute once the message is received.

(static) stopListening(message, callbackopt)

Prevent a function from being executed when a message is received for the
global Messenger instance.

Parameters:
Name Type Attributes Description
message string

The message to stop listening for.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for the message.

(static) stopListeningByRegexp(regexp, callbackopt)

De-register callback(s) from being executed on the global messengerr instance
when messages matching the given regular expression are received.

Parameters:
Name Type Attributes Description
regexp Regexp

regexp - The regular expression to filter messages with.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for messages matching the regular expression.

(static) stopListeningToAll()

Prevent any functions from being executed when any message is received for
the global Messenger instance.

emit(message, valueopt)

Send a message, causing listener functions for the message on this object
to be executed.

Parameters:
Name Type Attributes Description
message string

The message to emit.

value any <optional>

Optional argument to pass to listener callbacks.

listenTo(message, callback)

Execute a function when a message is received for this object.

Parameters:
Name Type Description
message string

The message to listen for.

callback function

Function to execute once the message is received.

stopListening(message, callbackopt)

Prevent a function from being executed when a message is received for this
object.

Parameters:
Name Type Attributes Description
message string

The message to stop listening for.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for the message.

stopListeningByRegexp(regexp, callbackopt)

De-register callback(s) from being executed when messages matching the given
regular expression are received.

Parameters:
Name Type Attributes Description
regexp Regexp

regexp - The regular expression to filter messages with.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for messages matching the regular expression.

stopListeningToAll()

Prevent any functions from being executed when any message is received for
this object.