← Back to team overview

launchpad-dev team mailing list archive

State of lazr-js/YUI in Launchpad

 

Hi, all.

There has been a lot of activity around lazr-js and JavaScript in
Launchpad lately, which makes me happy. :-)  Since we're on YUI 3.3
now, I wanted to write briefly about some things to watch out for as
we're coding JavaScript.  I also thought I would post some of my
observations after this latest upgrade, a sort of "State of js in
Launchpad" for those curious or mindful of these sort of things.

First, one major thing about how you should be writing js now.

== YUI 3.3 one/all ==

* use Y.one/$MY_NODE.one and Y.all/$MY_NODE.all
  (instead of Y.query or Y.queryAll or Y.get)

$MY_NODE here means a YUI node assigned to a var.  So:

var my_node = Y.one('.myclass');
var sub_node = my_node.one('.someotherclass');

not

var my_node = Y.query('.myclass');
var sub_node = my_node.query('.someotherclass');

and not

var my_node = Y.get('.myclass');
var sub_node = my_node.get('.someotherclass');

(I believe node.get was cleaned up in an earlier upgrade,  but just to
be clear we shouldn't do this.)

The same applies to Y.queryAll/$MY_NODE.queryAll needing to be
Y.all/$MY_NODE.all.  If you use the old constructions, your code will
not work.

You can work around this by explicitly adding node-deprecated to your
requires property in add blocks.  Please don't do this unless it's a
last resort.  I've removed node-deprecated from our dependencies as
one step toward a smaller launchpad.js file, and you'll have to add
this back if you need it.

Which brings us to other observations...

== launchpad.js size and developer needs ==

I've trimmed the list of dependencies substantially for building
launchpad.js.  If you find something js-related suddenly doesn't work
now on Launchpad, check for missing dependencies first.  Also, please
think carefully before adding to these.  Make sure you need the dep
before adding it.  When we have a combo loader, this doesn't matter,
but until then, this is a great step toward a smaller js file.

Maris also pointed out a nice flag for building launchpad.js from
unminified files.  It only works for lp js files, not the YUI deps,
but it makes debugging our own files substantially easier.  To use
un-minified files do:

$ make clean_js
$ make jsbuild JSFLAGS='--filetype=raw'

I've opened bug 720097 to track getting this working for YUI deps, too.

== license.pt JavaScript makes babies cry ==

The JavaScript for showing or hiding license choices found in
lib/lp/app/widgets/templates/license.pt is really fragile and really
needs to be rewritten.  I fixed it for now but it breaks with every
YUI upgrade.  I suspect it may break again.  It's trying to do too
much for some simple slider animations.

I've opened bug 715892 about this and put suggestions there for what
needs to be done.  Any of us could fix this.

== Testing ==

And please write YUI tests people! ;) :)  The license js code would
not make babies weep if it had been tested.  You really can test your
JavaScript as easily as Python.

I realize not everyone knows how to do this, so I'll put another email
together later today about YUI test and Windmill.

Thanks for making it this far!  (And yes, I will dump all this into
the appropriate wiki pages later.)

Cheers,
deryck