[Dojo-interest] Dojo 1.7 way to do "requires"

Kitson Kelly kitson.kelly at asseverate.co.uk
Tue May 8 10:23:01 EDT 2012


Best to re-order your arguments, so the ones you don't need to expressly
refer are at the end of the arguments.  So I would do require(["pkg/a",
"pkg/d", "pkg/b", "pkg/c"], function(a, d){});

Another coding style that some people prefer is to include all the modules
in the require and then do a non-array require when you need a reference to
the module.  Like:

require(["pkg/a", "pkg/b", "pkg/c"], function(){
  // ...
  var a = require("pkg/a");
  // ..
  var b = require("pkg/b");
  // ..
  var c = require("pkg/c");
});


Personally, I don't like this style, but some people like it because it
might avoid a level of confusion in large code blocks.

Also, don't forget you can nest require callbacks, so you don't have to
load everything at once, just need to get your mind over async/callback
structure to code.

On 8 May 2012 07:11, Rags <dojo at ragnorok.net> wrote:

> **
> I've seen numerous code 1.7.x snippets where every single niggly little
> module that ever *may* be needed is in the require, so there are twenty or
> more of the darned things, but when one gets to the "callback", only three
> lines are present and maybe one or two modules actually employed.  Is this
> normal?
>
> If it is normal, may one skip the unnecessary ones like so:
>
>  require(["pkg/a", "pkg/b", "pkg/c", "pkg/d"], function(a,,, d){
>   // ...
> });
>
>
>  Note the empty parms in the list.  I'm thinking the answer is "no", but
> it never hurts to ask.
>
> Thanks for your time...
>
> - Rags
>
>
> On 5/8/2012 9:21 AM, Kitson Kelly wrote:
>
> Not if they aren't being used directly in the callback, and the provided
> code doesn't use them directly.  The parser in 1.7 will resolve declarative
> markup based on looking up the dot notation in the global scope.  The 1.8
> parser has few new ways of dealing with it, but still doesn't require
> passing of the modules in the callback that aren't expressly used.
>
>  The only thing that I have seen people make a mistake about is
> forgetting that JavaScript can't figure out missing arguments and do
> something like this:
>
> require(["pkg/a", "pkg/b", "pkg/c", "pkg/d"], function(a, d){
>   // ...
> });
>
>
>  Thinking they are going to get pkg/a and pkg/d somehow, but are getting
> pkg/a and pkg/b.
>
>
> On 7 May 2012 12:37, Jared Jurkiewicz <jared.jurkiewicz at gmail.com> wrote:
>
>> In AMD mode, yes.
>>
>> -- Jared
>>
>> On Mon, May 7, 2012 at 3:10 PM, stackyStack <stackystack77 at gmail.com>
>> wrote:
>> > Hell fbCarter, Thanks for the reply. Is it must to pass loaded
>> components in
>> > callback function?
>> >
>>
>
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
>
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
> Dojo-interest at mail.dojotoolkit.orghttp://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
>
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
>
> Dojo-interest at mail.dojotoolkit.org
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-interest/attachments/20120508/a8b0ac92/attachment.htm 


More information about the Dojo-interest mailing list