@@ -18,16 +18,6 @@ function getDisplayName(WrappedComponent) {
18
18
return WrappedComponent . displayName || WrappedComponent . name || 'Component'
19
19
}
20
20
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
-
31
21
// Helps track hot reloading.
32
22
let nextVersion = 0
33
23
@@ -45,17 +35,25 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
45
35
// Helps track hot reloading.
46
36
const version = nextVersion ++
47
37
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
-
58
38
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
+
59
57
class Connect extends Component {
60
58
shouldComponentUpdate ( ) {
61
59
return ! pure || this . haveOwnPropsChanged || this . hasStoreStateChanged
@@ -68,9 +66,9 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
68
66
69
67
invariant ( this . store ,
70
68
`Could not find "store" in either the context or ` +
71
- `props of "${ this . constructor . displayName } ". ` +
69
+ `props of "${ connectDisplayName } ". ` +
72
70
`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 } ".`
74
72
)
75
73
76
74
const storeState = this . store . getState ( )
@@ -88,7 +86,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
88
86
this . finalMapStateToProps ( state , props ) :
89
87
this . finalMapStateToProps ( state )
90
88
91
- return checkStateShape ( stateProps )
89
+ return checkStateShape ( stateProps , 'mapStateToProps' )
92
90
}
93
91
94
92
configureFinalMapState ( store , props ) {
@@ -100,7 +98,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
100
98
101
99
return isFactory ?
102
100
this . computeStateProps ( store , props ) :
103
- checkStateShape ( mappedState )
101
+ checkStateShape ( mappedState , 'mapStateToProps' )
104
102
}
105
103
106
104
computeDispatchProps ( store , props ) {
@@ -113,7 +111,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
113
111
this . finalMapDispatchToProps ( dispatch , props ) :
114
112
this . finalMapDispatchToProps ( dispatch )
115
113
116
- return checkStateShape ( dispatchProps , true )
114
+ return checkStateShape ( dispatchProps , 'mapDispatchToProps' )
117
115
}
118
116
119
117
configureFinalMapDispatch ( store , props ) {
@@ -125,7 +123,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
125
123
126
124
return isFactory ?
127
125
this . computeDispatchProps ( store , props ) :
128
- checkStateShape ( mappedDispatch , true )
126
+ checkStateShape ( mappedDispatch , 'mapDispatchToProps' )
129
127
}
130
128
131
129
updateStatePropsIfNeeded ( ) {
@@ -284,7 +282,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
284
282
}
285
283
}
286
284
287
- Connect . displayName = `Connect( ${ getDisplayName ( WrappedComponent ) } )`
285
+ Connect . displayName = connectDisplayName
288
286
Connect . WrappedComponent = WrappedComponent
289
287
Connect . contextTypes = {
290
288
store : storeShape
0 commit comments