ben hockey wrote:On 7/13/2011 1:11 PM, Bryan Forbes wrote:
My initial reason for wanting to email the list about this was the
NodeList extensions requiring "./main" instead of using granular
dependencies. This isn't a big problem for something like NodeList-fx,
but NodeList-traverse doesn't need "./_base/fx" brought in from
"./main" to operate. I hesitate to propose this, but perhaps we should
stick to the rule that most, if not all, modules in dojo (the
directory, not the toolkit) should refrain from requiring "./main". If
I remember right, DojoX has this rule. -Bryan
+1 we (rawld and i) discussed this before
(http://permalink.gmane.org/gmane.comp.web.dojo.devel/15231). there's
likely no need for any library code to reference main directly. its
more of a convenience for client code. i have no objection to this rule
...with a disclaimer that we can make exceptions for exceptional
circumstances (although i don't foresee any).
I don't foresee any either. An argument could be made that the size of
the dependency lists will be larger, but if that is a concern you should
be doing a build which will take care of the dependency list size (and I
hate saying that a build will solve problems). There's also an added
benefit that lookups happen faster on objects with fewer properties on
them which means looking up a function from the `dojo` object will be
slower than the granular module that you can require. For instance:
dojo/someModule.js:
===================
declare(["./main", "./_base/array"], function(dojo, array){
return {
someOftenCalledFunction1: function(arr){
return dojo.map(arr, function(item){
dojo.forEach(item, function(subItem){
// do something really neat here
});
});
},
someOftenCalledFunction2: function(arr){
return array.map(arr, function(item){
array.forEach(item, function(subItem){
// do something really neat here
});
});
}
};
});
`someOftenCalledFunction1` will be slower than
`someOftenCalledFunction2` because it is referencing the array functions
from the `dojo` object rather than the `array` object. How much slower
will depend on how many modules have added properties to the `dojo`
object. Granted, the speed improvements will be on the millisecond
level, but imagine that almost every module of a large application uses
`dojo/someModule` (think dojo.declare). We don't want the toolkit being
the bottleneck of an application.