Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there something like tap in RxJS that ignores notification type?

In general tap pipe is for side-effects such as logging. In my case I just want to set isLoading property to false. The key is this place shouldn’t care whether it’s next or error type of notification but still tap needs to have it distinguished to work so I need to have duplicated code:

something.pipe(
    tap({
        next: () => {
            this.isLoading = false;
        },
        error: () => {
            this.isLoading = false;
        }
    }),
)

Is there any pipe, or some way to configure tap so I just provide one callback function which would run no matter what the notification type is? Eg.

something.pipe(
    anyTap(() => {
        this.isLoading = false;
    }),
)

And whatever something returns, anyTap would run it’s callback function anyway.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

something.pipe(
  finalize(() => {
    this.isLoading = false;
  });
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading