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

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.

主站蜘蛛池模板: 阳西县| 弥勒县| 黎平县| 崇仁县| 泗洪县| 启东市| 金平| 南投县| 普定县| 丹江口市| 淮南市| 合作市| 进贤县| 榆林市| 闸北区| 峨眉山市| 巴彦县| 淅川县| 长阳| 射阳县| 普安县| 徐水县| 临沂市| 喜德县| 清原| 许昌市| 横山县| 台南县| 托克逊县| 台江县| 钟山县| 新津县| 聂荣县| 甘谷县| 沁水县| 南陵县| 民县| 景德镇市| 安徽省| 本溪市| 永年县|