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

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.

主站蜘蛛池模板: 西藏| 保靖县| 尼勒克县| 临城县| 玉龙| 鄄城县| 股票| 梧州市| 龙门县| 新竹县| 昭觉县| 卓资县| 和田县| 桐庐县| 辉县市| 监利县| 永川市| 澜沧| 临桂县| 西城区| 定安县| 阳泉市| 仁布县| 瓦房店市| 昭觉县| 南江县| 淮南市| 大余县| 凤山县| 新竹市| 托克逊县| 呼玛县| 永春县| 商城县| 夏津县| 保康县| 孝感市| 安图县| 丰镇市| 夏河县| 区。|