[Cosmo-dev] Dojo 0.4.3 and circular dojo.requires

Travis Vachon travis at osafoundation.org
Tue Oct 16 16:50:20 PDT 2007


Hi folks

We've recently tried to upgrade from 0.4.1 to 0.4.3 but ran into some  
problems related to changes in the Dojo build system. We'd like to  
follow up on this experience by attempting to clarify best practices  
for 0.4.3 builds.

Our application is large enough that we are utilizing the custom  
namespace functionality as follows:

dojo.registerNamespaceManifest("cosmo", "../../cosmo", "cosmo",  
"cosmo.ui.widget",null)

where our directory structure looks like:

js -
      |- cosmo - <our javascript>
      |- lib-
	      |- dojo -
                            |- dojo.js



Unfortunately, a number of circular require dependencies have worked  
their way into the codebase over time. For example:

cosmo/app/pim.js:
...
dojo.require('cosmo.app.pim.layout');
...

cosmo/app/pim/layout.js:
...
dojo.require('cosmo.view.cal.canvas');
...

cosmo/view/cal/canvas.js:
...
dojo.require('cosmo.ui.event.handlers');
...

cosmo/ui/event/handlers.js:
...
dojo.require('cosmo.app.pim');
...


In all cases the requires are being used at the top of the script  
immediately below the appropriate dojo.provide. In most cases,  
however, the module they reference is not used during the loading of  
the script, but is required for a library function provided within.

The Dojo 0.4.1 build system strips out dojo.requires for files it  
includes in the monolithic dojo.js file it creates. This means that  
the circular dependencies described above are hidden without causing  
errors, since by the time the library functions are used the  
appropriate modules have indeed been loaded.

In the 0.4.3 build system, however, these requires are not being  
stripped. This is causing problems when dojo.js loads because  
dojo.require("cosmo.app.pim") has been packed into the built dojo.js  
file before dojo.provide("cosmo.app.pim"). These problems are  
actually errors because we have not yet used  
registerNamespaceManifest to specify the location of "cosmo" code and  
as a result dojo makes requests to the wrong location on the server.


Our questions are as follows:

1) Are we using any of this infrastructure in glaringly incorrect ways?

2) What is considered best practice regarding circular dependencies?  
Are they simply unacceptable within the constraints of the Dojo build  
system (that is, will the build system ever support them?)

3) Is there a way to re-enabled the stripping of dojo.requires in 0.4.3?


I've included our build profile at the bottom of this email in case  
it will help. Please do not hesitate to ask for any more information  
that would be useful.

Thank you very much for your time!

-Travis Vachon
Open Source Applications Foundation
http://svn.osafoundation.org/server/cosmo





cosmo.profile.js:

var dependencies = [
     "cosmo.app",
     "cosmo.app.pim",
     "cosmo.ui.global_css",
     "cosmo.ui.event.listeners",
     "dojo.debug.console",
     "dojo.logging.ConsoleLogger",
     "dojo.logging.Logger",
     "cosmo.ui.widget.Debug",
     "cosmo.datetime.timezone.LazyCachingTimezoneRegistry"
];

dependencies.prefixes = [
    ["cosmo", "../../cosmo/src/main/webapp/js/cosmo"]
];

load("getDependencyList.js");







More information about the cosmo-dev mailing list