[dojo-contributors] self executing scripts

Peter E Higgins dante at dojotoolkit.org
Sun May 31 11:22:21 EDT 2009


Mike Wilcox wrote:
> I think it's great. I had tried formatting my code this way early
> on, and saw that it didn't work. I like that you have a "dojo
> block" of code.
>
> It spawns a few other ideas:
>
> Useful if you only had one or two "main" require scripts: <script
> src="dojo.js" djConfig="parseOnLoad=true" require="my.application"
> />
>
you can already put require:[] in djConfig, so we've got that covered
already. The self-closing script tag sill likely never be capable of
support, the browsers don't like them.

> May be slower to load (requiring two passes with the parser maybe)
> but I bet newbies would like it: <script src="dojo.js"
> djConfig="parseOnLoad=true" autoRequire="true" />
>
This would be cool, but as you state slow. It would probably be best
as a djConfig param, too. Perhaps there could be a post-dojo.js
bootstrap/plugin hook (like the magic i18n and parser do with the
addOnLoad stack) to where you could register functionality like this.

dojo.config.autoRequire && dojo._hackInOnload(0, function(){
    dojo.query("[dojoType]").map(function(n){ return
d.attr(n,"dojoType"); }).forEach(dojo.require, dojo);
});

then:
djConfig = { autoRequire: true };

This would _almost_ work as the classes used as dojoType's are 1:1
these days, but hard to support for custom namespaces as many people
don't follow that "rule" in personal code. But having a hook to where
you could register your own "magic" [officially] like that would allow
anyone to implement such a thing without touching base code (the
self-executing scripts too, fwiw, but I like the clenliness of _not_
having to specify a djConfig to enable to functionality)

Regards,
Peter

-- 
Peter E Higgins
Dojo Project Lead : http://dojotoolkit.org



More information about the dojo-contributors mailing list