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

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.

主站蜘蛛池模板: 保康县| 奇台县| 城固县| 永福县| 张家口市| 涪陵区| 抚远县| 茌平县| 石棉县| 宁河县| 霍林郭勒市| 噶尔县| 同江市| 封开县| 都匀市| 二手房| 鸡东县| 兰考县| 宿州市| 临桂县| 东至县| 五大连池市| 衡阳市| 兴宁市| 民县| 商水县| 济源市| 砀山县| 辽中县| 阜新| 万源市| 邵阳县| 松原市| 万山特区| 中西区| 同心县| 汉川市| 稷山县| 马龙县| 滕州市| 门头沟区|