官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 大同市| 西盟| 黑河市| 寿阳县| 平原县| 湄潭县| 轮台县| 景泰县| 克拉玛依市| 子洲县| 南乐县| 西乌珠穆沁旗| 沁水县| 马山县| 富锦市| 滁州市| 广元市| 泊头市| 大新县| 开远市| 滕州市| 克拉玛依市| 罗山县| 犍为县| 南岸区| 阳新县| 巴彦县| 丰县| 黄龙县| 金阳县| 克拉玛依市| 茶陵县| 诸城市| 台山市| 磐石市| 台中市| 维西| 神池县| 漯河市| 甘谷县| 葫芦岛市|