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

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.

主站蜘蛛池模板: 彰化县| 枣庄市| 宕昌县| 阆中市| 平安县| 城固县| 抚远县| 娄底市| 健康| 平罗县| 岳池县| 威远县| 莱芜市| 漳浦县| 阿拉善左旗| 平湖市| 镶黄旗| 石泉县| 菏泽市| 宜兰县| 华坪县| 昭觉县| 河北省| 惠州市| 杭州市| 兴文县| 怀柔区| 宣恩县| 盐池县| 沙湾县| 黄大仙区| 安阳市| 清水县| 惠州市| 夏邑县| 琼海市| 穆棱市| 西乌珠穆沁旗| 虞城县| 呼和浩特市| 讷河市|