Question

I am trying to raise an event to all of the widgets that catch it. I have an authentication widget and other widgets that depend on the fact that the user is logged in. I would like to raise an event to all of those widgets when a user is logged in without connecting them manually. How can it be done?

Was it helpful?

Solution

Try dojo.publish and dojo.subscribe

Perhaps this is a better link

OTHER TIPS

Here's some more detailed and up-to-date links on pub/sub in Dojo:

Blog posts
http://davidwalsh.name/dojo-pub-sub
http://startdojo.com/2010/05/21/decoupling-widget-to-widget-interaction-with-dojo/
http://www.naelshawwa.com/dojo-how-to-publish-subscribe-2/

Docs
http://dojotoolkit.org/reference-guide/dojo/publish.html
http://dojotoolkit.org/reference-guide/dojo/subscribe.html
http://dojotoolkit.org/reference-guide/quickstart/events.html (particularly the last section)

Once your javascript web app gets at all complicated, pub/sub is a godsend, allowing you to decouple your classes, and so make your code more maintainable and modular.

dojo.subscribe("mytopic",console,"debug");
dojo.publish("mytopic",["whatever"]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top