Article

Should I Use RxJS in My Project?

RxJS-logo

If you’re thinking about using RxJS, you might as well be asking, “Should I use a jump kick in a street fight?” Unless you are Bruce Lee, probably not.

As a disclaimer, I am not an RxJS pro. I only started learning about it a couple of weeks ago. Consider this post a record of my thoughts as I begin to learn about this powerful library.

According to their website, RxJS is a library for composing asynchronous and event-based programs by using observable sequences. I have been researching whether or not this would be a good fit for one of our current projects. 

So, Is It Worth It?

Front-end Dev Lead Elisha and I discuss RxJS in a recent video:

I’ve heard that once your brain gets plugged into the stream everything will begin to make sense and you’ll eventually reach the promised land. But until you reach that point, it’s a dangerous path, as there are many wrong ways to do things. If you have not yet reached RxJS enlightenment, you might fall into such anti-patterns like the nested subscribe pattern or imperative subscription management.

However, if you can avoid these mistakes and learn some of the commonly used operators like map, filter, do, mergeMap, and switchMap, you’ll be in decent shape. It also helps to visualize observables as marbles of events floating down a stream of time. And RxJS provides a multitude of operators to help you manage those streams. So far, I’ve only learned a handful, but they were enough to get a simple photo search dropdown working with infinite scroll, http cancellation, and debounced input.

So that brings us to the original question.

Should I Use RxJS in My Project?

Well, like many other questions, the answer is: It depends. Do you have the time and budget to learn this new tool which is known to have a steep learning curve? Will your project have complex async requirements that RxJS may bring clarity to? Are you using Angular2, which comes with RxJS out of the box? Will your current framework and lodash suffice for your needs? After reading numerous articles, watching tutorial videos, and building a simple proof of concept, I came to the conclusion that, while RxJS could make my life easier, time spent learning RxJS would add up to unnecessary overhead for a typical CRUD web app project.

RxJS is indeed a powerful tool, and I have only begun to see its potential. I may revisit this library in the future, but, for now, I haven’t encountered a project where the efficiency benefits outweigh the the cost of learning and implementing it.

Travis-Luong-Default-BW_optimize.jpg

Travis Luong

Full-Stack Developer

Travis is a Full-Stack Developer with 5 years of professional programming experience. Having worked as a freelance consultant, web contractor, and full-time engineer prior to joining Fresh, he excels at both server-side and client-side web development. While his expertise is in Ruby on Rails and Javascript, Travis is familiar with a variety of tools, languages, and frameworks. Most recently, he has worked on web and mobile apps for CBRE and Fornetix.