DEV Community

Cover image for πŸ™…β€β™‚οΈ Stop trying to learn RxJS

πŸ™…β€β™‚οΈ Stop trying to learn RxJS

Richard Tong on June 09, 2020

If you have any interest in RxJS, this article is for you. If you have no idea what RxJS is, I advise you not to worry about it and check out rubic...
Collapse
 
anduser96 profile image
Andrei Gatej

Have you tried reading RxJS’ source code? I bet you’ll learn a lot more than you’d do with diagrams. Even more, it won’t seem that difficult!

Collapse
 
richytong profile image
Richard Tong

is there a particular spot in RxJS' source code you found to be helpful for learning RxJS?

Collapse
 
anduser96 profile image
Andrei Gatej

I’d say everything. It’s all about linked lists and OOP concepts. It may seem a lot, but it’s the same pattern used almost across the entire library.

Thread Thread
 
richytong profile image
Richard Tong

Okay, I'll do that, thanks.

Thread Thread
 
anduser96 profile image
Andrei Gatej

Awesome! I’m sure it will be a fun journey.

I’d recommend creating an rxjs project in StackBlitz and try to debug the sources right there. With stackblitz you can debug the TS files.

I’d be glad to help if you’ll have questions! Good luck

Thread Thread
 
richytong profile image
Richard Tong

I have a couple questions, Andrei. How did you get into RxJS? How has it helped you in your work?

Collapse
 
bjesuiter profile image
Benjamin Jesuiter

Hey @richard Tong,
thanks for this interesting perspective.

I will look into rubico and, if i have time / find something interesting, give you some feedback on this.

I found your post while searching for a state management solution for deno.
I also do have some custom rxjs operators published on npm, so I think, I can nicely compare the two experiences.

Rubico sounds interesting for me, since the idea of 'using the platform' is also my main paradigm right now.
But I also wonder whether rubico will be a real complete (or neraly complete, maybe without edge cases) replacement for the vast functionalities build into rxjs.

Let's see! Anyway, thanks for the post!

Collapse
 
richytong profile image
Richard Tong

Hey Benjamin, thanks for the comment. I think you're right - rubico has a long way to go. Actually I was just on my way to implementing some stuff I have on its roadmap, since today my day is light. Cheers

Collapse
 
qm3ster profile image
Mihail Malo • Edited
  1. How do you make a lossy iterable for late binding that keeps the latest value? (BehaviorSubject in RxJS)
  2. What is your solution to forking the stream? (multicast in RxJS)
  3. Can you clarify what is hard to learn about RxJS?
  4. "property functions" like map.pool are bad for treeshaking.
  5. why is your compose called pipe :v
Collapse
 
daviddomingoslalom profile image
David Domingo

Hey @richytong I like the design of your API, I do find it more intuitive, but I also like RxJS's design as well. You keep mentioning the "Why" and I suspect it's probably due to a very famous TED talk. If you absolutely need the why, just have in mind that RxJS is an implementation of reactivex in JS:

reactivex.io/intro.html

You can find the "why" of reactivex in the website above. For the why of RxJS, just add "in Javascript" at the very end.

On the topic of map, concatMap, exhaustMap, mergeMap and switchMap all have their place and are useful in their own way. I'm not sure about how I would use them in the backend but I constantly use them on the frontend in different scenarios. Especially switchMap.

Collapse
 
hulaprose profile image
hula-prose

Very interesting work. Thank you for your effort and sharing.

Curious how to create event streams in rubico as RxJS fromEvent() does. Tried to find it from the documentation and tutorials but couldn't. Sample code snippets or mention in documentation will be helpful as it was the most exciting feature to me. If event streams could be handled as in RxJS, then rubico will be the winning FRP framework for my next big project.

Collapse
 
artydev profile image
artydev • Edited

A starting point perhaps :

const { pipe } = rubico


function fromEvent(event, tranformation) {
  document.addEventListener(event,  function (e) {
     tranformation(e)
  })
}

const logx = (e) => pipe([(x) =>  {  
  document.body.style.background = x < 500 ? "blue" : "red"
  return x
}, console.log])(e.x)

fromEvent("mousemove", logx)
Enter fullscreen mode Exit fullscreen mode

DEMO