[Recompose] Make Reusable React Props Streams with Lenses

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Recompose] Make Reusable React Props Streams with Lenses相关的知识,希望对你有一定的参考价值。

If you hard-code a stream of props to target a specific prop, it becomes impossible to reuse that stream with any other components. Configuring your props stream with lenses will allow you to reuse your stream with any React component.

 

Checkout: lensProp, lensPath.

const personNameLens = R.lensPath([
  "person",
  "name"
])

const typewriter = lens =>
  mapPropsStream(props$ =>
    props$.switchMap(
      props =>
        Observable.zip(
          Observable.from(R.view(lens, props)),
          Observable.interval(100),
          letter => letter
        ).scan((acc, curr) => acc + curr),
      (props, name) => R.set(lens, name, props)
    )
  )

 

const DateDisplay = props => <h1>{props.date}</h1>
const dateLens = R.lensProp("date")
const DateTypewriter = typewriter(dateLens)(
  DateDisplay
)

 

 

以上是关于[Recompose] Make Reusable React Props Streams with Lenses的主要内容,如果未能解决你的问题,请参考以下文章

java http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html

java http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html

java http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html

xml http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html

xml http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html

[Recompose] Lock Props using Recompose -- withProps