Publisher, widget A: |
Assume widget A is a publisher
to the topic
'fooTopic'. If widget A decides to publish to the
topic, then widget A makes the API call, dojo.publish("fooTopic",
[{ source: this, message: "foo"}]); That API
call
tells the Dojo Toolkit to publish a JavaScript
object that contains an attribute named source, which is a reference to
the posting widget, and an attribute named message, with the string
value of foo, to a
topic named fooTopic.
You do not need an attribute named source, nor an attribute named message. The item posted to the topic can be any type of JavaScript object, atomic or a complex object, which is a collection of attributes. |
Consumer, widget B: |
Assume widget B is a consumer of
messages from fooTopic.
Widget B needs to register the method on its object that acts as the
callback
handler. For example, widget B
wants its function, _gotMessage
called whenever
a message is published to the topic, fooTopic. Widget B
must initiate the following API call in its postCreate Dojo API function: dojo.subscribe("fooTopic",
this, "_gotMessage");
After that call is made, widget
B listens for messages on the named topic. Now, when a
message is published to fooTopic
the method, _gotMessage,
is run for widget B. |