I'm uploading a file to server and I would like to track upload progress without spamming with many actions (on each http event). Is it possible to return something like null or empty observable in some cases? Because I want to dispatch an action only in two cases - success or failure. And now I must return an action in each http event type and it's becoming a spam then..
@Effect()
public createMediaItem: Observable<Action> = this._actions
.pipe(
ofType(MediaItemActionTypes.MediaItemCreateAction),
map((action: MediaItemCreateAction) => action),
switchMap(action => {
return this._uploadService.createMediaItem(action.formData)
.pipe(
map((event: HttpEvent<HttpEventType>) => {
switch (event.type) {
case HttpEventType.UploadProgress: {
console.log('ignore');
action.fileItem.progress = Math.round(event.loaded / event.total * 100);
break;
// return;
}
case HttpEventType.Response: {
return new MediaItemCreateSuccessAction();
}
default:
break;
// return;
}
})
);
})
);
tapandfinalize, which would trigger at request creation and at request ending. - user4676340