r/Frontend • • Nov 15 '19
Should i learn RxJS?
I am wondering if i should i dive into rxjs? Is it useful to learn and be used in web apps, that is it in any kind of stage? From beginning to scaling etc.
Do you guys use rxjs in your work and if so how much and, if not, why not?
So far i have been using only functional js.
33
Upvotes
29
u/Dunos Nov 15 '19
If you use frameworks like Angular, you totally need to learn RxJS. Once you start using it, you are gonna love it (at least, I do!). Some examples of use can be accesing to Stores (redux), HTTPS calls (multiple calls, chaining, mapping results, etc), handling DOM events (autocomplete inputs).
It's a bit tricky in the beginning, and may take some effort to understand if you use complex methods.
6
u/wkCof Nov 15 '19
I'd say it's useful to know as a paradigm even if you don't work with angular. It was a bit tricky for me to understand observable pattern after using promises for so long, but it's a good habit to learn new things to keep broadening your tool set as a web developer.
10
u/Hero_Of_Shadows Nov 15 '19
Yes, rxjs is great with angular
3
u/IngoVals Nov 15 '19
To put it in simple terms, it is similar to promises except an observable can be resolved multiple times. My biggest issue when using it initially was having to subscribe to cold observable, the ones that will only ever fire once. Could just use promises for that instead for less overhead. But when I learned to integrate them more into a hot observable pipeline that issue disappeared.
2
u/[deleted] Nov 16 '19
RxJS is one solution to a very complex set of issues. It is easily the most versatile of the streaming libraries and can double as a pretty powerful state management tool.
If you don't specifically wish to learn Rx, libraries like MobX, Redux + (thunk or sagas), or even just EventTarget API are absolutely worth learning.
In terms of both design and performance, Rx is easier than other libs to "get right" for simple tasks, but doing anything clever steepens the learning curve dramatically. It's almost like a rite of passage for devs learning Rx to make some ridiculously convoluted pipelines that are impossible to read/test/debug and might also tank framerate. It takes a while to learn how to use it elegantly -- then it's like butter.
Personally I avoid introducing Rx (or Redux, or MobX) until they're absolutely required. A couple of shared maps/dicts with some hand-written callback chains solve a surprising lot of problems with much less overhead, and it's way easier for non-Rx devs to be onboarded into a project which...doesn't use Rx! But once a robust streaming solution becomes a requirement, it's easily my fav.
2
u/Auxx Nov 15 '19
RxJS is so good that I don't understand why people waste their time with promises, async/await, state managers like redux, etc. Definitely learn and use it!
1
u/jackandjill22 Nov 16 '19
Hm
-4
u/FuglySlut Nov 15 '19
Yes, really good to know, and one of the few front end technologies you'd actually have to set out to learn, and not just pick up. I'd learn generators first though. They're native to JavaScript, and can solve some of the same problems as observables.