]>
Commit | Line | Data |
---|---|---|
1354d172 AD |
1 | define("dojo/topic", ["./Evented"], function(Evented){ |
2 | // summary: | |
3 | // The export of this module is a pubsub hub | |
4 | // You can also use listen function itself as a pub/sub hub: | |
5 | // | topic.subscribe("some/topic", function(event){ | |
6 | // | ... do something with event | |
7 | // | }); | |
8 | // | topic.publish("some/topic", {name:"some event", ...}); | |
9 | ||
10 | var hub = new Evented; | |
11 | return { | |
12 | publish: function(topic, event){ | |
13 | // summary: | |
14 | // Publishes a message to a topic on the pub/sub hub. All arguments after | |
15 | // the first will be passed to the subscribers, so any number of arguments | |
16 | // can be provided (not just event). | |
17 | // topic: String | |
18 | // The name of the topic to publish to | |
19 | // event: Object | |
20 | // An event to distribute to the topic listeners | |
21 | return hub.emit.apply(hub, arguments); | |
22 | }, | |
23 | subscribe: function(topic, listener){ | |
24 | // summary: | |
25 | // Subcribes to a topic on the pub/sub hub | |
26 | // topic: String | |
27 | // The topic to subscribe to | |
28 | // listener: Function | |
29 | // A function to call when a message is published to the given topic | |
30 | return hub.on.apply(hub, arguments); | |
31 | } | |
32 | } | |
33 | }); |