RxJS operator that combines tapAsyncState + tapAsyncProgress for HTTP event streams
tapHttpAsyncState
Functioncommon/data/async-state
projects/common/data/async-state/operators.ts
Description#
RxJS operator that combines tapAsyncState + tapAsyncProgress for HTTP event streams.
Pipe this onto an HttpClient call with { observe: 'events', reportProgress: true }.
It will:
- Set
loadingon subscribe - Report upload/download progress via
setProgress() - Extract the response body on
HttpEventType.Response - Call
setSuccess(body)with the extracted body - Call
setError(err)on error
The output Observable emits the response body (not HttpEvents).
Throws if the response body is null.
readonly upload = createManualState<UploadResult>();
handleUpload(file: File): void {
this.http.post('/api/upload', file, {
reportProgress: true,
observe: 'events',
}).pipe(
tapHttpAsyncState(this.upload),
takeUntilDestroyed(this.destroyRef),
).subscribe();
// upload.status(), upload.progress(), upload.data() — all wired
}Signature#
tapHttpAsyncState(state: AsyncStateSink, options?)Parameters#
@paramoptions?
Returns#
OperatorFunction