The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Render on the DOM with RxJS

Render on the DOM with RxJS

5:22
Learn how to take data from a network response and display it on the DOM using RxJS reactive event streams.
Watch this lesson now
Avatar
egghead.io

Learn how to take data from a network response and display it on the DOM using RxJS reactive event streams.

Avatar
br9191fr

Hello
I have one question. In line 15 the argument to the map function is listUser => user (ie [elt] => elt)
I thought that the argument of a map function should be elt => elt

Did i missed something ?

Thanks in advance

In reply to egghead.io
Avatar
Roc

Hi,

First of all, thanks for this series and the very good explanation of each of the concepts.

In this example, it seems that if I wanted to show 100 users instead of 3 the only way to do it would be something like this:

for (let i = 0; i < 100; i++) {
  createSuggestionStream(responseStream).subscribe(user => {
    renderSuggestion(user, `suggestion${i}`);
  });
}

Is this the only way or there is a way of doing this that leverages the functional approach of RxJS?

In reply to egghead.io
Avatar
Roc

As I understand it, this map is a map over the EventStream "array" of RxJS and the value, in this case, happens to be an array also and that's why listUser is an array.

In reply to br9191fr
Avatar
Roc

Omg, the comment posting didn't include my code, It was just a typical for(i=0, i<100, i++) and inside the for just a createSuggestionStream(responseStream).subscription(...).

And thanks in advance!

In reply to Roc
Avatar
Andre

Hi Roc, there is nothing wrong in using a for loop to create many suggestion streams and subscribe to them, it doesn't break the "functional" pattern. On the other hand if we were to create a hundred suggestions on the UI, we could make a stream listOfSuggestedUsers$ which emits an array of all those 100, and in its subscribe we would create elements for each.

In reply to Roc
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?