[dojo-contributors] Dojo 1.7 Goals: has() and granular dependency lists

ben hockey neonstalwart at gmail.com
Fri Mar 11 11:16:36 EST 2011

On 3/11/2011 10:38 AM, Kris Zyp wrote:
> On 3/11/2011 8:28 AM, ben hockey wrote:
>>> Second, as our AMD support will be improved in 1.7, we should start
>>> using more precise dependency lists to facilitate highly optimized
>>> builds (only what is needed) and fewer runtime property lookups:
>>> http://bugs.dojotoolkit.org/ticket/12432
>> in the example in the ticket, does dojo/_base/connect still augment dojo
>> so that the first snippet would still work?  if so, then is there any
>> gain by being more precise with the dependencies since
>> dojo/_base/connect will need to declare a dependency on dojo in order to
>> augment it?
> I thought our (back-compat) module loader augmented the dojo variable
> with module returns (line #884 in dojo/_base/_loader/loader.js), so you
> don't have to depend on the "dojo" module to have dojo be augmented.
> However, when module names don't match corresponding created
> functions/namespaces (dojo/_base/connect  != dojo.connect) there is an
> issue. Perhaps we need a dependency that just represents the dojo
> namespace (and not base)?
> Kris
dojo/lib/kernel is the dependency that is the namespace without base.  
dojo/lib/main-browser is the dependency that represents dojo base.  so 
to answer my own question, dojo/_base/connect can/does augment the dojo 
namespace without bringing in all of base.  from dojo/_base/connect.js:
define("dojo/_base/connect", ["dojo/lib/kernel", "dojo/_base/lang"], 
     // ...
     dojo.connect = ...
     // ...
     return dojo.connect;

so then there should be a gain in being more precise with the 
dependencies with the caveat being that the end user will need to do the 
same and use dojo/lib/kernel as their entry point rather than 
dojo/lib/main-browser if they want to take advantage of this.  so now we 
have kernel, base and core :)

one thing to note is because dojo/_base/connect contains more than just 
dojo.connect (dojo.disconnect, dojo.publish, dojo.subscribe, ...) but 
only returns dojo.connect, i think the general pattern will need to be

define(['dojo/lib/kernel', 'dojo/_base/connect', ...], function (dojo) {

declare kernel as a dependency so that you have a handle to the dojo 
namespace and then include all the dependencies you need for augmenting 
the namespace but don't reference their return values in the factory.  
for example, there is no way to reference dojo.subscribe except by the 
dojo namespace.

+1 for precise dependencies.


More information about the dojo-contributors mailing list