[dojo-contributors] Module formats for the browser

Rawld Gill rcgill at earthlink.net
Tue May 4 06:18:26 EDT 2010


James and I have been discussing our loaders off and on in this thread for a
few months. This message gives further details on my loader proposal.

My goals are:

1. make dojo compatible with a script-inject loader.
2. make dojo.js more concise, smaller, easier to understand, and more
configurable.

To that end, I've been building new loaders and playing with the bootstrap
for the last 8 months as part of a major project I'm about to launch. I am
offering the dojo-related parts of this work for inclusion in dojo. There
are still a few loose ends--I was hoping to postpone this discussion until
1.5 is out--but I know some of you want to see what I've talked about on the
list. So....

I've put together a *preliminary* version of dojo with the loader I've
discussed. It is open for public review at
http://github.com/rcgill/dojo-1-5. I've tried to be careful in the git repo
contents so that you can easily understand the migration path I am
proposing. If you look at the commit log
(http://github.com/rcgill/dojo-1-5/commits/master ) you'll see there are
three commits of substance.

Step1: dojo, dijit, util at svn v22052

Step2: dojo and dijit modules all converted to the script-inject module
format by a program. Additionally, dojo/_base/_loader/loader.js was modified
to work with the converted modules. Notice that with about 20 lines of new
code in the loader, dojo works correctly with the new module format. This
allows both the current loader and a script-inject loader to co-exist with
the same code stack. This idea should help with the transition. 

Step3: add the backdraft (my) script-inject loader. This loader also
replaces the dojo bootstrap (since the bootstrap is tightly wound with the
current dojo loaders), so there are really two changes (new loader and new
bootstrap) that are made concurrently.

The loader is found in /dojo/dojo-ng.js. My goal with this code was the
absolutely smallest, easiest-to-understand, full-featured loader possible
without any cruft. I am pleased with the results. It comes in at 2.1K
closure-compiled and zipped (7.16 white space removed and no zip). I've
commented it as if I'm talking to this list; you shouldn't have any trouble
understanding it (it's less than 400 lines sans comments).

I made a few design decisions that may generate disagreement:

1. I didn't implement module modifiers as with requireJS: In the end, I
didn't find them compelling enough to include. If required, I think they
should be added as a plugin.

2. I didn't include multi-version support out of the box. For those who need
it (I believe a *very* small minority), I think this feature should be added
as a plugin. I've got one, but it's not finished.

3. The configuration cannot be passed as an object (like requireJS). You
configure by defining dojo.config before loading the loader.

4. Mapping from module name to URL is quite a bit more powerful. See the
function "url" in dojo-ng.js. This new machinery allows you to decouple the
layout of resources on the disk from the namespace organization in a much
more flexible way than module paths.

Other than that, the API is compatible with requireJS; although I haven't
kept up with James recently so there may be a couple of corners that don't
quite match.

I'm quite happy with the loader. I believe it is very concise, powerful, and
yet easy to understand and make it do different tricks. I'm sure you'll all
tell me if you disagree :)

In order to get the new loader to work with dojo, a few minor changes were
needed. See
http://github.com/rcgill/dojo-1-5/commit/040a49d2c4f624710e8891d07f89f02e4ef
a0b57 for details. Notice that, other than the bootstrap, only 39 lines were
changed over 4 files!

Since the bootstrap is really another topic, I'll start another thread on
that in a day or two.

Best,
Rawld



> -----Original Message-----
> From: dojo-contributors-bounces at mail.dojotoolkit.org [mailto:dojo-
> contributors-bounces at mail.dojotoolkit.org] On Behalf Of James Burke
> Sent: Wednesday, April 28, 2010 11:06 PM
> To: dojo dev.
> Subject: Re: [dojo-contributors] Module formats for the browser
> 
> On Wed, Apr 28, 2010 at 7:44 AM, Kris Zyp <kzyp at dojotoolkit.org> wrote:
> > I've played around with this some, and it seems awesome. What needs to
> > be done to move forward with creating a more reliable/official
> > distribution of RequireJS-based Dojo?
> 
> There are some things that could be done better with the conversion done
> today:
> - dojo.moduleUrl could be converted to require.nameToUrl() calls
> - requireIf is not handled correctly, maybe I will just manually code up a
> change in dojo.gfx to get around this.
> 
> I am happy to put out a converted release, but I think I will wait for the
Dojo
> 1.5 release. Hopefully I can get the above two things resolved by then.
> 
> I can host the converted release on the RequireJS site, so that it is not
> confused with an official indication of where Dojo is going. That might
give
> Rawld enough time to bring his code out for more people to examine.
> 
> James
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at mail.dojotoolkit.org
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-contributors
> 
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5070 (20100428) __________
> 
> The message was checked by ESET NOD32 Antivirus.
> 
> http://www.eset.com
> 




More information about the dojo-contributors mailing list