Question

After reading tag I've found out many problems that people have with customizing the builds, so I've thought of creating the build myself instead. But I wasn't able to find a reference for syntax used while constructing Dojo AMD layers, namely:

require({cache:{"custom/MyModule":function () {
    define(["dojo/_base/lang"], function (lang) {

It looks like cache is a map where the module name is key, and the value is function which body is my module file content.

But I don't fully understand the lower part:

}, "*now":function (r) {
    r(["dojo/i18n!*preload*custom/nls/all*[\"en\",\"de\",\"ROOT\"]"]);
}}});

This "*now" is also a key, but it seems to have special interprenation. Do I need it in my module? Or it is optional?

define("custom/all", [], 1);

is the last part. As I suppose, it is obligatory to do this define, even if layer module won't be directly referenced anywhere?

Was it helpful?

Solution

After some reverse engineering:

cache object contains map of modules, that are defined in-place. Module name is the key, the value is the function that calls define (so it's the content of module).

*now is a special keyword, it's absolutely not required, but once it is present, the function mapped under that key is executed with function that can be used to call additional require, for example to load the NLS files.

The block

  "*now":function (r) {
     console.log('*now is called with argument: '+r)
  } 

prints:

now is called with argument: function (a1, a2, a3) { return contextRequire(a1, a2, a3, module, result); }

Function contextRequire is defined in dojo.js.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top