You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
define("dojo/topic", ["./Evented"], function(Evented){
|
|
|
|
// module:
|
|
// dojo/topic
|
|
|
|
var hub = new Evented;
|
|
return {
|
|
// summary:
|
|
// Pubsub hub.
|
|
// example:
|
|
// | topic.subscribe("some/topic", function(event){
|
|
// | ... do something with event
|
|
// | });
|
|
// | topic.publish("some/topic", {name:"some event", ...});
|
|
|
|
publish: function(topic, event){
|
|
// summary:
|
|
// Publishes a message to a topic on the pub/sub hub. All arguments after
|
|
// the first will be passed to the subscribers, so any number of arguments
|
|
// can be provided (not just event).
|
|
// topic: String
|
|
// The name of the topic to publish to
|
|
// event: Object
|
|
// An event to distribute to the topic listeners
|
|
return hub.emit.apply(hub, arguments);
|
|
},
|
|
|
|
subscribe: function(topic, listener){
|
|
// summary:
|
|
// Subscribes to a topic on the pub/sub hub
|
|
// topic: String
|
|
// The topic to subscribe to
|
|
// listener: Function
|
|
// A function to call when a message is published to the given topic
|
|
return hub.on.apply(hub, arguments);
|
|
}
|
|
};
|
|
});
|