Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Mostly Front-end developers who are listening Reactive word first time they confuse it with React library. Actually it’s completely different.
Today I am going to explain about Reactive Programming and how to do it in JavaScript.
This article doesn’t go deep, it will help you to imagine the basic concepts of Reactive Programming and will help to find more good topics related to this article.
Before going to understand Reactive Programming, I would like to tell you about Imperative Programming.
What is Imperative Programming?
Imperative Programming is a programming paradigm that uses statements that change a program’s state.
Example of Imperative Programming
It means that t is assigned the result of n+m
Later the values of n and/or m, can be changed with no effect on the value of variable t.
What is Reactive Programming?
Reactive Programming is a declarative programming paradigm concerned with data streams and the propagation of change.
If we try previous example using Reactive paradigm, the result will look like this
This is not working example (easy to understand)
Here is a working simple example using RxJS library with Node
As you see, in Reactive Programming, on the value of variable t is automatically updated whenever the values of n changes, without the program having to re-execute.
It’s common to use the $ suffix to qualify variables that mean as a streams.
Reactive Programming is programming with asynchronous data streams.
What is Stream?
Streams are a sequence of values over time.
It means a Stream is simply a collection that arrives over time.
More about Stream herehttps://www.youtube.com/watch?v=UHI0AzD_WfY
ReactiveX
This is a rewrite of Reactive-Extensions.An API for asynchronous programming with observable streams.
Rx has many libraries for different programming languages.
RxJS
https://github.com/ReactiveX/rxjs
Lodash for async.
It’s the most popular library for JavaScript which helps to do Reactive Programming.
RxJS has many operators which helps to do Reactive things more faster, also has many operators which works with DOM elements.
redux-observable
https://redux-observable.js.org/
RxJS 5-based middleware for Redux.
redux-observable helps to do asynchronous actions using Redux library like redux-saga or redux-thunk.
Summary
Learning RxJS and starting to use it is not very easy for beginners, because to start understanding how it works and how you can use it, you will need to spend more time on investigation and learning more to start using it in your project.You don’t need use RxJS everywhere in your project, just you need to understand where and in which situation you can use it and resolve your issues more effective.
Thanks for reading my first article, If you have any questions or anything to say feel free.
Good sourcesRxJS 5: https://www.youtube.com/watch?v=COviCoUtwx4redux-observable: https://www.youtube.com/watch?v=AslncyG8whgCrash Course: https://www.youtube.com/watch?v=ei7FsoXKPl0
The websites from where I have used sources for this articlereactivex.io, Wikipedia
Reactive Programming was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.