DEV Community


Discussion on: Vanilla JavaScript vs. RxJs

riccardoodone profile image
Riccardo Odone Author • Edited

However, an api request, a call via fetch, is fundamentally a single in and a single out.

It doesn't have to be, it can be a response stream:


const response = await fetch(url);
const reader = response.body.getReader();

while (true) {
  const { value, done } = await;
  if (done) break;
  console.log('Received', value);

console.log('Response fully received');
Enter fullscreen mode Exit fullscreen mode

However, I agree most of the time it's not used that way. Still, treating everything as a stream has the advantage of making things composable and re-usable.

In any case, I'm not advocating for any approach. I should have made it more clear in the post. Also, you are right, I could have used async/await in the vanilla JavaScript code to make it look cleaner.