Tutorial hero
Lesson icon

Improving and RxJS Stream

Originally published October 27, 2022 Time 2 mins

I’m currently working on a new video where I compare a seemingly complex RxJS stream from one of my previous videos with the equivalent functionality created without RxJS.

In an attempt to not be biased in the comparison, I posted the code I created for the imperative/non-RxJS version on Twitter to see if people thought it was a generally fair representation of the approach.

If you’re curious, this is what I tweeted:

RxJS and non-RxJS code

RxJS on the left, non-RxJS on the right.

The tip for the week isn’t actually anything specifically to do with this, but I did also get some suggestions on changes for the RxJS version as well. One in particular from Mike Pearson which suggested:

tweet from Mike Pearson

This doesn’t fundamentally change anything about the stream, it is really just organising it in a slightly different way, but I think the result actually greatly improves readability:

RxJS version

Specifically, separating the delay out into its own stream makes this a lot easier to read (assuming you know RxJS!) - on one count because it is explicitly named now, but also because it reduces the level of nesting/indentation required for the currentPhoto stream.

So, if you are ever dealing with more complex RxJS streams, see if splitting your streams out like this can help make everything a bit easier to follow.

Learn to build modern Angular apps with my course