[ 3 posts ]

Christian Enze

  • Username: janson
  • Joined: Wed Jul 29, 2009 5:46 am
  • Posts: 3
  • Offline
  • Profile

Callback-function of use(), base-url of the loader

Post Posted: Fri Jul 31, 2009 4:55 am
+0-
Hi,

I am trying a few things on YUI 3 to see the differences between version 2 and 3. Now I have a few questions:

The code of the examples is always looking like this:
Code:
YUI().use('node', function(Y) {
...
});

The whole Code of the examples is located at the callback-function. Do I have to put all my code at the callback of use() even if I have larger scripts? What is the recommended way to use YUI3 at this point? Are there other ways to use YUI3 at this point?

I save the library on my own server. Now I have to set a base-url, when I make an instance of the YUI:
Quote:
YUI({base : "./yui/build/"}).use('node', function(Y) {
...

If I want to make more instances on one page, I have to set this url twice. Can I set base globally?

thank you in anticipation

Jeff Craig

YUI Contributor

  • Username: foxxtrot
  • Joined: Thu Dec 04, 2008 9:20 am
  • Posts: 135
  • Location: Pullman, WA
  • Twitter: foxxtrot
  • GitHub: foxxtrot
  • Gists: foxxtrot
  • IRC: foxxtrot
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: Callback-function of use(), base-url of the loader

Post Posted: Fri Jul 31, 2009 6:40 am
+1-
You don't have to use the callback function, you can declare your scripts like this:

Code:
var Y = YUI().use('list','of','modules');


And then use the Y variable as you would have inside the callback.

I generally only do this for testing purposes, however, as the benefit of using the callback is that you don't have to worry about your code interacting in strange, unexpected ways. For me, each feature I'm implementing on a page gets it's own instance of YUI3 and exists in it's own callback. If you do want interaction between modules on a page, you can use the YUI.namespace function to create a global namespace for values.

As for the build parameters, you either need to directly modify the defaults in the YUI file in your local copy, or you'll have to set the Base url in all your subsequent code. I use a global configuration variable on my site to deal with this.

Caridy Patino

YUI Contributor

  • Username: caridy
  • Joined: Mon Dec 08, 2008 5:40 pm
  • Posts: 492
  • Location: Miami, FL
  • Twitter: caridy
  • GitHub: caridy
  • Gists: caridy
  • IRC: caridy
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: Callback-function of use(), base-url of the loader

Post Posted: Mon Aug 10, 2009 12:43 pm
+0-
The upcoming version should include a new feature to infer "base" value based on the yui-*.js path. So, you just need to change the path for your base file and all the instances can get it from there.

Hopefully few more features related with the YUI conf will be included. You can follow up the discussion here:

viewtopic.php?f=18&t=541&p=1974

Best Regards,
Caridy
  [ 3 posts ]
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