0
votes

I was just wondering and it is just a general question that was Tickling my brain. Dojo 1.7 an above uses the AMD module which is a great way of calling widgets and helping classes.

The question the normal way to call classes or AMD modules with call back looks like below:

require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/dom', 'dojo/domReady!'],
    function(lang, DataGrid, ItemFileWriteStore, dom){

in this way i am calling the lang, DataGrid and ItemFileWriteStore module with a call back in the function to use these modules, some of the modules doesn't have a callback such as dojo/domReady!.

So is there a difference or would it cause an error in the sequence of calling the modules ? or the important part is to have them on the same sequence in the require and the function. but it doesn't matter which to call first ?

2

2 Answers

2
votes

I'm not sure what you're asking. But the parameters in the function should be in the same order/sequence as the module names you import (like in the given example).

If the module doesn't return an object (like domReady), you are recommended to put it as the last modules, since most of them still return something (like a HTML document or a function or something).

You can of course add them wherever you want, but if you would switch dojo/dom and dojo/domReady!, it would mean that the variable dom will no longer contain the code for dojo/dom but for the other module (no object). This would mean that you had to do something like:

require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/domReady!', 'dojo/dom'],
    function(lang, DataGrid, ItemFileWriteStore, placeholder, dom){

Where placeholder has no real use.

0
votes

I think you might be misunderstanding something, or maybe I am misunderstanding what you're saying.

the define() function takes two parameters:

  • An array of module names that are dependencies
  • A callback function that needs those dependencies

The module or module names themselves are not callbacks, the callback is the function you've written and is fired when all the modules have been loaded.

As Demitri M says, it makes sense to put modules that return no value (because they do something else) at the end of your callback function, because that way you could shorten your parameter list.