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

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.

主站蜘蛛池模板: 咸阳市| 油尖旺区| 台山市| 夹江县| 科尔| 常山县| 保山市| 香港 | 昔阳县| 鄂托克前旗| 平武县| 新源县| 平山县| 顺义区| 泸州市| 老河口市| 南华县| 田林县| 安徽省| 肇州县| 肇州县| 嘉义市| 竹溪县| 汪清县| 通渭县| 江陵县| 晋州市| 大余县| 清水县| 墨脱县| 金门县| 松桃| 修武县| 渭源县| 汝阳县| 青海省| 全南县| 武穴市| 高雄县| 朝阳区| 沾化县|