DEV Community

Cover image for When and how to use mergeMap
Jozsef
Jozsef

Posted on

1

When and how to use mergeMap

If a developer uses Angular without knowing the power of RxJS the code can turn into a huge mass very fast.

When the inner observable needs a value from the outer observable, we can and must use mergeMap!

As a result, we not just gonna have nicer and more readable code, but we can follow the async pipe pattern.
It has also performance advantages if the outer event triggers twice then the first execution will be canceled.

With mergeMap

with mergeMap

Without mergeMap

without mergeMap

I am a Full-stack [Angular, Java] contractor/freelancer developer, if you would like to contact me here is my website !

You can find me on LinkedIn as well.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️