Passed
Push — master ( 4c2534...c3984e )
by Christiaan
54s queued 10s
created

src/createConnect.js

Complexity

Total Complexity 0
Complexity/F 0

Size

Lines of Code 21
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 12
mnd 0
bc 0
fnc 0
dl 0
loc 21
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from 'react'
2
import { compose } from 'ramda'
3
4
import fromRenderProps from './fromRenderProps'
5
import setHocDisplayName from './setHocDisplayName'
6
import { stateToProps } from './stateToProps'
7
8
/**
9
 * This function creates a HOC for connect the given global store context to the given Component.
10
 * Only the props provided through the
11
 * @param {React.Context} GlobalStoreContext The global store context
12
 * @function
13
 * @return connect HOC
14
 */
15
export const createConnect = GlobalStoreContext => mapStateToProps => Component =>
16
  compose(
17
    setHocDisplayName('connect', Component),
18
    fromRenderProps(GlobalStoreContext.Consumer, stateToProps(mapStateToProps)), // connect with consumer
19
    React.memo // Do not unnessasary rerender
20
  )(Component)
21