[Recompose] Handle React Events as Streams with RxJS and Recompose

Events are the beginning of most every stream. Recompose provides a createEventHandler function to help your create handler and stream pairs. Once the handler/stream pairs are created, it’s simply a matter of passing the handlers down the stream as props and combining the streams any way you want.

 

const SimpleFormStream = componentFromStream(
  props$ => {
    const {
      stream: onInput$,
      handler: onInput
    } = createEventHandler();

    const text$ = onInput$
      .map(e => e.target.value)
      .debounceTime(500)
      .switchMap(text => createTypeWrite(text))
      .startWith("");

    return text$
 
      .map(text => ({ text, onInput }))
      .map(SimpleForm) 
  }
)

 

 

posted @ 2017-12-22 03:59  Zhentiw  阅读(214)  评论(0编辑  收藏  举报