@@ -37,11 +37,10 @@ export default function createConnect(React) {
37
37
// Helps track hot reloading.
38
38
const version = nextVersion ++ ;
39
39
40
- function computeStateProps ( store , props ) {
41
- const state = store . getState ( ) ;
40
+ function computeStateProps ( storeState , props ) {
42
41
const stateProps = shouldUpdateStateProps ?
43
- finalMapStateToProps ( state , props ) :
44
- finalMapStateToProps ( state ) ;
42
+ finalMapStateToProps ( storeState , props ) :
43
+ finalMapStateToProps ( storeState ) ;
45
44
46
45
invariant (
47
46
isPlainObject ( stateProps ) ,
@@ -89,7 +88,8 @@ export default function createConnect(React) {
89
88
} ;
90
89
91
90
shouldComponentUpdate ( nextProps , nextState ) {
92
- return ! pure || ! shallowEqual ( this . state . props , nextState . props ) ;
91
+ return ! pure || ! shallowEqual ( this . props , nextProps ) ||
92
+ ! shallowEqual ( this . state , nextState ) ;
93
93
}
94
94
95
95
constructor ( props , context ) {
@@ -104,48 +104,17 @@ export default function createConnect(React) {
104
104
`or explicitly pass "store" as a prop to "${ this . constructor . displayName } ".`
105
105
) ;
106
106
107
- this . stateProps = computeStateProps ( this . store , props ) ;
108
- this . dispatchProps = computeDispatchProps ( this . store , props ) ;
109
107
this . state = {
110
- props : this . computeNextState ( )
108
+ dispatchProps : computeDispatchProps ( this . store , props ) ,
109
+ storeState : this . store . getState ( )
111
110
} ;
112
111
}
113
112
114
- computeNextState ( props = this . props ) {
115
- return computeNextState (
116
- this . stateProps ,
117
- this . dispatchProps ,
118
- props
119
- ) ;
120
- }
121
-
122
- updateStateProps ( props = this . props ) {
123
- const nextStateProps = computeStateProps ( this . store , props ) ;
124
- if ( shallowEqual ( nextStateProps , this . stateProps ) ) {
125
- return false ;
126
- }
127
-
128
- this . stateProps = nextStateProps ;
129
- return true ;
130
- }
131
113
132
114
updateDispatchProps ( props = this . props ) {
133
- const nextDispatchProps = computeDispatchProps ( this . store , props ) ;
134
- if ( shallowEqual ( nextDispatchProps , this . dispatchProps ) ) {
135
- return false ;
136
- }
137
-
138
- this . dispatchProps = nextDispatchProps ;
139
- return true ;
140
- }
141
-
142
- updateState ( props = this . props ) {
143
- const nextState = this . computeNextState ( props ) ;
144
- if ( ! shallowEqual ( nextState , this . state . props ) ) {
145
- this . setState ( {
146
- props : nextState
147
- } ) ;
148
- }
115
+ this . setState ( {
116
+ dispatchProps : computeDispatchProps ( this . store , props )
117
+ } ) ;
149
118
}
150
119
151
120
isSubscribed ( ) {
@@ -172,15 +141,10 @@ export default function createConnect(React) {
172
141
173
142
componentWillReceiveProps ( nextProps ) {
174
143
if ( ! shallowEqual ( nextProps , this . props ) ) {
175
- if ( shouldUpdateStateProps ) {
176
- this . updateStateProps ( nextProps ) ;
177
- }
178
-
179
144
if ( shouldUpdateDispatchProps ) {
180
145
this . updateDispatchProps ( nextProps ) ;
181
146
}
182
147
183
- this . updateState ( nextProps ) ;
184
148
}
185
149
}
186
150
@@ -193,19 +157,24 @@ export default function createConnect(React) {
193
157
return ;
194
158
}
195
159
196
- if ( this . updateStateProps ( ) ) {
197
- this . updateState ( ) ;
198
- }
160
+ this . setState ( { storeState : this . store . getState ( ) } ) ;
199
161
}
200
162
201
163
getWrappedInstance ( ) {
202
164
return this . refs . wrappedInstance ;
203
165
}
204
166
205
167
render ( ) {
168
+
169
+ const finalProps = computeNextState (
170
+ computeStateProps ( this . state . storeState , this . props ) ,
171
+ this . state . dispatchProps ,
172
+ this . props
173
+ ) ;
174
+
206
175
return (
207
176
< WrappedComponent ref = 'wrappedInstance'
208
- { ...this . state . props } />
177
+ { ...finalProps } />
209
178
) ;
210
179
}
211
180
}
@@ -221,9 +190,7 @@ export default function createConnect(React) {
221
190
222
191
// Update the state and bindings.
223
192
this . trySubscribe ( ) ;
224
- this . updateStateProps ( ) ;
225
193
this . updateDispatchProps ( ) ;
226
- this . updateState ( ) ;
227
194
} ;
228
195
}
229
196
0 commit comments