-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Description
[x] feature request
Current behavior
When I want to attach to XMLHttpRequest.prototype.upload events using Http I need to put my hands on the default backend/connection provided and override the provider for Http injecting my modified backend/connection.
Expected/desired behavior
When I invoke .{get,post,put,...} on Http I want to be able to optional listen to upload progress of the underlying connection. I want to do so the least intrusive way. After a glance at source I see a possibility to implement an optional property on RequestOptions and/or Request object. It could be of type Subject. The abstract Connection could have an additional optional property progress of the same time.
- A Connection-Implementation, which supports progress could .next to the Subject, passing specified RequestProgressEvent interface, when the given option is not undefined.
- A Connection-Implementation which does not support it could either ignore it and not emit any events, or mock the state by just sending start and end events - not sure yet which way would be the best.
The RequestProgressEvent could abstract from concrete events used for example in XHR to a common interface, so that any Connection which supports it could adapt its internal impl. to this interface.
The usage could look like that:
let progress$ = new Subject<RequestProgressEvent>();
progress$.subscribe(event => {
switch (event.type) {
// do something ... different types, like timeout, progress, etc.
}
});
// http: Http
// given the Connection used supports progress, ii would also .next upload events to progress$
http.get(url, {progress: progress$}).subscribe(/* ... */);Sure the instantiation of Subject can be omitted by passing a shorthand next/error/complete to progress-option.
Something I'v overlooked that makes this not a good approach?
updated: Escaped less-than/greater-than characters for generic type, so they are now visible.