码迷,mamicode.com
首页 > Web开发 > 详细

[Recompose] Merge RxJS Button Event Streams to Build a React Counter Component

时间:2017-12-22 20:48:48      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:tin   https   handler   sso   hand   oms   less   from   through   

Combining input streams then using scan to track the results is a common scenario when coding with streams. This lesson walks you through setting up two buttons and merging their input events together to build a streaming Counter component.

 

const CounterStream = componentFromStream(
  props$ => {

    const { stream: onInc$, handler: onInc } = createEventHandler();
    const { stream: onDec$, handler: onDec } = createEventHandler();

    return props$
      .switchMap(
      propos => Observable.merge(
        onInc$.mapTo(1),
        onDec$.mapTo(-1)
      )
        .startWith(propos.value)
        .scan((acc, curr) => acc + curr)
        .map((value) => ({ value, onInc, onDec })))
      .map(
      Counter
      )
  }
);

 

 

[Recompose] Merge RxJS Button Event Streams to Build a React Counter Component

标签:tin   https   handler   sso   hand   oms   less   from   through   

原文地址:http://www.cnblogs.com/Answer1215/p/8087375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!