- Mastering Reactive JavaScript
- Erich de Souza Oliveira
- 184字
- 2021-07-09 20:33:06
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);
});
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.
- Mastering vRealize Operations Manager(Second Edition)
- Learning Windows Server Containers
- 白話區(qū)塊鏈
- Kali Linux滲透測試全流程詳解
- 循序漸進(jìn)學(xué)Docker
- 嵌入式操作系統(tǒng)(Linux篇)(微課版)
- Linux運(yùn)維最佳實踐
- 嵌入式系統(tǒng)原理及開發(fā)
- Windows Server 2012網(wǎng)絡(luò)操作系統(tǒng)項目教程(第4版)
- Delphi Programming Projects
- NetDevOps入門與實踐
- Hands-On UX Design for Developers
- Linux基礎(chǔ)使用與案例
- Linux網(wǎng)絡(luò)配置與安全管理
- Learning Continuous Integration with Jenkins(Second Edition)