← Back to team overview

launchpad-dev team mailing list archive

YUI "issue" under Windmill

 

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>

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.




Follow ups