3

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?

3 Answers 3

4

Try dojo.publish and dojo.subscribe

Perhaps this is a better link

0
2

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.

1
dojo.subscribe("mytopic",console,"debug");
dojo.publish("mytopic",["whatever"]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.