I'm interested in writing a class to upload files from the browser. It
will accept a File (or Blob), write it to some scratch space using the
File System API and start uploading chunks to the server via XHR. If
the browser crashes or the user browses away, uploading can continue
when they browse back.
I'd like to let users of the class subscribe to events when a chunk
has been uploaded (w/ which file and % complete), or when a complete
file is uploaded (w/ which file it was), and when all files are
finished uploading, i.e., when the queue is empty.
This seems like a job for event listener lists, as seems to be
idiomatic in the rest of Dart. e.g.,
button.on.click.add((Event e) => window.console.log('yay'));
or in my case something like:
uploader.on.progress.add((ProgressEvent e) =>
window.console.log('uploaded ${e.percent}% of ${e.filename}'));
I see the generated code for this is in
http://code.google.com/searchframe#TDGadvYaD94/trunk/dart/lib/html/dartium/html_dartium.dart
and seems to rely on private classes to wrap browser events. Is this
the approved way to do this in external-to-Dart code? Should I wrap
native JS browser events, or is there a better native Dart way to do
this?
Can I use a Completer/Future and just "complete" with different values
each time? Do Futures support being called more than once?
An example of this being done in pure Dart code would be fantastic, I
just couldn't find anything.
Thanks!
- Jason