Nowadays in this ocean of technologies can be confusing to choose to look to a new one, especially with a lot of new technologies coming every week.
Well, in that same ocean we can find ReactiveX, another trending technology that it’s being used by big companies like Netflix, Github & Microsoft, just to mention a few. But why bother to even look at it? anyways another trending technology will come the next week, right?
Basically, ReactiveX is a library that not only implements the observer pattern but also claims to extend it. Yes, I know that the text that you just read maybe doesn’t help to understand what ReactiveX is if you are not familiar with that pattern, so let me elaborate a little bit more, but first I will paste here the definition that we can find on their web page:
” ReactiveX is a library for composing asynchronous and event-based programs by using observable sequences. “
As you can see in the definition, this library (… and pattern) aims to help us on creating & maintaining our asynchronous code. That’s good news because modern apps are challenging developers to achieve a lot more under the hood to provide better user experience and the new tools rarely focus on helping the developers in that particular area.
While using ReactiveX you will have the Observer and Observable objects. The Observables takes some data, process it and then notifies to the Observers subscribed to that particular Observable, and then
you can do some other cool stuff that you like with that. That’s basically the observer pattern on ReactiveX.
Another concept that ReactiveX introduces is that any collection of data must be seen as a stream of data, even an array should be seen like a stream of data. That’s why you will see the marble diagrams to explain the data flow.
Marble Diagram from ReactiveX webpage
The Marble Diagrams are key to understand what’s going on with your data or how a particular function will behave. The Marble Diagrams are read from left to right and that arrow represents time.
The cool stuff
ReactiveX is multiplatform and has been ported to several languages and frameworks so, there’s no excuse to start playing with it on your favorite language. It’s very well documented and has a lot of cool helper functions for your asynchronous code like Debounce, Retry, SkipUntil, etc.
It also has a great growing community and as mentioned before some developers of big companies love ReactiveX, like Netflix, and the cool thing is that they are also contributing on making it more useful & robust.
The community also has released a lot of good tutorials & videos that makes it easy to understand the concepts. I also recommend to check the Netflix UI Engineering’s Youtube channel, there are some great videos with real problems solved using ReactiveX.
” The ReactiveX Observable model allows you to treat streams of asynchronous events with the same sort of simple, composable operations that you use for collections of data items like arrays. It frees you from tangled webs of callbacks, and thereby makes your code more readable and less prone to bugs. – http://reactivex.io/intro.html “
ReactiveX shines especially in web development, either on your frontend or your backend but it’s not limited to the web. This library can help too if you have several functions that must be run in an asynchronous fashion, maybe you’re waiting for another process/machine to send data or waiting for different threads to end their tasks. It will simplify the way you handle the results thus resulting in a more readable & maintainable code.
Either if your app is fetching the next page in a paginated view meanwhile the user is scrolling products or if you are consuming data streams from different sources in order to get a real-time dashboard, this library is for you. Don’t forget that even your backend can benefit from ReactiveX.
ReactiveX is relatively new and has been out there for at least 3 years. The future for this technology seems very bright, there are not many libraries that does the same or similar stuff that ReactiveX (can’t say the same about the front-end libraries) and is heavily used by big technology companies that currently invest on it, making it better.
The pattern and the key concepts are not that complex like in some other technologies (I’m looking at you Redux ¬¬ ) which means that the learning curve is very smooth and you will start using ReactiveX on your favorite language in a breeze. Totally worth taking a look.