jQuery.telligent.evolution.messaging
This module provides a simple, generic publish/subscribe message bus for client code to use to communicate within the current document, or across documents in separate windows or tabs. This enables easy cross-widget communication without relying on expectation of specifc DOM elements or events. Additionally, the platform uses messages for coordinating synchronization between separate UI components related to the same piece of content.
Methods
subscribe
Subscribes to a message, and returns a subscription handle.
var subscriptionId = $.telligent.evolution.messaging.subscribe(messageName, function(data) {
// handle message
});
var subscriptionId = $.telligent.evolution.messaging.subscribe(messageName, namespace, function(data) {
// handle message
});
messageName
: message to subscribe tonamespace
: optional namespace string or array of namespace strings to allow clearing one or many multiple handlers later without having subscription handleshandler
: message handler
publish
Publishes a message. All current subscriptions will be called and passed the data
.
// Publish a message
$.telligent.evolution.messaging.publish(messageName, data);
// Optionally publish a message that will received by handlers on other windows or tabs
$.telligent.evolution.messaging.publish(messageName, data, { crossWindow: true });
unsubscribe
Unsubcribes a specific message handler by subscription handle or one or multiple subscriptions by namespace
$.telligent.evolution.messaging.unsubscribe(subscriptionId);
$.telligent.evolution.messaging.unsubscribe(namespace);
suppress
Suppresses, but leaves bound, a specific message handler by subscription handle or one or multiple subscriptions by namespace
$.telligent.evolution.messaging.suppress(subscriptionId);
$.telligent.evolution.messaging.suppress(namespace);
unsuppress
Un-suppresses a specific message handler by subscription handle or one or multiple subscriptions by namespace
$.telligent.evolution.messaging.unsuppress(subscriptionId);
$.telligent.evolution.messaging.unsuppress(namespace);
Automatic Message Links
Anchors which define the attribute, data-messagename
raise a message named according to the value of the attribute when clicked without the need for explicitly binding. Message links' binding is delegated to support links being added or modified dynamically.
// Register a message link on an anchor
<a href="#" data-messagename="action.occurred">My Link</a>
// handle the message
$.telligent.evolution.messaging.subscribe('action.occurred', function(data) {
// handle the message
// data.target is the link which raised the message
});