Home Reference Source Test
import Bus from 'runtime-core/src/bus/Bus.js'
public class | source

Bus

Direct Subclass:

MessageBus, MiniBus

Indirect Subclass:

Sandbox

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

addListener(url: URL, listener: Listener): MsgListener

Register listener to receive message when "msg.to === url".

public

addResponseListener(url: URL, msgId: number, responseListener: Function)

Manually add a response listener.

public

bind(outUrl: URL, inUrl: URL, target: MiniBus): Bound

Helper method to bind listeners (in both directions) into other MiniBus target.

public

postMessage(msg: Message, responseCallback: Function): number

Send messages to local listeners, or if not exists to external listeners.

public

Remove all existent listeners for the URL

public

removeResponseListener(url: URL, msgId: number)

Remove the response listener.

Public Constructors

public constructor() source

Public Methods

public addListener(url: URL, listener: Listener): MsgListener source

Register listener to receive message when "msg.to === url". Special url "*" for default listener is accepted to intercept all messages.

Params:

NameTypeAttributeDescription
url URL

Address to intercept, tha is in the message "to"

listener Listener

listener

Return:

MsgListener

instance of MsgListener

public addResponseListener(url: URL, msgId: number, responseListener: Function) source

Manually add a response listener. Only one listener per message ID should exist. ATENTION, there is no timeout for this listener. The listener should be removed with a removeResponseListener, failing to do this will result in a unreleased memory problem.

Params:

NameTypeAttributeDescription
url URL

Origin address of the message sent, "msg.from".

msgId number

Message ID that is returned from the postMessage.

responseListener Function

Callback function for the response

public bind(outUrl: URL, inUrl: URL, target: MiniBus): Bound source

Helper method to bind listeners (in both directions) into other MiniBus target.

Params:

NameTypeAttributeDescription
outUrl URL

Outbound URL, register listener for url in direction "this -> target"

inUrl URL

Inbound URL, register listener for url in direction "target -> this"

target MiniBus

The other target MiniBus

Return:

Bound

an object that contains the properties [thisListener, targetListener] and the unbind method.

public postMessage(msg: Message, responseCallback: Function): number source

Send messages to local listeners, or if not exists to external listeners. It's has an optional mechanism for automatic management of response handlers. The response handler will be unregistered after receiving the response, or after response timeout (default to 3s).

Params:

NameTypeAttributeDescription
msg Message

Message to send. Message ID is automatically added to the message.

responseCallback Function

Optional parameter, if the developer what's automatic response management.

Return:

number

Returns the message ID, in case it should be needed for manual management of the response handler.

public removeAllListenersOf(url: URL) source

Remove all existent listeners for the URL

Params:

NameTypeAttributeDescription
url URL

Address registered

public removeResponseListener(url: URL, msgId: number) source

Remove the response listener.

Params:

NameTypeAttributeDescription
url URL

Origin address of the message sent, "msg.from".

msgId number

Message ID that is returned from the postMessage