← Back to team overview

launchpad-dev team mailing list archive

Re: YUI "issue" under Windmill

 

On 11/13/2010 06:42 AM, Ian Booth wrote:
> Hi
>
> Well, not really an issue but a problem I had getting stuff to work. I
> recently wrote some YUI javascript and it all worked fine when running
> Launchpad but the Windmill tests would fail. But the failure was
> intermittent. Since everything worked outside Windmill (and sometimes
> under Windmill too)  I really struggled to find out what was wrong. But
> I think I finally found what I needed to do to fix it.
>
> My javascript was written to be executed onload so I added some stuff to
> base-layout-macros.pt:
>
>   <script id="base-layout-load-scripts" type="text/javascript">
>     LPS.use('lp.app.links',
>       function(Y) {
>         Y.on('load', function(e) {
>             Y.lp.app.links.check_valid_lp_links();
>         }, window);
>     });
>   </script>

It's probably better for you if you structure this code like this:

LPS.use('lp.app.links', function(Y) {
    Y.config.win.on('domready', function(e) {
        Y.lp.app.links.check_valid_lp_links();
    });
});

We shouldn't be referencing window or document in our code.  We should
be using Y.config.win and Y.config.doc.

> My javascript was like so:
>
> YUI.add('lp.app.links', function(Y) {
>
>     Y.lp.app.links.check_valid_lp_links = function() {
>         //code here
>     };
> }, "0.1", {"requires": [
>     "base", "node", "io", "dom", "json"
>     ]});
>
> Can anyone see what makes the above fail under Windmill but work fine
> every time when running Launchpad? By fail, I mean that what happens is
> that the call to check_valid_lp_links() in the onload just never happens.
>
> Well, in case anyone else is new to YUI like me, I had to add this line
> of code to the top of the javascript:
>
>     var namespace = Y.namespace('lp.app.links');
>
> Or at least doing the above made the Windmill tests run reliably every
> time I subsequently ran them.
>
> Why? Nothing in the javascript uses the namespace variable at all.
> It's as if the Y.namespace('lp.app.links') call has some magic side
> effect that Makes Stuff Work (tm).
>
> Can someone enlighten me? I wasted far too much time trying to track
> this down and would like to know the answer.

Y.namespace indeed does some (kinda icky) magic for namespacing.  I'm
starting to wonder if we really need to namespace as much as we are. 
There's a pretty large performance hit to it, and as long as we don't
YUI.use('*') or something, we should be okay with a more relaxed
namespacing.  If we didn't use periods as our namespacing character, we
wouldn't need it at all.

Cheers,
Paul



Follow ups

References