- 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>
- 電腦組裝與系統安裝
- pcDuino開發實戰
- Linux設備驅動開發詳解(第2版)
- 發布!設計與部署穩定的分布式系統(第2版)
- Linux集群和自動化運維
- Java EE 8 Design Patterns and Best Practices
- Instant Optimizing Embedded Systems using Busybox
- 竹林蹊徑:深入淺出windows驅動開發
- 嵌入式系統原理及開發
- Learning Bootstrap
- Advanced TypeScript Programming Projects
- ElasticSearch Cookbook
- 精解Windows 10
- Windows 10從新手到高手
- 從實踐中學習Windows滲透測試