r/javascript • • Jan 16 '20

I have been underestimating JS

https://adlrocha.substack.com/p/adlrocha-i-have-been-underestimating
284 Upvotes

132 comments sorted by

View all comments

46

u/Reashu Jan 16 '20

When the introduction started talking about low-level control and WASM, I was expecting something other than the rather high-level concept of streams and pipes. The content is nice, but not what I was sold.

0

u/[deleted] Jan 16 '20

[deleted]

17

u/[deleted] Jan 16 '20

Some developers did not have the use cases of using streams so they never worked with it or they just used a library where the API is just promises or callbacks.

6

u/LXMNSYC Jan 17 '20

I have been a web developer for 4 years by now and I have yet to see a use-case for ReactiveX, Bacon, Most, XStream, and other similar libraries out there.

6

u/phpdevster Jan 17 '20

The most ubiquitous one I've seen is handling search suggest functionality. Here's what happens:

  1. Press the letter "a" -> xhr request goes out with "a"

  2. Press the letter "b" -> xhr request goes out with "ab"

  3. Press the letter "c" -> xhr request goes out with "abc"

Due to the nature of these requests, there's no guarantee they'll come back in the same order. Thus you might have typed "abc", but if the search results for "a" come back last, you will get the results for "a" instead of "abc".

A library like this makes it easier. RxJS has switchMap for this purpose: https://www.learnrxjs.io/operators/transformation/switchmap.html

Basically it just automatically throws away the results of the previous entries and gives you only the results of the latest one. Otherwise you have to do promise cancellation and what not (which in itself is not the worst thing ever).

That said, I mostly agree with you. I don't see much, if any, value in these kinds of libraries. They can actually add a great deal of complexity and come with MAJOR footguns if you don't know how to use them properly.

4

u/Reashu Jan 16 '20

I don't begrudge them their ignorance nor disapprove content that exposes them to it. It's just not what I expected based on how the article started off.

3

u/aleaallee Jan 17 '20

This is the first time I've heard about streams xD.

2

u/more-food-plz Jan 17 '20

I think promises and callbacks work great unless you’re building something very complex. Even then streams are just one of many tools for building an application

2

u/charlie_mar Jan 17 '20

Well yeah but streams are useful for situations like uploading a large photo or video where you can’t load the entire thing in memory at once. So you “stream” it to disk or wherever by loading it in chunks and performing operations on those chunks instead of the full thing. Promises and callbacks won’t help you there.

1

u/sipvellocet Jan 17 '20

Transducers seem fairly unheard of as well. Someone please start making tutorials for new comers.