new Publisher()
- Source:
Members
handlerInvoker :function
adapt the parameters to the handlers function signature
Type:
- function
- Source:
Example
// the new handler function receives the event's payload
// in it's single argument
var mySubscriber = function( data ){
console.log( data );
};
// create a publisher using the factory method
var publisher = createPublisher({
handlerInvoker: function(handler, message, payload){
handler(payload);
}
});
// register the handler
var subscription = publisher.subscribe( 'topic', mySubscriber );
publisher.publish( 'topic', 'hello world!' );
// logs 'hello world!' to the console
Methods
publish(message, data) → {boolean}
Publishes the the message, passing the data to it's subscribers
Parameters:
Name | Type | Description |
---|---|---|
message |
String | The message to publish |
data |
* | The data to pass to subscribers |
- Source:
Returns:
- Type
- boolean
publishSync(message, data) → {boolean}
Publishes the the message synchronously, passing the data to it's subscribers
Parameters:
Name | Type | Description |
---|---|---|
message |
String | The message to publish |
data |
* | The data to pass to subscribers |
- Source:
Returns:
- Type
- boolean
subscribe(message, callback) → {Object}
Subscribes the passed function to the passed message.
Parameters:
Name | Type | Description |
---|---|---|
message |
String | The message to subscribe to |
callback |
module:lib/pubsub~Publisher~eventCallback | The function to call when a new message is published |
- Source:
Returns:
a subscription object with a single method dispose
you need to call to unsubscribe
- Type
- Object
unsubscribeAll()
remove all references to the subscribers. Is useful if the publisher is destroyed.
- Source:
Type Definitions
eventCallback(message, dataopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
string | the topic | |
data |
* |
<optional> |
the payload |
- Source: