Rather than using Components to push streams into other Components, mapPropsStream allows you to create functions that can wrap components to create shareable behaviors across components.

Using componentFromStream:

import React from "react"
import { render } from "react-dom"
import { Observable } from "rxjs"
import config from "recompose/rxjsObservableConfig"
import {
setObservableConfig,
componentFromStream,
createEventHandler,
mapPropsStream
} from "recompose" setObservableConfig(config)
//#endregion const Counter = props => <h1>{props.count}</h1> const CounterWithInterval = componentFromStream(
props$ => props$.switchMap(
props => Observable.interval(1000),
(props, count) => ({count, ...props})
)
.map(Counter)
) const App = () => (
<div>
<CounterWithInterval />
</div>
) render(<App />, document.getElementById("root"))

MapPropsStream allows you to create functions that will decorate your component, rather than creating a component itself. I'm going to create an interval here using MapPropsStream.

A mapProposStream version can be like this:

import React from "react"
import { render } from "react-dom"
import { Observable } from "rxjs"
import config from "recompose/rxjsObservableConfig"
import {
setObservableConfig,
componentFromStream,
createEventHandler,
mapPropsStream
} from "recompose" setObservableConfig(config)
//#endregion const Counter = props => <h1>{props.count}</h1> const interval = mapPropsStream(props$ => props$.switchMap(
props => Observable.interval(1000),
(props, count) => ({ count, ...props })
)) const CounterWithInterval = interval(Counter) const App = () => (
<div>
<CounterWithInterval />
</div>
) render(<App />, document.getElementById("root"))

As you can see, we take the hightlighted part as own function, wrapped with 'mapPropsStream'.

[Recompose] Create Stream Behaviors to Push Props in React Components with mapPropsStream的更多相关文章

  1. [React] Recompose: Theme React Components Live with Context

    SASS Bootstrap allows us to configure theme or branding variables that affect all components (e.g. P ...

  2. [React] Create and import React components with Markdown using MDXC

    In this lesson I demonstrate how to use the library MDXC to create and import React components with ...

  3. [Recompose] Stream Props to React Children with RxJS

    You can decouple the parent stream Component from the mapped React Component by using props.children ...

  4. [Recompose] Configure Recompose to Build React Components from RxJS Streams

    Recompose provides helper functions to stream props using an Observable library of your choice into ...

  5. Akka(18): Stream:组合数据流,组件-Graph components

    akka-stream的数据流可以由一些组件组合而成.这些组件统称数据流图Graph,它描述了数据流向和处理环节.Source,Flow,Sink是最基础的Graph.用基础Graph又可以组合更复杂 ...

  6. [React] Create a Query Parameter Modal Route with React Router

    Routes are some times better served as a modal. If you have a modal (like a login modal) that needs ...

  7. [React] Make Controlled React Components with Control Props

    Sometimes users of your component want to have more control over what the internal state is. In this ...

  8. [Recompose] Stream a React Component from an Ajax Request with RxJS

    Loading data using RxJS is simple using Observable.ajax. This lesson shows you how to take the ajax ...

  9. [React Native] Create a component using ScrollView

    To show a list of unchanging data in React Native you can use the scroll view component. In this les ...

随机推荐

  1. HDU 1505 City Game【DP】

    题意:是二维的1506,即在1506的基础上,再加一个for循环,即从第一行到最后一行再扫一遍--- 自己写的时候,输入的方法不对---发现输不出结果,后来看了别人的----@_@发现是将字母和空格当 ...

  2. 织梦(dedecms)循环调用多级子栏目如二级栏目下三级栏目

    本文是关于织梦DedeCMS调用多级子栏目的,拿来分享下. 后台已经建好栏目,对于产品展示栏 栏目导航如下图所示:  复制代码 代码如下: {dede:channelartlist cacheid=' ...

  3. BZOJ 3790 神奇项链(manacher+贪心)

    3790: 神奇项链 Time Limit: 10 Sec  Memory Limit: 64 MB Description 母亲节就要到了,小 H 准备送给她一个特殊的项链.这个项链可以看作一个用小 ...

  4. JavaScript函数写法整理

    1.普通函数定义的两种写法 function hello(){ console.log("hello!"); } var hello = function(){ console.l ...

  5. System.IO.IsolatedStorage 使用 IsolatedStorageFileStream 存储信息

    在C#中还有一种叫做IsolatedStorage的存储机制,他存储信息的方式类似于我们的cookie, IsolatedStorage存储独立于每一个application,换句话说我们加载多个应用 ...

  6. C语言回调

    来源:https://www.cnblogs.com/jiangzhaowei/p/9129105.html 1. 什么是回调函数? 回调函数,光听名字就比普通函数要高大上一些,那到底什么是回调函数呢 ...

  7. 洛谷 P1702 突击考试

    P1702 突击考试 题目描述 一日,老师决定进行一次突击考试.已知每个学生都有一个考试能力等级,教室里一共有N个课桌,按照顺序排成一列,每张课桌可以坐两个人,第i张课桌坐的两个人的能力等级为(A[i ...

  8. HDU 4965 Fast Matrix Calculation(矩阵高速幂)

    HDU 4965 Fast Matrix Calculation 题目链接 矩阵相乘为AxBxAxB...乘nn次.能够变成Ax(BxAxBxA...)xB,中间乘n n - 1次,这样中间的矩阵一个 ...

  9. Random numbers

    Most computer programs do the same thing every time they execute, given the same inputs, so they are ...

  10. The python programing language

    Python is an example of high-level language. As you might infer from the name “high-level language”, ...