- 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.
- Cybersecurity:Attack and Defense Strategies
- 精通Linux內(nèi)核開發(fā)
- Windows Phone 7.5 Data Cookbook
- 高性能Linux服務(wù)器構(gòu)建實戰(zhàn):系統(tǒng)安全、故障排查、自動化運維與集群架構(gòu)
- Joomla! 3 Template Essentials
- 無蘋果不生活 The New iPad隨身寶典
- Ceph分布式存儲實戰(zhàn)
- 計算機系統(tǒng)的自主設(shè)計
- 從實踐中學(xué)習(xí)Windows滲透測試
- Linux軟件管理平臺設(shè)計與實現(xiàn)
- OpenVZ Essentials
- OpenHarmony開發(fā)與實踐:基于紅莓RK2206開發(fā)板
- Windows 8完全自學(xué)手冊
- BuddyPress Theme Development
- Serverless Architectures with Kubernetes