[ 13 posts ] Go to page 1, 2 Next

JesterVineo

  • Joined: Fri Mar 02, 2012 7:30 pm
  • Posts: 6
  • Offline
  • Profile

Where to put module dependency requirements

Post Posted: Fri Mar 02, 2012 8:06 pm
+0-
What is the difference between putting your module dependency requirements in your call to YUI.add versus putting them in your call to YUI().use?

Code:
YUI.add('my-module', function(Y) {
    ....
}, 1.2.3, {
    requires: [ 'dep1', 'dep2', ... ] // <-- method 1: put them here
});

var myCfg = {
    groups: {
        mygroup: {
            combine: false,
            base: 'my/base',
            modules: {
                'my-module': {
                    path: 'my/path/mymodule.js',
                    requires: [ 'dep1', 'dep2', ... ] // <-- method 2: put them here
                }
            }
        }
    }
}

YUI(myCfg).use('my-module', function(Y) {
    ...
});


When I do it with method 1, it doesn't seem to load the dependencies. It seems like it should work that way. I prefer that method so that I don't have to put dependency requirements in the config object, and I can just put them in the same javascript file with my module.

What are the differences between these two methods, and what might I be doing wrong that I can't get the first method to work?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile
Tags:

Re: Where to put module dependency requirements

Post Posted: Mon Mar 05, 2012 12:14 pm
+0-
What version of YUI was this tested against? It "should" work both ways, the difference is dynamic versus static loading.

If loader is not present and you statically include it on the page, the the requirements need to be in the add statement.

If loader is present, then either or should work.

JesterVineo

  • Joined: Fri Mar 02, 2012 7:30 pm
  • Posts: 6
  • Offline
  • Profile

Re: Where to put module dependency requirements

Post Posted: Mon Mar 05, 2012 1:31 pm
+0-
Here is the actual code I'm using:

My main javascript file that gets loaded with a script tag in my html page:
http://pastie.org/3528889

The module's javascript file (pgmainview.js):
http://pastie.org/3528893

I'm testing with the debug version of YUI 3.4.1. If I put the requires array in the global config, then everything works fine. If I put them in the add statement, then I get the following error from the inner call to YUI().use('node', 'pg-main-view', ...

Code:
Uncaught TypeError: Cannot call method 'create' of undefined


I noticed that if I do the inner YUI.use call like this:

Code:
YUI.use('node', 'base', 'io-base', 'view', 'pg-main-view', function(Y) {


Then it works again. So it seems like the loader is not loading the dependencies specified in YUI.add. Any thoughts on what I am doing wrong?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: Where to put module dependency requirements

Post Posted: Mon Mar 05, 2012 1:44 pm
+0-
Try this against 3.5.0pr2 and see if that fixes your issue. I've done a lot of work in 3.5.0 to make this much better of an experience.

JesterVineo

  • Joined: Fri Mar 02, 2012 7:30 pm
  • Posts: 6
  • Offline
  • Profile

Re: Where to put module dependency requirements

Post Posted: Mon Mar 05, 2012 2:08 pm
+0-
I tried 3.5.0pr2 and got the same problem.

Here's the full set of files for my test project if you want to try it out:

http://dl.dropbox.com/u/34056939/yui-experiment/pg.css
http://dl.dropbox.com/u/34056939/yui-experiment/pg.html
http://dl.dropbox.com/u/34056939/yui-experiment/pg.js
http://dl.dropbox.com/u/34056939/yui-experiment/pgmainview.html
http://dl.dropbox.com/u/34056939/yui-experiment/pgmainview.js

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: Where to put module dependency requirements

Post Posted: Mon Mar 05, 2012 2:49 pm
+0-
Please create an example at JSfiddle so I can see it break and I can fork it: http://jsfiddle.net

JesterVineo

  • Joined: Fri Mar 02, 2012 7:30 pm
  • Posts: 6
  • Offline
  • Profile

Re: Where to put module dependency requirements

Post Posted: Mon Mar 05, 2012 7:20 pm
+0-
Here you go. I simplified it a bit too. It is still loading one external js file from my Dropbox account since the problem seems to have something to do with loading a module from an external file.

http://jsfiddle.net/JesterVideo/cDUhv/

The result panel should say "Hello, World!" when everything works, but it doesn't. If you uncomment the requires line in the GlobalConfig, then everything works fine.

Nick Husher

YUI Contributor

  • Offline
  • Profile
Tags:

Re: Where to put module dependency requirements

Post Posted: Tue Mar 06, 2012 6:59 am
+0-
It appears your issue is related to this ticket.

JesterVineo

  • Joined: Fri Mar 02, 2012 7:30 pm
  • Posts: 6
  • Offline
  • Profile
Tags:

Re: Where to put module dependency requirements

Post Posted: Tue Mar 06, 2012 12:22 pm
+0-
Thanks for pointing out that ticket. It does look very similar. It looks like the issue is assigned to Dav Glass, who also responded to this thread. Dav, any thoughts on the issue or comments about when it might get resolved?

Nick Husher

YUI Contributor

  • Offline
  • Profile

Re: Where to put module dependency requirements

Post Posted: Tue Mar 06, 2012 12:59 pm
+0-
I suspect this is a low-priority issue for two reasons:

First, if you're using the loader this way, you're doing it wrong. It means that dependencies can't be fetched in parallel by the loader. So, if you have a module A that requires B, and B requires C, and C requires view, model, datatable, or whatever, the loader has to request A, wait for it to load, then request B wait for it to load, then request C, wait for that. Only once C is done can it make the relatively fast parallel requests for view, model, and datatable.

Second, if you use a pattern the loader behaves in the way you desire. There's a section on pattern matching in this guide. Note that this doesn't solve the blocking load problem you see above.
  [ 13 posts ] Go to page 1, 2 Next
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum