Lazy Load DataSource for YUI

I'm a fan of the DataSource concept in the YUI libary. It's a very logical construct for abstracting data in JavaScript. Not only does it abstract data formats (XML, JSON, HTML, text), but it generalizes the retrieval as well (local static data, function, AJAX). The result of all this is a a uniform data access mechanism for different UI components like the DataTable and AutoComplete.

While working on some auto-completing features for a project I realized that there was a remote retrieval mechanism missing. I had small datasets that I wanted to retrieve on demand in a single request. I thought to use the XHRDataSource at first, but there would continue to be multiple requests with each letter I typed.

To solve my requirement for a lazy, single-request data source, I created the (obviously named) LazyLoadDataSource. It's much like the XHRDataSource, except it expects to retrieve all the data in a single request. Now I can create more efficient auto-completes that can retrieve data on demand while keeping requests to the server at an absolute minimum.

Here is an example that 'screen scrapes' an HTML document of names. It makes use of the YUI AutoComplete to illustrate the LazyLoadDataSource. I recommend the use of Firebug or something similar to keep track of the server calls the page makes and notice that only a single one is made when needed.

To ensure the single request rule, the LazyLoadDataSource provides initial queueing support. The concept is to queue up requests until the remote data is retrieved. Once it is, all pending requests are processed.

Code for the LazyLoadDataSource can be found here. I probably have not commented the code enough, but it's small and I hope it speaks for itself.

NOTE: It'd be wrong to not give a quick shout out to, where I got my names data from. It's a site I just found and plan on using in the future to generate test data to play with.

Why start another (tech) blog?

I've been trying to answer the above question for months now.

There have been feelings of self-doubt mixed with a drive to create something with my own name. Going through a sort of quarter-life crisis, I have realized that I have created very little of my own work. Something that was not just my employer's or client's. However, I felt that my postings would not have much value and would just get lost in the mix with all the other tech blogs.

But recently, while reading Pragmatic Thinking & Learning, I was inspired that maybe "in the detailed minutiae of everyday life were occasional philosophical gems." I realized that a blog, at the very least, would help me keep track of my thoughts and ideas over time. A public forum would force me to think through them more fully and clearly. And maybe the seemingly meaningless musings would germinate. So I started to keep a list of "Potential Blog Postings" to reflect on and see if anything was worth publishing with my name attached. While I found value in the ideas, I still did not feel sure they were worth posting to the world. So I decided to push off the endeavor and inserted it in my "todo" list between "Complete P90X Workout" and "Skydiving."

Still feeling doubtful, it wasn't until I was determined to build an efficient, paginated SQL query that I found the final inspiration. The simple and elegant solution was on small blog by a self-proclaimed Swedish geek who could not even be bothered enough to update the default Blogspot template. I realized that I find so many useful solutions and insights on small, random blogs. Maybe one of my future postings might help someone solve a vexing problem of their own.

So here I am now. Hoping somebody (including myself) finds something useful. Armed with a lame title, a list of "Potential Blog Postings," and a 14 day trial on Squarespace: