| Page 1 of 1 | [ 8 posts ] |
|
Way to get Y from YUI with no side effects? Calling Y=YUI().use("*") has possible side effects. Is there no direct path to it? I'm guessing there is a reason why it is hidden away as a private inside a module pattern, but it is a pain to learn by just inspecting around. I don't know what sort of issues having Firebug do such a call on every website visited that has YUI on it would be.
|
|
YUI() is a factory method that generates a Y instance. .use() is a method on Y that invokes the loader, running YUI.add() functions to augment your Y instance with required modules.
So, if you want a Y instance with zero side-effects, just call YUI(). Actually this isn't *quite* zero side-effects since the YUI.Env.UA namespace doesn't exist until the first time a Y instance is instantiated, but that's the only side-effect I can think of. |
|
Using this as an example:
examples/slider/slider_basic_clean.html YUI().Widget is undefined YUI().use("*").Widget may be undefined if the page is not using Widget, or it may be the Widget object if the page is using it and it is loaded. Sorry if I am not asking the question correctly. I want to see all the loaded classes like Widget and Slider that happened to be loaded, and I want to do that synchronously. I want to be sure that I'm not causing something to happen (I don't want to cause things to get loaded for example). Unfortunately, use("*") causes the Security Manager to squash the call do to implementation details of the function. There is only so much such a function can do being called from chrome context that would be safe. Unfortunately, I don't know what part of use() is causing the error. I might investigate this, though I'm not sure if that would be of any help. My next bet is to start injecting script into the page, having it create an event with the Y object as a param, and setup a listener to listen for the event on pages that have YUI on it. Much more complicated than, say, a direct access to YUI.Classes. It is a fine solution, but I assume synchronous information gathering at the moment, and may just drop hope of YUI support until I rework things to make use of an event system (which I want to do anyway, but time is limited, yada, yada, yada...) |
|
YUI.Env.mods contains a list of the all the modules registered with YUI via a YUI.add statement. I think this may be what you want.
|
|
I saw that... however the class function object themselves are not there.
I thought at one time that YUI.Env.mods.widget.fn was it, but it is an empty function. |
|
Okay... so you want to be on a page where YUI exists, where there is already a YUI().use(..., function(Y) { ...} ) call, and you want to know what's on the Y inside of that callback?
|
|
Okay, I've re-read your post.
A Y instance inside of a 'use' callback is sandboxed. You have no easy way to access it. Now, since YUI() returns that Y and use is chainable (so it also returns that Y) then a Y instance can be 'leaked' outside of it's sandbox, SimpleYUI is possible in part because of this. However, it is unusual to leak a Y instance outside of it's sandbox, because the reason we sandbox is to avoid global pollution. The metadata in YUI.Env.mods can tell you what classes are available. To use the widget example, YUI.Env.mods.widget.details.use is an array that tells you that Widget is built using 'widget-base', and 'widget-htmlparser'. Loader uses that to know that it needs to run the fn's for those modules before it runs Widget's own empty method. widget-base requires ["attribute", "event-focus", "base-base", "base-pluginhost", "node-base", "node-style", "node-event-delegate", "classnamemanager"], and Loader will walk up that chain to determine what it needs to execute before it runs the 'widget' module's setup method. Widget is a weird case, because it's a 'roll-up' adding no functionality itself, but making sure other parts are available. Of course, not every module adds new classes, some simply modify existing modules (for instance, widget-htmlparser adds functionality to widget-base, but does not add a new Class), but the mods metadata can help you determine what is available to Y instances on the page, though not what is in use. But, if you want to know about a specific Y instance, it needs to be set to a global variable when YUI().use() is called, so you can look at it (though if external resources need to be loaded you'll need to give it time to load them). Does that (finally) answer your question? |
|
Yes, it does answer my question. There is no easy way at getting what I want.
I have a couple of options: inject code into the page (send event or set a global to be discovered later), or find out what is causing the security manager veto. On the second note, I tracked it down to the YUI instanceOf (it is the real instanceof that is the problem), which exposes a bug in Gecko. I have come across it before, and worked to have it fixed in FF4, and indeed it was just fixed last week in Minefield and the fix should ship in FF4beta10 (tomorrow?). I guess the last part of this questions is: is there some side effect of YIU().use("*") that would be negative, that I should be aware of? (And thank you!) |
| Page 1 of 1 | [ 8 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