[ 7 posts ]

Levan

  • Username: levancho
  • Joined: Thu Sep 17, 2009 3:29 am
  • Posts: 129
  • Location: New York, NY
  • Twitter: dlevancho
  • GitHub: levancho
  • Gists: levancho
  • Offline
  • Profile
Tags:

amateur Question on [YUI().use('node'..]

Post Posted: Mon Nov 16, 2009 11:33 am
+0-
Hi Guys,

I started looking into YUI3 and seems to be getting hang of its architecture etc.
.I have very amateur question


I understand conceptually what does use method do, but what does 'node' parameter is for?

Code:
 YUI().use('node', function(Y) {
                 // some code
});



if I pass module name to use() it will be loaded, if I pass * all required modules will be loaded, and if I pass 'node' what will happen?

kind Regards
Levan

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: amateur Question on [YUI().use('node'..]

Post Posted: Mon Nov 16, 2009 11:39 am
+0-
node in this case is a module.

'*' will only load what you have already included on the page.

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

Re: amateur Question on [YUI().use('node'..]

Post Posted: Mon Nov 16, 2009 11:40 am
+2-
'*' doesn't load all required modules, it loads all the modules that have been registered with the current YUI instance via the 'add' method. In other words, all the modules that you've either explicitly loaded via script tags, or have implicitly loaded via other YUI().use() calls. It's not recommended for normal use, since it doesn't provide any semantic information about what you're using in the coming method block.

'node' is a module name, so it tells the YUI instance to create a new Y instance with the 'node' module and all of it's dependencies. These instances are created independent of any other Y instance anywhere on the page, allowing you to be sure a given piece of code won't likely be impacted by a neighboring widget on the page.

Levan

  • Username: levancho
  • Joined: Thu Sep 17, 2009 3:29 am
  • Posts: 129
  • Location: New York, NY
  • Twitter: dlevancho
  • GitHub: levancho
  • Gists: levancho
  • Offline
  • Profile

Re: amateur Question on [YUI().use('node'..]

Post Posted: Mon Nov 16, 2009 11:57 am
+0-
the reason I said "all required" because in YUI3 page under YUI global Object there is note towards the buttom that says (in context of using '*' ):

Quote:
Note: This shorthand only loads modules that are already on the page. If you explicitly specify the module list on which your instance depends, YUI Loader will dynamically load any missing dependencies; this tends to be a more robust usage, because it can self-complete its requirements. Only use * if you are sure that your instance will never be used in a context in which one or more of its dependencies might be missing.


part that says:
Quote:
YUI Loader will dynamically load any missing dependencies
threw me off, assuming that if I did not include for example dd, and its required it will be also loaded automatically

regarding 'node' - now its clear, I did not realize there was a Module named 'node' since there is also a Node Utility class.

thanks again for having great community
Regards
Levan

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

Re: amateur Question on [YUI().use('node'..]

Post Posted: Mon Nov 16, 2009 12:38 pm
+0-
The wording on the documentation might be awkward, and you should perhaps file a bug to that effect.

What the documentation is saying, however, is that if you've included a script tag for, say, widget, YUI.use('*') will proceed to load everything widget depends on to function correctly, so if you had loaded via script tag something that did require dd, but you hadn't loaded it explicitly, YUI would load it for you. I still advise against using '*'

As for the module names, I'd suggest spending some time with the configurator for YUI3, as it provides a list of all the module names, as well as sub-modules names available, and it's proved useful for me in crafting my "use" statements before, particularly when showing me what exactly a given "use" statement is going to load.

Alex Leduc

  • Username: voidmind
  • Joined: Fri Sep 04, 2009 9:16 am
  • Posts: 34
  • Location: Montreal, Canada
  • Offline
  • Profile

Re: amateur Question on [YUI().use('node'..]

Post Posted: Thu Dec 03, 2009 7:09 am
+0-
Related question:

Is there a way to use YUI 3 without using the Loader / .use()?

For example, I want to use IO + io.swf to do some XSS. I have to manually upload each html/css/js files I want to use in our CMS, one by one, so it would be very useful for me to not have to upload the whole YUI distro for the Loader to do it's work but upload & include only what I need via script tags.

All the examples I've seen so far have a YUI(...).use("module_name", function(Y) { ... }); wrapping everything so I'm afraid this will cause some problem if I just copy-pasted the files I [think] I need. from the YUI /build/some_subfolder to my plain old /js folder which contains only the files I need to include via script tags.

In my case, I think that would be:
js/yui-min.js
js/io-xdr-min.js
js/json-parse-min.js
js/substitute-min.js

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

Re: amateur Question on [YUI().use('node'..]

Post Posted: Thu Dec 03, 2009 8:28 am
+0-
Hey Alex,

You can put those files in your CMS, and just include then into the page using "script" tags, right before the instantiation process (YUI().use('io', etc....). In this case, the loader will not try to load the files again, because they are already in the page. :-)

Also, you can go to the configurator, create your own configuration, save it as a local file: myyuicopy.js, and include it in your page as a single file. Keep in mind that the recommendation is to use dynamic injection to prevent blocking the browser loading/render process, but definitely this is a solution for your use-case.

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