| Page 1 of 1 | [ 7 posts ] |
|
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 |
|
node in this case is a module.
'*' will only load what you have already included on the page. |
|
'*' 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. |
|
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 automaticallyregarding '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 |
|
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. |
|
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 |
|
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 |
| Page 1 of 1 | [ 7 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group