Skip to content

Fix File Progress Type #1140

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

Merged
merged 6 commits into from
Apr 12, 2020
Merged

Conversation

JeromeDeLeon
Copy link
Contributor

@JeromeDeLeon JeromeDeLeon commented Apr 7, 2020

According to @ladigitale from last PR

I just found the time to test the pacth.
As expected at the end of the upload with this code you will yet have 2 consecutive callbacks of the same function with different meanings :

1 14535341 14535341 (meaning end of the upload)
1 165 165 (meaning end of the download sent as one chunk because of the low size of the response)

Thats why aditionnal imformations / api evolution would have been usefull.

@ladigitale
Copy link

Is there any issue to put the type at last position, for backward compatibility ?

@@ -159,27 +159,28 @@ const RESTController = {
headers[key] = customHeaders[key];
}

function handleProgress(event) {
function handleProgress(type, event) {
if (options && typeof options.progress === 'function') {
if (event.lengthComputable) {
options.progress(
Copy link
Contributor Author

@JeromeDeLeon JeromeDeLeon Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed it at the beginning, or

progress(event.loaded / event.total, {
  type,
  event
});

@dplewis , @ladigitale let me know your thoughts if you have a free time 😄

Copy link
Contributor Author

@JeromeDeLeon JeromeDeLeon Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think there is. I was reluctant to just add it and the end, somehow, why not just enclose it in object to allow future values instead of

progress(progressValue, loaded, total, type, ...restArgs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be perfect.
In fact when we've got the original event i think we've got the type.
The targets of each event have a different type who gives the needed imformation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that so? Have you tried it? haven't looked into values of event tho.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just logged the target propety one is XMLHttpRequest, and the other is XMLHttpRequestUpload

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to make suggestion on the PR using the suggestion feature of Github. 😄

Comment on lines 166 to 169
type,
event.loaded / event.total,
event.loaded,
event.total

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could keep the 3 first parameters as is for backward compatibility, then we could add an object that can handle any future addition. we would just give the original event in it.
By testing original event.target people could infere if it's upload or download phase.

event.loaded / event.total,
event.loaded,
event.total,
{originalEvent:event}

But i'm ok with

event.loaded / event.total,
event.loaded,
event.total,
type

and with

event.loaded / event.total,
event.loaded,
event.total,
event

for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for determining the type of progress, we can use event.target, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon checking, I tried logging event and here's what I got:
image
I could check the instance, but it would be better to tell explicitly rather then leaving us the logic for checking whether it came from download or upload

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I agree with that.
Maybe satisfying and scallable solution would be
event.loaded / event.total, event.loaded, event.total, {type:type}
as arguments of the progress function.

Copy link
Member

@dplewis dplewis Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ladigitale I see what you are trying to do now. I didn't realize there was a difference. I agree on the backwards compatibility by adding the options to the end.

There are other places in the code that you can add progress for instance file.getData in Parse.File, FileController.download etc

@codecov
Copy link

codecov bot commented Apr 9, 2020

Codecov Report

Merging #1140 into master will not change coverage by %.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1140   +/-   ##
=======================================
  Coverage   92.30%   92.30%           
=======================================
  Files          54       54           
  Lines        5235     5235           
  Branches     1169     1169           
=======================================
  Hits         4832     4832           
  Misses        403      403           
Impacted Files Coverage Δ
src/ParseFile.js 97.77% <ø> (ø)
src/RESTController.js 84.51% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 824713f...2c60e54. Read the comment docs.

Copy link
Member

@dplewis dplewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dplewis dplewis changed the title Fix file progress Fix File Progress Type Apr 12, 2020
@dplewis dplewis merged commit 393b723 into parse-community:master Apr 12, 2020
@JeromeDeLeon JeromeDeLeon deleted the fix-file-progress branch April 12, 2020 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants