Opened 12 years ago

Closed 12 years ago

#4499 closed defect (fixed)

dojo._loadModule function signature incorrect

Reported by: Rawld Gill Owned by: James Burke
Priority: high Milestone: 1.0
Component: Core Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description

The rational for the second argument ("exactOnly") in dojo._loadModule (in /_base/_loader/loader.js) seems to be an artifact of removed functionality. The current comment in the code says (v10423):

_loadModule("A.B") first checks to see if symbol A.B is defined. If it is, it is simply returned (nothing to do).

If it is not defined, it will look for "A/B.js" in the script root directory, followed by "A.js".

But dojo._loadModule never looks for "A.js", thus behaving as if "exactOnly" is always passed as true.

If I am correct, then I recommend the following:

  1. Remove the argument exactOnly from dojo._loadModule.
  1. Change dojo.require:

dojo.require= function(module) {

dojo._loadModule(module);

}

This causes dojo.require to do what it says.

  1. Add the function dojo.load:

dojo.load= function(module) {

dojo._loadModule(module, true);

}

This allows a script to be loaded without implying a module.

Without this change, it is fairly ugly to explain that loading a module without implying a module requires writing:

dojo.require(module, whatever, true);

Finally, if the proposed solution is accepted, for style points, the current "omitModuleCheck" could be renamed to "checkModule" avoiding a negative. Then, we would have

dojo._loadModule(module, checkModule) {

replace "omitModuleCheck" with "!checkModule"

}

dojo.require= function(module) {

dojo._loadModule(module, true);

}

dojo.load= function(module) {

dojo._loadModule(module);

}

Change History (5)

comment:1 Changed 12 years ago by Adam Peller

Owner: changed from anonymous to James Burke

comment:2 Changed 12 years ago by James Burke

Milestone: 1.0

comment:3 Changed 12 years ago by James Burke

(In [11087]) Refs #4499, removing unused exactOnly argument to dojo._loadModule()

comment:4 Changed 12 years ago by James Burke

(In [11088]) Refs #4499, removing unused exactOnly argument to dojo._loadModule()

comment:5 Changed 12 years ago by James Burke

Resolution: fixed
Status: newclosed

I removed the exactOnly argument to dojo._loadModule(): you are right, it was left over from the old 0.4.3 code, but does not apply in 0.9+. Thanks for the catch.

I am leaving omitModuleCheck as-is, since that is the default, majority case for use of dojo._loadModule() (actually seems like the 100% case). I appreciate wanting to avoid the double-negative though. I'm also not sure of the value of the _global_omit_module_check. We can probably remove that, perhaps in 2.0.

I am not comfortable exposing a dojo.load wrapper over dojo._loadModule(). Once we make a public method, there will be more pressure to maintain it, and I'm not sure it is worth the extra code weight (even though it is not huge) and support cost.

It seems like module checking is the norm using Dojo. Also, in ticket #4573, there is some anonymous function wrapping of the module text before evaluating it, so it does not act just like a generic JS code import. Also factor in MSIE and Safari's eval scope issues. I also think it is good to enforce the module checking to help promote constructing module code under a module name, to avoid polluting the global namespace.

If you want just a script import, you can see dojo.io.script.get(). It can be an asynchronous call though, and does not have the dot-notation to path conversion that dojo._loadModule does. It may not be what you want.

I would like to export the dot-notation to path conversion to another function at some point, to help support something like a dojo.requireCss(), but I'll wait until there is a solid plan for it first.

Note: See TracTickets for help on using tickets.