milo-core

MessengerMessageSource

declaration
MessengerMessageSource

Subclass of MessageSource that allows to connect Messenger to another Messenger using it as external source.

var MessengerMessageSource = _.createSubclass(MessageSource, 'MessengerMessageSource');

module.exports = MessengerMessageSource;

MessengerMessageSource instance methods

_.extendProto(MessengerMessageSource, {
    init: init,
    addSourceSubscriber: addSourceSubscriber,
    removeSourceSubscriber: removeSourceSubscriber,
    postMessage: MessengerMessageSource$postMessage
});

init

function
init()

Option name Type Description
sourceMessenger Messenger

messenger this message source connects to

Initializes MessengerMessageSource
Defines one parameter in addition to MessageSource parameters

function init(hostObject, proxyMethods, messengerAPI, sourceMessenger) {
    MessageSource.prototype.init.apply(this, arguments);
    this.sourceMessenger = sourceMessenger;
}

addSourceSubscriber

function
addSourceSubscriber()

Option name Type Description
sourceMessage String,Regex

source message to subscribe to

Subscribes to source message. See MessageSource docs.

function addSourceSubscriber(sourceMessage) {
    this.sourceMessenger.onSync(sourceMessage, { context: this, subscriber: this.dispatchMessage });
}

removeSourceSubscriber

function
removeSourceSubscriber()

Option name Type Description
sourceMessage String,Regex

source message to unsubscribe from

Unsubscribes from source message. See MessageSource docs.

function removeSourceSubscriber(sourceMessage) {
    this.sourceMessenger.off(sourceMessage, { context: this, subscriber: this.dispatchMessage });
}

MessengerMessageSource$postMessage

function
MessengerMessageSource$postMessage()

Option name Type Description
message String
data Object

Overrides defalut message source to dispatch messages synchronously

function MessengerMessageSource$postMessage(message, data) {
    this.messenger.postMessageSync(message, data);
}