1 | import verifyPlainObject from '../utils/verifyPlainObject'
|
2 |
|
3 | export function defaultMergeProps(stateProps, dispatchProps, ownProps) {
|
4 | return { ...ownProps, ...stateProps, ...dispatchProps }
|
5 | }
|
6 |
|
7 | export function wrapMergePropsFunc(mergeProps) {
|
8 | return function initMergePropsProxy(
|
9 | dispatch,
|
10 | { displayName, pure, areMergedPropsEqual }
|
11 | ) {
|
12 | let hasRunOnce = false
|
13 | let mergedProps
|
14 |
|
15 | return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
|
16 | const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps)
|
17 |
|
18 | if (hasRunOnce) {
|
19 | if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps))
|
20 | mergedProps = nextMergedProps
|
21 | } else {
|
22 | hasRunOnce = true
|
23 | mergedProps = nextMergedProps
|
24 |
|
25 | if (process.env.NODE_ENV !== 'production')
|
26 | verifyPlainObject(mergedProps, displayName, 'mergeProps')
|
27 | }
|
28 |
|
29 | return mergedProps
|
30 | }
|
31 | }
|
32 | }
|
33 |
|
34 | export function whenMergePropsIsFunction(mergeProps) {
|
35 | return typeof mergeProps === 'function'
|
36 | ? wrapMergePropsFunc(mergeProps)
|
37 | : undefined
|
38 | }
|
39 |
|
40 | export function whenMergePropsIsOmitted(mergeProps) {
|
41 | return !mergeProps ? () => defaultMergeProps : undefined
|
42 | }
|
43 |
|
44 | export default [whenMergePropsIsFunction, whenMergePropsIsOmitted]
|