- Mastering Reactive JavaScript
- Erich de Souza Oliveira
- 186字
- 2021-07-09 20:33:08
Changes in an observable
In the last section, we saw how to use the scan() method to create a Property from an EventStream. When we use this method (actually, when we use any operator), we do not change the original observable; we always create a new observable. So, it never interferes with the other subscriptions (and transformations) of the observable. We can change the previous code to listen to events on both the EventStream and the Property; now we will see that making changes in one of these two doesn't affect the other:
var eventStream = Bacon
.sequentially(100,['a','b','c','d']);
eventStream.onValue((value)=>{
console.log('From the eventStream :'+value);
});
var property = eventStream.scan('=> ',(acc,b)=> acc+b);
property.onValue((value)=>{
console.log('From the property :'+value);
});
It gives the following output:
From the property :=>
From the eventStream :a
From the property :=> a
From the eventStream :b
From the property :=> ab
From the eventStream :c
From the property :=> abc
From the eventStream :d
From the property :=> abcd
This shows that the usage of the scan() method to concatenate the array in the Property does not change the behavior of the original eventStream.
推薦閱讀
- Cybersecurity:Attack and Defense Strategies
- PLC控制程序精編108例
- Linux操作系統基礎
- BPEL and Java Cookbook
- Mastering Distributed Tracing
- Learn Helm
- Linux Shell編程從入門到精通(第2版)
- Mobile First Design with HTML5 and CSS3
- 無蘋果不生活 The New iPad隨身寶典
- 跟老男孩學Linux運維:Shell編程實戰
- Kali Linux高級滲透測試(原書第3版)
- 大規模分布式系統架構與設計實戰
- Zabbix監控系統之深度解析和實踐
- Linux內核分析及應用
- Linux系統安全:縱深防御、安全掃描與入侵檢測