- 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修煉手冊
- Windows Server 2019 Cookbook
- 每天5分鐘玩轉Kubernetes
- 發(fā)布!設計與部署穩(wěn)定的分布式系統(tǒng)(第2版)
- 阿里云數(shù)字新基建系列:云原生操作系統(tǒng)Kubernetes
- Windows Phone應用程序開發(fā)
- Python基礎教程(第3版)
- 直播系統(tǒng)開發(fā):基于Nginx與Nginx-rtmp-module
- 完美應用RHEL 8
- Linux操作系統(tǒng)
- Hadoop Real-World Solutions Cookbook
- 統(tǒng)信UOS應用開發(fā)進階教程
- Android Telephony原理解析與開發(fā)指南
- Azure Serverless Computing Cookbook
- Microsoft DirectAccess Best Practices and Troubleshooting