Skip to content
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

Split progress event handlers into upload and download. #423

Merged
merged 7 commits into from Aug 23, 2016

Conversation

Projects
None yet
3 participants
@diesal11
Copy link
Contributor

diesal11 commented Aug 22, 2016

Splits progress config into two options, progressDownload and progressUpload. No longer limits these to GET/POST/PUT requests.

Previously there were no tests for progress handling...so i've added some. But testing is difficult as the Jasmine-AJAX plugin doesn't handle xhr.upload.addEventListener correctly. Im also not overly familiar with Jasmine and it's tools so if you have any ideas on how i could improve the tests please let me know :)

At some point in future i'll do a PR to allow progress events in the Node world.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Aug 22, 2016

Coverage Status

Coverage increased (+1.03%) to 93.947% when pulling 10a986c on diesal11:master into 59080e6 on mzabriskie:master.

README.md Outdated
// as well as 'GET' downloads
progress: function (progressEvent) {
// `progressUpload` allows handling of progress events for uploads
progressUpload: function (progressEvent) {

This comment has been minimized.

Copy link
@nickuraltsev

nickuraltsev Aug 22, 2016

Member

I would suggest to rename progressUpload and progressDownload to onUploadProgress and onDownloadProgress respectively.

}

if (typeof config.progressUpload === 'function') {
request.upload.addEventListener('progress', config.progressUpload);

This comment has been minimized.

Copy link
@nickuraltsev

nickuraltsev Aug 22, 2016

Member

It doesn't look like upload is supported by all modern browsers (please correct me if I'm wrong) so I would suggest to check whether this property is present before calling addEventListener:

if (typeof config.progressUpload === 'function' && request.upload) {
  // ...
}

This comment has been minimized.

Copy link
@diesal11

diesal11 Aug 23, 2016

Author Contributor

It's not really clear which browsers support request.upload and when they did. It was included in the XHR2 spec so older browsers definitely won't support it. Will add a check.


getAjaxRequest().then(function (request) {
// Not sure of the best way to test this, so just test that the new listener is present
expect(request.eventBus.eventList.progress.length).toEqual(2);

This comment has been minimized.

Copy link
@nickuraltsev

nickuraltsev Aug 22, 2016

Member

I don't think it's safe to rely on jasmine-ajax internals (request.eventBus).

This comment has been minimized.

Copy link
@diesal11

diesal11 Aug 23, 2016

Author Contributor

Yeah i agree, i don't like that at all on a second look!
Plus the upload test doesn't actually test for anything atm as i couldn't figure out the best way to test it as Jasmine AJAX doesn't seem to catch/handle upload events.

I'll have another dive in and see how i can improve both. :)

Updating progress event params. Also check if we can attach to Upload…
… events before attaching.

Updated tests to use Spies.
@diesal11

This comment has been minimized.

Copy link
Contributor Author

diesal11 commented Aug 23, 2016

@nickuraltsev the Jasmine AJAX fakeXHR hasn't implemented upload events. So i can't do any tests on that yet. I'm gonna create an issue/PR over there so we can test this properly, not sure if you wanna wait for that before merging this.

In the meantime i've switched the tests to use spies which is much nicer.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Aug 23, 2016

Coverage Status

Coverage decreased (-23.7%) to 69.211% when pulling 2dffe90 on diesal11:master into 59080e6 on mzabriskie:master.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Aug 23, 2016

Coverage Status

Coverage increased (+1.03%) to 93.947% when pulling 3f5d411 on diesal11:master into 59080e6 on mzabriskie:master.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Aug 23, 2016

Coverage Status

Coverage increased (+1.03%) to 93.947% when pulling bcad5b1 on diesal11:master into 59080e6 on mzabriskie:master.

@nickuraltsev

This comment has been minimized.

Copy link
Member

nickuraltsev commented Aug 23, 2016

@diesal11 Thank you! Could you please also rename the config options in README.md? Everything else looks good to me.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Aug 23, 2016

Coverage Status

Coverage increased (+1.03%) to 93.947% when pulling f623809 on diesal11:master into 59080e6 on mzabriskie:master.

@nickuraltsev nickuraltsev merged commit 63f41b5 into axios:master Aug 23, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@nickuraltsev

This comment has been minimized.

Copy link
Member

nickuraltsev commented Aug 23, 2016

@diesal11 Merged. Thank you for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.