All files / src/connect mergeProps.js

100% Statements 17/17
75% Branches 6/8
100% Functions 7/7
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x     77x       1x 1x 1x 1x 1x 5x 5x 4x 4x   1x 1x     5x           1x           40x 38x                
import shallowEqual from './utils/shallowEqual';
 
export function defaultMergeProps(stateProps, sendProps, ownProps) {
  return { ...ownProps, ...stateProps, ...sendProps }
}
 
export function wrapMergePropsFunc(mergeProps) {
  return function initMergePropsProxy() {
    let hasRunOnce = false
    let mergedProps
    const areMergedPropsEqual = shallowEqual;
    return function mergePropsProxy(stateProps, sendProps, ownProps) {
      const nextMergedProps = mergeProps(stateProps, sendProps, ownProps)
      if (hasRunOnce) {
        Eif (!areMergedPropsEqual(nextMergedProps, mergedProps))
          mergedProps = nextMergedProps
      } else {
        hasRunOnce = true
        mergedProps = nextMergedProps
      }
 
      return mergedProps
    }
  }
}
 
export function whenMergePropsIsFunction(mergeProps) {
  return (typeof mergeProps === 'function')
    ? wrapMergePropsFunc(mergeProps)
    : undefined
}
 
export function whenMergePropsIsOmitted(mergeProps) {
  return (!mergeProps)
    ? () => defaultMergeProps
    : undefined
}
 
export default [
  whenMergePropsIsFunction,
  whenMergePropsIsOmitted
]