官术网_书友最值得收藏!

What is RxJS?

If we look at the RxJS documentation, we're greeted with the following definition: "ReactiveX is a library for composing asynchronous and event-based programs by using observable sequences" (http://reactivex.io/intro.html). At first glance, this is not exactly a description that makes us feel comfortable using this within our projects.

RxJS assists us in using reactive programming principles inside of our application, often referred to as a more declarative style rather than imperative. When we talk about an imperative programming style, we're usually telling the computer the exact steps of how to do a particular task. A declarative style allows us to focus more on the expected outcome rather than the implementation.

In JavaScript, we can create an event stream by using the following:

document.addEventListener('click', event => {
console.log(event);
});

This then allows us to observe any mouse clicks on the document. We can capture things such as the click coordinates, target, event type, and so on. Evidently, this is an asynchronous observable data stream. We don't know when someone is going to click the screen, nor do we care. All we do is observe and perform a particular action when that event occurs.

We can use RxJS to take these same principles and apply it to our modern day applications where everything is a stream. We could have an observable data stream of everything from a Facebook feed to document click events, timers, anything! Everything can be a stream.

主站蜘蛛池模板: 江口县| 商都县| 博兴县| 宁夏| 连州市| 聂荣县| 海南省| 萍乡市| 新郑市| 临江市| 霸州市| 延安市| 四川省| 临沂市| 滁州市| 库车县| 曲水县| 辉县市| 崇阳县| 扎兰屯市| 轮台县| 汕尾市| 漳浦县| 临潭县| 松溪县| 澄迈县| 肃宁县| 石首市| 油尖旺区| 金坛市| 武城县| 县级市| 秦皇岛市| 河津市| 武陟县| 蓝田县| 屏边| 江西省| 青冈县| 沈阳市| 太仆寺旗|