Clear data while loading with RxJS startWith

InstructorAndré Staltz

Share this video with your friends

Send Tweet

Let's fix a small UI glitch that was occurring on startup and whenever the refresh button was clicked. In this lesson we will see how to avoid common bad habits of imperative programming, and how to use reactive programming to keep the complete dynamic behavior of a value specified in one convenient place.

Roaders
~ 8 years ago

Hi. Great videos, many thanks. Why can't you use start with in the previous lesson to load the initial list of users before the refresh button is pressed rather than merging the 2 streams?

André Staltzinstructor
~ 8 years ago

Hi Roaders, we wanted to introduce only one new concept per lesson.

Roaders
~ 8 years ago

Great, thanks for the reply.

Michel
~ 8 years ago

Would you be getting a race condition between getting the response from the requestStream and the null event from the refresh stream?

André Staltzinstructor
~ 8 years ago

Hi Michel, no we wouldn't, because from refresh to the null emission, all of this was synchronous, but a response is asynchronous. In worse cases where both are asynchronous, we can still neatly handle race conditions in RxJS using either concat or concatMap or zip, depending on the situation.

Thanh
~ 7 years ago

This part of transcript is false, else condition must be : 'suggestionEl.style.visibility = 'visible'; if (suggestedUser === null) { suggestedEl.style.visibility = 'hidden'; } else { suggestionEl.style.visibility = 'hidden'; }

fredrik
~ 5 years ago

That is not an advantage for me. I still wanna show the data, until the data has been completely downloaded from httpRequest and then shows it (directly switched over to the new avatar and text) so it won't be any cleared or spinning loading animations. How could I do that ?