W3C home > Mailing lists > Public > public-webapi@w3.org > August 2007

Fwd: Progress Events "done" event

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Sun, 26 Aug 2007 10:50:40 -0700
Message-ID: <c9e12660708261050v30aaaf2fgd9757b98297ecf9d@mail.gmail.com>
To: public-webapi@w3.org

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

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  he 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.

The same conceptual metaphor of a phone call applies to our http call example.

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

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


Received on Sunday, 26 August 2007 17:50:47 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:09:57 UTC