forked from dojo/dojo-oldmirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
topic.js
33 lines (32 loc) · 1.08 KB
/
topic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
define(["./Evented"], function(Evented){
// summary:
// The export of this module is a pubsub hub
// You can also use listen function itself as a pub/sub hub:
// | topic.subscribe("some/topic", function(event){
// | ... do something with event
// | });
// | topic.publish("some/topic", {name:"some event", ...});
var hub = new Evented;
return {
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);
}
};
});