@@ -18,17 +18,6 @@ function getDisplayName(WrappedComponent) {
1818 return WrappedComponent . displayName || WrappedComponent . name || 'Component'
1919}
2020
21- function checkStateShape ( componentDisplayName , props , methodName ) {
22- invariant (
23- isPlainObject ( props ) ,
24- '`%s %s` must return an object. Instead received %s.' ,
25- componentDisplayName ,
26- methodName ,
27- props
28- )
29- return props
30- }
31-
3221// Helps track hot reloading.
3322let nextVersion = 0
3423
@@ -46,14 +35,25 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
4635 // Helps track hot reloading.
4736 const version = nextVersion ++
4837
49- function computeMergedProps ( componentDisplayName , stateProps , dispatchProps , parentProps ) {
50- const mergedProps = finalMergeProps ( stateProps , dispatchProps , parentProps )
51- return checkStateShape ( componentDisplayName , mergedProps , 'mergeProps' )
52- }
53-
5438 return function wrapWithConnect ( WrappedComponent ) {
5539 const connectDisplayName = `Connect(${ getDisplayName ( WrappedComponent ) } )`
5640
41+ function checkStateShape ( props , methodName ) {
42+ invariant (
43+ isPlainObject ( props ) ,
44+ '`%s %s` must return an object. Instead received %s.' ,
45+ connectDisplayName ,
46+ methodName ,
47+ props
48+ )
49+ return props
50+ }
51+
52+ function computeMergedProps ( stateProps , dispatchProps , parentProps ) {
53+ const mergedProps = finalMergeProps ( stateProps , dispatchProps , parentProps )
54+ return checkStateShape ( mergedProps , 'mergeProps' )
55+ }
56+
5757 class Connect extends Component {
5858 shouldComponentUpdate ( ) {
5959 return ! pure || this . haveOwnPropsChanged || this . hasStoreStateChanged
@@ -86,7 +86,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
8686 this . finalMapStateToProps ( state , props ) :
8787 this . finalMapStateToProps ( state )
8888
89- return checkStateShape ( connectDisplayName , stateProps , 'mapStateToProps' )
89+ return checkStateShape ( stateProps , 'mapStateToProps' )
9090 }
9191
9292 configureFinalMapState ( store , props ) {
@@ -98,7 +98,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
9898
9999 return isFactory ?
100100 this . computeStateProps ( store , props ) :
101- checkStateShape ( connectDisplayName , mappedState , 'mapStateToProps' )
101+ checkStateShape ( mappedState , 'mapStateToProps' )
102102 }
103103
104104 computeDispatchProps ( store , props ) {
@@ -111,7 +111,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
111111 this . finalMapDispatchToProps ( dispatch , props ) :
112112 this . finalMapDispatchToProps ( dispatch )
113113
114- return checkStateShape ( connectDisplayName , dispatchProps , 'mapDispatchToProps' )
114+ return checkStateShape ( dispatchProps , 'mapDispatchToProps' )
115115 }
116116
117117 configureFinalMapDispatch ( store , props ) {
@@ -123,7 +123,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
123123
124124 return isFactory ?
125125 this . computeDispatchProps ( store , props ) :
126- checkStateShape ( connectDisplayName , mappedDispatch , 'mapDispatchToProps' )
126+ checkStateShape ( mappedDispatch , 'mapDispatchToProps' )
127127 }
128128
129129 updateStatePropsIfNeeded ( ) {
@@ -147,7 +147,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
147147 }
148148
149149 updateMergedPropsIfNeeded ( ) {
150- const nextMergedProps = computeMergedProps ( connectDisplayName , this . stateProps , this . dispatchProps , this . props )
150+ const nextMergedProps = computeMergedProps ( this . stateProps , this . dispatchProps , this . props )
151151 if ( this . mergedProps && checkMergedEquals && shallowEqual ( nextMergedProps , this . mergedProps ) ) {
152152 return false
153153 }
0 commit comments