- 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.
推薦閱讀
- Windows Vista基礎(chǔ)與應(yīng)用精品教程
- Ansible權(quán)威指南
- Microsoft Operations Management Suite Cookbook
- 網(wǎng)絡(luò)操作系統(tǒng)教程:Windows Server 2016管理與配置
- VMware NSX Cookbook
- 突破平面3ds Max動畫設(shè)計與制作
- Ceph分布式存儲實戰(zhàn)
- 一學(xué)就會:Windows Vista應(yīng)用完全自學(xué)手冊
- OpenStack系統(tǒng)架構(gòu)設(shè)計實戰(zhàn)
- INSTANT Galleria Howto
- Linux系統(tǒng)最佳實踐工具:命令行技術(shù)
- Mastering Windows 8 C++ App Development
- Linux 從入門到項目實踐(超值版)
- 統(tǒng)信UOS應(yīng)用開發(fā)進階教程
- VMware vSphere 5.1 Cookbook