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

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.

主站蜘蛛池模板: 泉州市| 恩平市| 延吉市| 武陟县| 城口县| 齐齐哈尔市| 汾阳市| 遵义县| 呼伦贝尔市| 平定县| 普安县| 海兴县| 松潘县| 收藏| 玉门市| 东山县| 玛沁县| 常山县| 梧州市| 平湖市| 丹寨县| 吉木乃县| 白山市| 绥宁县| 泸定县| 绥中县| 辉南县| 新沂市| 甘南县| 苍南县| 武乡县| 洛扎县| 轮台县| 永宁县| 凌源市| 合阳县| 来宾市| 宁远县| 宿迁市| 阿坝| 乐业县|