Tuesday, March 25, 2008

IBRPG Update: Fighting YUI Dragons...

I learned alot about events and cookies tonight. I had been debating with myself as to which library to use to store information on the browser. I had seen the Dojo storage library and I thought it'd be cool to try to use that. However it still seems like it needs some final polish before its usable in the outside world (the example files failed with js errors).

So, I realized that there is yet another Hidden Gem in YUI. Cookies! If you have ever had to deal with cookies before YUI you know it's a real pain. YUI Cookie allows you to create a json like object and store it in a named cookie.

With Cookie(s) in hand I happily started tonight to get a simple addition to my panel and display a username. However it was then that I began to fight the YUI dragon of MISSING DOCUMENTATION. I believe this is the single most frustrating aspect of working with YUI. There are all kinds of cool shortcuts and special methods for doing things - like best practices and such - that simply do not show up in the docs. ARGGH!

However after a while of search engine bashing I discovered the answer to my problem. First off my issue was that I wanted to do something to the panel I had created after it had been shown. I knew there was something like "onshow" that was fired and I wanted to hook into that. However panel.onShow.subscribe(... did not work.

Long story short I discovered this:

+ Prototype of all classes (Module, Overlay, Panel, Dialog, SimpleDialog,
Tooltip, Config, and ContainerEffect) are augmented with
YAHOO.util.EventProvider, facilitating subscribing to an instance's
Custom Events by name via a "subscribe" method that is a direct member of
the class. For example:

var oOverlay = new YAHOO.widget.Overlay("myoverlay");

oOverlay.subscribe("show", onShow);


Hello? Can we add that back to the docs please? :)

Anyway after a few more issues with event binding I now have a dynamic panel which will allow you to type in a username and if you reload the page you'll see that username come back magically from cookie land.

Here's some advice for YUI folks. Hire someone who's great at writing documentation and set them on the YUI libraries. Get him or her to sit down with the authors of each component and get the "inside scoop" on each one. There are so many countless cool shortcuts and things you can do with YUI that it's a crying shame that this information is not more available.

For instance you may be using YUI to add even listeners to your buttons and such. You may be using:

YAHOO.util.Event.addListener(oElement, "click", fnCallback);


However, did you know you can instead do:

YAHOO.util.Event.on(oElement, "click", fnCallback);


So, I'm really happy I found a way to store information about my game, and not have to include another big library from another source. Instead I can just use Cookie and be very careful about long strings. With regards to YUI features, I encourage those very smart and dedicated folks to consider adding a new "feature" called "super verbose example - laden documentation of best practices including shortcuts"

AddThis Social Bookmark Button

1 Comments:

At 4:13 PM, Blogger Brad Neuberg said...

This post has been removed by a blog administrator.

 

Post a Comment

<< Home