Event Listeners
Direct communication channels are constructed by explicitly chaining together functions and/or DOM events so that when one executes, another is automatically invoked afterward. For example, each time an object changes via a "setter" method, you may want to automatically trigger a change in the application's visual interface. Or, perhaps each time one object changes, you might want to automatically update a derived property on another object. The possibilities are endless.
The two primary methods involved in a direct communication
scheme are dojo.connect and
dojo.disconnect. In short, you use
dojo.connect to chain together a
series of events. Each call to dojo.connect returns a handle that you
should keep and explicitly pass to dojo.disconnect whenever you are ready to
dispose of the connection. Conveniently, all handles are disconnected
automatically when the page unloads, but manual management of the
handles may be necessary for preventing memory leaks in long-running
applications that invoke a lot of connections that are used
temporarily. (This is particularly the case on IE.) Coming up is the
API that was introduced in Chapter 1.
Warning
Don't ever connect anything until after the page is loaded.
Trying to use dojo.connect before the page is loaded is a very common mistake and can cause you to sink a lot of time into trying to debug something that isn't very easy to track down the first time you run into it. You should always set up your connections within the function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access