@@ -18,16 +18,6 @@ function getDisplayName(WrappedComponent) {
1818 return WrappedComponent . displayName || WrappedComponent . name || 'Component'
1919}
2020
21- function checkStateShape ( stateProps , dispatch ) {
22- invariant (
23- isPlainObject ( stateProps ) ,
24- '`%sToProps` must return an object. Instead received %s.' ,
25- dispatch ? 'mapDispatch' : 'mapState' ,
26- stateProps
27- )
28- return stateProps
29- }
30-
3121// Helps track hot reloading.
3222let nextVersion = 0
3323
@@ -45,17 +35,25 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
4535 // Helps track hot reloading.
4636 const version = nextVersion ++
4737
48- function computeMergedProps ( stateProps , dispatchProps , parentProps ) {
49- const mergedProps = finalMergeProps ( stateProps , dispatchProps , parentProps )
50- invariant (
51- isPlainObject ( mergedProps ) ,
52- '`mergeProps` must return an object. Instead received %s.' ,
53- mergedProps
54- )
55- return mergedProps
56- }
57-
5838 return function wrapWithConnect ( WrappedComponent ) {
39+ const connectDisplayName = `Connect(${ getDisplayName ( WrappedComponent ) } )`
40+
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+
5957 class Connect extends Component {
6058 shouldComponentUpdate ( ) {
6159 return ! pure || this . haveOwnPropsChanged || this . hasStoreStateChanged
@@ -68,9 +66,9 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
6866
6967 invariant ( this . store ,
7068 `Could not find "store" in either the context or ` +
71- `props of "${ this . constructor . displayName } ". ` +
69+ `props of "${ connectDisplayName } ". ` +
7270 `Either wrap the root component in a <Provider>, ` +
73- `or explicitly pass "store" as a prop to "${ this . constructor . displayName } ".`
71+ `or explicitly pass "store" as a prop to "${ connectDisplayName } ".`
7472 )
7573
7674 const storeState = this . store . getState ( )
@@ -88,7 +86,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
8886 this . finalMapStateToProps ( state , props ) :
8987 this . finalMapStateToProps ( state )
9088
91- return checkStateShape ( stateProps )
89+ return checkStateShape ( stateProps , 'mapStateToProps' )
9290 }
9391
9492 configureFinalMapState ( store , props ) {
@@ -100,7 +98,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
10098
10199 return isFactory ?
102100 this . computeStateProps ( store , props ) :
103- checkStateShape ( mappedState )
101+ checkStateShape ( mappedState , 'mapStateToProps' )
104102 }
105103
106104 computeDispatchProps ( store , props ) {
@@ -113,7 +111,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
113111 this . finalMapDispatchToProps ( dispatch , props ) :
114112 this . finalMapDispatchToProps ( dispatch )
115113
116- return checkStateShape ( dispatchProps , true )
114+ return checkStateShape ( dispatchProps , 'mapDispatchToProps' )
117115 }
118116
119117 configureFinalMapDispatch ( store , props ) {
@@ -125,7 +123,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
125123
126124 return isFactory ?
127125 this . computeDispatchProps ( store , props ) :
128- checkStateShape ( mappedDispatch , true )
126+ checkStateShape ( mappedDispatch , 'mapDispatchToProps' )
129127 }
130128
131129 updateStatePropsIfNeeded ( ) {
@@ -284,7 +282,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
284282 }
285283 }
286284
287- Connect . displayName = `Connect( ${ getDisplayName ( WrappedComponent ) } )`
285+ Connect . displayName = connectDisplayName
288286 Connect . WrappedComponent = WrappedComponent
289287 Connect . contextTypes = {
290288 store : storeShape
0 commit comments