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

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.

主站蜘蛛池模板: 内乡县| 景泰县| 前郭尔| 手机| 江城| 界首市| 札达县| 武邑县| 永安市| 望城县| 思茅市| 交口县| 漠河县| 进贤县| 邛崃市| 绵竹市| 电白县| 柳江县| 新泰市| 无为县| 宁安市| 离岛区| 高雄县| 礼泉县| 商洛市| 东兰县| 肥西县| 海安县| 桂阳县| 寿光市| 铁力市| 宜兰市| 沁阳市| 务川| 汤阴县| 游戏| 武穴市| 太谷县| 和平县| 平凉市| 龙岩市|