[whatwg] Progress Events "done" event

I've noticed a case when developing Ajax apps that I often end up
duplicating a call to hide "loading.gif" (for example) when the call
is over.
Progress Events
http://dev.w3.org/cvsweb/~checkout~/2006/webapi/progress/Progress.html?rev=1.16&content-type=text/html;%20charset=iso-8859-1#XHR

Helps facilitate that, however, I think I see a way that the use case
could be better-accomodated. Here is a simple use-case that
illustrates the problem:

Author loads a large picture.
While the picture is loading, the user sees a progress bar.
When the call is done, the progress bar is hidden.

Notice, the use case is not, "when the picture is loaded, remove the
progress bar." Instead, it reads: "When the call is done, the progress
bar is hidden."

In this use case, the progress bar must be removed, whether the call
is successful or not. If the call fails, the call is aborted, or the
call is successful, the progress bar is hidden.

To fulfill the use case, the author creates a function callFinished,
for example:

function callFinished( progressEvent ) {
  // Remove loader bar.
}

Using the current proposal, the author adds an EventListener for load,
to hide the progress bar when the image is done loading. However, the
author must also add EventListeners for failure and success Events to
remove the loader bar in those cases now.

==========================================
function showImage(imageHref) {
...

// remove the progress bar when done.
       image.addEventListener("load", hideProgressBar, false);
       image.addEventListener("error", hideProgressBar, false);
       image.addEventListener("abort", hideProgressBar, false);
}
==========================================

This is somewhat verbose. Clearly, the author is forced to repeat
himself when all he really wants to do is hide the progress bar after
the call is done.

I see this as being analogous to "hang up the phone after the call is
done." We all know how that works. It doesn't matter if the other
person hung up on rudely, we both said goodbye, the line got cut off,
the phone service was down -- the call is over. (digression)

It would be useful to have a "done" event.

The revised example, with a hypothetical "done" event:


==========================================
function showImage( imageHref ) {
       ...
// remove the progress bar when done.
       image.addEventListener("done", hideProgressBar, false);
}
==========================================


Garrett

Received on Saturday, 25 August 2007 23:24:45 UTC