Currently, I am in the process of transitioning an app from Promises to RxJS and I could use some guidance on whether I am heading in the right direction.
Situation: I have a ModalComponent that appears when an HTTP request is sent and disappears once the response is received. Here's what I'm doing:
public post(uri: string, body: object, showLoading: boolean = true, params: object = {}): Observable<any> {
if (showLoading) {
this.toggleModal('open');
}
return this.http.post(
this.createUrl(uri),
body,
this.createOptionsWrapper(params)
)
.pipe(
this.toggleModal('close'),
catchError(err => this.handleError(err))
);
}
toggleModal() takes one parameter and controls the opening or closing of the Modal based on that. I am aware that pipeable Operators should return an OperatorFunction type. What do you think would be the most appropriate RxJS Operator for my scenario, where I don't need to manipulate the Observable itself but simply want to make it pipeable so it follows a specific sequence? Would it be beneficial to create a custom Operator for this purpose? Keep in mind that the Observable being returned here will be piped elsewhere whenever the service is injected.