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

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.

主站蜘蛛池模板: 克东县| 苍南县| 澄江县| 仁怀市| 绥芬河市| 永济市| 甘谷县| 石楼县| 栾川县| 固原市| 繁昌县| 全州县| 青龙| 阳信县| 蒲城县| 紫阳县| 满城县| 庄河市| 普陀区| 拜城县| 盐亭县| 左云县| 彩票| 达尔| 黔西县| 陆河县| 贺州市| 青浦区| 荔波县| 丹阳市| 兰考县| 瓦房店市| 综艺| 什邡市| 九台市| 徐闻县| 新建县| 延边| 顺昌县| 昌都县| 南昌市|