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

The bacon.js observables

In functional reactive programming, an observable is an object where you can listen for events. This way, you can, for instance, create an observable for a button and then listen and act when a click happens.

The bacon.js gives you two flavors of an observable: the first one is EventStream and the other is Property. We will see the difference between the two objects later. To listen to events in an observable (or subscribe to an observable), you can use the onValue()method with a callback. So if you want to log every event in an EventStream, you can use the following code:

myEventStream.onValue(function(event){ 
console.log(event);
});
We will see how to create an EventStream in more detail later.

As we saw in the example in the last chapter, we can transform our observable using bacon.js operators. These operators let us filter, combine, map, buffer, and do a lot of other interesting things with our EventStream.

An observable can either finish or stay open to propagate events forever; it can also contain (and propagate) errors. We will see this in more detail later.

主站蜘蛛池模板: 镇远县| 沛县| 武威市| 福安市| 确山县| 盘锦市| 县级市| 卢龙县| 比如县| 中方县| 石景山区| 盐山县| 嘉黎县| 永定县| 疏勒县| 承德市| 天峻县| 桐柏县| 巴楚县| 张家口市| 仙桃市| 方城县| 富宁县| 金平| 调兵山市| 虹口区| 岚皋县| 杭州市| 泌阳县| 澄迈县| 桐梓县| 镇雄县| 灵寿县| 扎兰屯市| 金溪县| 新邵县| 安仁县| 大同县| 乌审旗| 刚察县| 凌云县|