[dojo-contributors] Module formats for the browser

Kris Zyp kzyp at dojotoolkit.org
Fri Mar 26 12:29:40 EDT 2010



On 3/26/2010 9:56 AM, Eugene Lazutkin wrote:
> I think everybody is in agreement that we want to have interoperability
> with XXX library as a separate plugin somewhere in DojoX. Obviously XXX
> can be CommonJS too. (I assume that there is a wealth of modules in this
> format that our users want to use --- I didn't really check.)
>
> Regarding RequireJS --- it is not backward compatible with what we have,
> so until this situation changes it cannot be introduced before 2.0.

In my proposed migration path, I suggested adding RequireJS and
retaining dojo.require support for 1.x. How does that break backwards
compatibility? Perhaps I should have explicitly stated that as a
corrolary to keeping dojo.require that we also need to retain our global
namespaces. I think we could move to defining modules with something
like this for 1.x:

require.def("dijit/Tooltip", ["dijit/_Widget"], function(_Widget){
  return dojo.declare("dijit.Tooltip", [_Widget], {
    ...
  }
});

And then you can do:

require.async("dijit/Tooltip", function(Tooltip){
  dijit.Tooltip == Tooltip // is true
});

or:
dojo.require("dijit.Tooltip");
dijit.Tooltip -> // works like it always has

And in 2.0 we could move to:
require.def("dijit/Tooltip", ["dijit/_Widget"], function(_Widget){
  // perhaps always retain the dojo.* namespace:
  return dojo.declare([_Widget], { // anonymous declaration
    ...
  }
});

require.async("dijit/Tooltip", function(Tooltip){
  // Must use Tooltip variable
});

Kris




More information about the dojo-contributors mailing list