Friday, May 19, 2006

Connect once to a Dojo Topic

Scenario: a script that is loaded/evaluated inside a ContentPane needs to subscribe to a topic that is publishing URLs, receive exactly one URL, and then reload the pane. Option 1. Look up the topic and connectOnce to its "sendMessage" method. (Note: scripts evaluated inside a ContentPane use the "_container_" variable to access it).
  dojo.event.connectOnce(dojo.event.topic.getTopic("treeurl"), "sendMessage",
                         _container_, "setUrl");
Option 2. Use kwConnect with once:true.
    once: true,
    srcObj: dojo.event.topic.getTopic("treeurl"),
    srcFunc: "sendMessage",
    adviceObj: _container_,
    adviceFunc: "setUrl"
Tested with Dojo 0.3 release.