@@ -18,15 +18,15 @@ function getDisplayName(WrappedComponent) {
18
18
return WrappedComponent . displayName || WrappedComponent . name || 'Component'
19
19
}
20
20
21
- function checkStateShape ( componentDisplayName , stateProps , dispatch ) {
21
+ function checkStateShape ( componentDisplayName , props , methodName ) {
22
22
invariant (
23
- isPlainObject ( stateProps ) ,
24
- '`%s %sToProps ` must return an object. Instead received %s.' ,
23
+ isPlainObject ( props ) ,
24
+ '`%s %s ` must return an object. Instead received %s.' ,
25
25
componentDisplayName ,
26
- dispatch ? 'mapDispatch' : 'mapState' ,
27
- stateProps
26
+ methodName ,
27
+ props
28
28
)
29
- return stateProps
29
+ return props
30
30
}
31
31
32
32
// Helps track hot reloading.
@@ -48,16 +48,12 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
48
48
49
49
function computeMergedProps ( componentDisplayName , stateProps , dispatchProps , parentProps ) {
50
50
const mergedProps = finalMergeProps ( stateProps , dispatchProps , parentProps )
51
- invariant (
52
- isPlainObject ( mergedProps ) ,
53
- '`%s mergeProps` must return an object. Instead received %s.' ,
54
- componentDisplayName ,
55
- mergedProps
56
- )
57
- return mergedProps
51
+ return checkStateShape ( componentDisplayName , mergedProps , 'mergeProps' )
58
52
}
59
53
60
54
return function wrapWithConnect ( WrappedComponent ) {
55
+ const connectDisplayName = `Connect(${ getDisplayName ( WrappedComponent ) } )`
56
+
61
57
class Connect extends Component {
62
58
shouldComponentUpdate ( ) {
63
59
return ! pure || this . haveOwnPropsChanged || this . hasStoreStateChanged
@@ -70,9 +66,9 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
70
66
71
67
invariant ( this . store ,
72
68
`Could not find "store" in either the context or ` +
73
- `props of "${ this . constructor . displayName } ". ` +
69
+ `props of "${ connectDisplayName } ". ` +
74
70
`Either wrap the root component in a <Provider>, ` +
75
- `or explicitly pass "store" as a prop to "${ this . constructor . displayName } ".`
71
+ `or explicitly pass "store" as a prop to "${ connectDisplayName } ".`
76
72
)
77
73
78
74
const storeState = this . store . getState ( )
@@ -90,7 +86,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
90
86
this . finalMapStateToProps ( state , props ) :
91
87
this . finalMapStateToProps ( state )
92
88
93
- return checkStateShape ( this . constructor . displayName , stateProps )
89
+ return checkStateShape ( connectDisplayName , stateProps , 'mapStateToProps' )
94
90
}
95
91
96
92
configureFinalMapState ( store , props ) {
@@ -102,7 +98,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
102
98
103
99
return isFactory ?
104
100
this . computeStateProps ( store , props ) :
105
- checkStateShape ( this . constructor . displayName , mappedState )
101
+ checkStateShape ( connectDisplayName , mappedState , 'mapStateToProps' )
106
102
}
107
103
108
104
computeDispatchProps ( store , props ) {
@@ -115,7 +111,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
115
111
this . finalMapDispatchToProps ( dispatch , props ) :
116
112
this . finalMapDispatchToProps ( dispatch )
117
113
118
- return checkStateShape ( this . constructor . displayName , dispatchProps , true )
114
+ return checkStateShape ( connectDisplayName , dispatchProps , 'mapDispatchToProps' )
119
115
}
120
116
121
117
configureFinalMapDispatch ( store , props ) {
@@ -127,7 +123,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
127
123
128
124
return isFactory ?
129
125
this . computeDispatchProps ( store , props ) :
130
- checkStateShape ( this . constructor . displayName , mappedDispatch , true )
126
+ checkStateShape ( connectDisplayName , mappedDispatch , 'mapDispatchToProps' )
131
127
}
132
128
133
129
updateStatePropsIfNeeded ( ) {
@@ -151,7 +147,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
151
147
}
152
148
153
149
updateMergedPropsIfNeeded ( ) {
154
- const nextMergedProps = computeMergedProps ( this . constructor . displayName , this . stateProps , this . dispatchProps , this . props )
150
+ const nextMergedProps = computeMergedProps ( connectDisplayName , this . stateProps , this . dispatchProps , this . props )
155
151
if ( this . mergedProps && checkMergedEquals && shallowEqual ( nextMergedProps , this . mergedProps ) ) {
156
152
return false
157
153
}
@@ -286,7 +282,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
286
282
}
287
283
}
288
284
289
- Connect . displayName = `Connect( ${ getDisplayName ( WrappedComponent ) } )`
285
+ Connect . displayName = connectDisplayName
290
286
Connect . WrappedComponent = WrappedComponent
291
287
Connect . contextTypes = {
292
288
store : storeShape
0 commit comments