- Mastering Reactive JavaScript
- Erich de Souza Oliveira
- 183字
- 2021-07-09 20:33:10
Observables' lazy evaluation
In bacon.js, an observable doesn't emit any event unless someone is subscribed to listen to it. We can easily check this behavior using doAction(). This operator lets us run an arbitrary function every time an event is emitted from an observable.
If you create an observable from an array and add a doAction() operator to log your events then, without a subscription, it will print nothing to the console. So if you run the following code, you will see your program doesn't give you any output:
Bacon
.fromArray([1,2,3])
.doAction((value)=>
console.log('running doAction')
);
As you can see in this code, we have no subscriber for the EventStream. This is why no event is emitted. However, if we add a subscriber to this EventStream, we will see the program print running doAction for each value:
Bacon
.fromArray([1,2,3])
.doAction((value)=>
console.log('running doAction')
)
.log();
The preceding code gives you the following output:
running doAction
1
running doAction
2
running doAction
3
<end>
- Kubernetes修煉手冊(cè)
- Ansible權(quán)威指南
- Hands-On DevOps with Vagrant
- 精解Windows8
- Windows Vista融會(huì)貫通
- Linux網(wǎng)絡(luò)內(nèi)核分析與開發(fā)
- 異質(zhì)結(jié)原理與器件
- Linux使用和管理指南:從云原生到可觀測(cè)性
- Windows 7中文版從入門到精通(修訂版)
- Windows 8實(shí)戰(zhàn)從入門到精通(超值版)
- 從零開始學(xué)安裝與重裝系統(tǒng)
- Windows Vista終極技巧金典
- Windows Server 2008組網(wǎng)技術(shù)與實(shí)訓(xùn)(第3版)
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)踐教程(Windows 7+MS Office 2010)
- Agile IT Security Implementation Methodology