- 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.
推薦閱讀
- Mastering ElasticSearch
- Implementing Cisco UCS Solutions
- Puppet實戰
- 無蘋果不生活 OS X Mountain Lion隨身寶典
- 高性能Linux服務器構建實戰:系統安全、故障排查、自動化運維與集群架構
- Windows 7中文版從入門到精通(修訂版)
- 無蘋果不生活 The New iPad隨身寶典
- INSTANT Migration from Windows Server 2008 and 2008 R2 to 2012 How-to
- Hands-On GPU Programming with Python and CUDA
- Learn CUDA Programming
- Windows 10從新手到高手
- OpenHarmony開發與實踐:基于紅莓RK2206開發板
- 基于Arduino的嵌入式系統入門與實踐
- Docker容器技術與運維
- Windows 10從入門到精通