-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add progress to RemotePending #9
Comments
@OliverJAsh This looks more like success state: type Loading = { type: 'progress', progress: number }
type Resolved<A> = { type: 'resolved', value: A }
type Data<A> = Loading | Resolved<A>
type RD<A> = RemoteData<Data<A>> Conceptually |
That initial loading will have a progress though? For context, I want to use this to track the progress of a file upload. The request is pending whilst the file uploads—it could still fail. |
@OliverJAsh Makes sense... Still it will be a massive breaking change for our codebase to add an argument to class RemotePending<L, A> {
constructor(readonly progress: number = 0) { }
}
const progress = <L, A>(progress: number): RemotePending<L, A> => new RemotePending(progress) Also we should think about |
Good idea. Do we need to make it explicit that the progress is for uploading (as it's typically derived from type RemotePendingUpload = { progress: { loaded: number } };
class RemotePending<L, A> {
constructor(readonly upload: Option<RemotePendingUpload> = Option.none()) { }
} |
@OliverJAsh Progress can also be tracked for downloading, not only uploading, so I'd rather stick to |
True, in that case, what about a request where we want to track the progress of both uploading and downloading? We need two pieces of state I think? Maybe we can also include the other properties of |
Could you provide an example of such request?
This doesn't play well with |
Sorry but can you elaborate?
I can't, sorry! Maybe it could be confusing if there was one |
I mean that if you already are in a pending state then |
@OliverJAsh What do you think about making type RemoteProgress = {
loaded: number;
total: Option<number>;
}
class RemotePending<L, A> {
constructor(readonly progress: RemoteProgress= { loaded: 0, total: none }) { }
}
const progress = <L, A>(progress: RemoteProgress): RemotePending<L, A> => new RemotePending(progress) |
@raveclassic Sounds sensible to me. I still wonder if we need to allow for upload/download progress simultaneously, or at least to help disambiguate whether the progress signals an upload or download. 🤔
Hmm, I see your point. OTOH, I don't think all requests emit a |
I think it's not responsibility of RemoteData but of the process itself.
Agree, you are right since RemoteData is not only about XHR. Summing up, is the following correct? type RemoteProgress = {
loaded: number;
total: Option<number>
}
class RemotePending<L, A> {
contructor(readonly progress: Option<RemoteProgress> = none) { }
}
const progress = <L, A>(progress: RemoteProgress): RemotePending<L, A> => new RemotePending(progress)
|
Here're my observations, need help with ???:
and the most tricky const a = { loaded: 1, total: 10 }
const b = { loaded: 3, total: 20 }
const resultTotal = a.total + b.total // I guess the values should be added here, right?
const resultLoaded
= (a.loaded / (resultTotal / a.total)) / resultTotal + (b.loaded / (resultTotal / b.total)) / resultTotal
= (a.loaded * a.total + b.loaded * b.total) / (resultTotal * resultTotal)
// correct? /cc @sutarmin @igoralekseev @mankdev EDIT: removed unnecessary |
I think summing up proportionally would be the best strategy here. |
@sutarmin Makes sense |
I'm not sure to be honest. I haven't required that ability yet. |
@OliverJAsh Please take a look #13 |
I want to record the progress of an (upload) request, however currently
RemotePending
does not store any value for itself.Example of a remote data type which has this: https://github.com/cyclejs-community/cycle-remote-data
https://github.com/cyclejs-community/cycle-remote-data#whencases-casest-u-u
Related krisajenkins/remotedata#25
The text was updated successfully, but these errors were encountered: