-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notifications for xhr.upload.onprogress #9
Conversation
Triggers deferred.notify during upload progress if the config option `watchUpload` is set to true. Adds the property `upload = true` to the upload progress event to easily detect the type of progress event (download or upload).
Thanks for the pull request! I like it - a couple of things:
No it's not. I would prefer to remove the flag and take a major version bump. This is a nice feature and I don't see a reason to turn it off, definitely not by default. Also documentation and a test (integration is good but unit only is fine) please. I see the build is failing on the saucelabs part - I'll check to see if my saucelabs key is still good but I am not worried about that. |
Thank you for your quick answer, I'll complete the pull request tomorrow. About I'll drop |
Yes, I like that approach. You can bump to |
I updated my changes but I'm not so familiar with mocha & coffee script so I screw up the tests. Could you take a look at it ? |
Yup I can update the tests. The changes are solid. thanks! |
Notifications for xhr.upload.onprogress
Hi,
Currently,
q-xhr
usesdeferred.notify
to track the progression of the download of the response. It would be nice to be able to track the upload when available.Angular's $http being backed by $q, they don't have the
deferred.notify
API so it's not possible to copy their implementation. (it's the goal of your lib if I'm not mistaken ?)Still, reacting to progress is a popular feature so here is a proposition for the implementation:
To avoid to break compatibility with applications expecting
Q.xhr({...}).progress
to only trigger on download progress, applications have to explicitly ask for upload progress notifications with the new config propertywatchUpload
(boolean).It's possible to set
Q.xhr.defaults.watchUpload = true
Since there will be two sorts of
progress
calls, it should be possible to differentiate them. Both type of progress objects are instances of ProgressEvent. To differentiate them, it's possible to use:window.XMLHttpRequestUpload
is a quick feature detection to avoid to throw onprogress.target instanceof undefined
when executed on older browsers.This test on the user side does not seem like a good idea (hard to maintain, boilerplate) so I add the flag
upload
when the progress event is received by theupload.onprogress
callback. This way, the above example becomes simply:What do you think about it ? (Maybe the names of the option and flag should change ?)