Last change
on this file since 274 was
256,
checked in by hendrikvanantwerpen, 13 years ago
|
Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).
|
File size:
1.1 KB
|
Line | |
---|
1 | define(["./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 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.