@@ -74,7 +74,13 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
74
74
75
75
class Connect extends Component {
76
76
shouldComponentUpdate ( ) {
77
- return ! pure || this . haveOwnPropsChanged || this . hasStoreStateChanged
77
+ return ! pure || this . haveMergedPropsChanged
78
+ }
79
+
80
+ componentWillMount ( ) {
81
+ this . updateDispatchPropsIfNeeded ( ) ;
82
+ this . updateStatePropsIfNeeded ( ) ;
83
+ this . haveMergedPropsChanged = this . updateMergedPropsIfNeeded ( ) ;
78
84
}
79
85
80
86
constructor ( props , context ) {
@@ -89,6 +95,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
89
95
`or explicitly pass "store" as a prop to "${ connectDisplayName } ".`
90
96
)
91
97
98
+ this . haveMergedPropsChanged = false ;
92
99
const storeState = this . store . getState ( )
93
100
this . state = { storeState }
94
101
this . clearCache ( )
@@ -215,6 +222,14 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
215
222
componentWillReceiveProps ( nextProps ) {
216
223
if ( ! pure || ! shallowEqual ( nextProps , this . props ) ) {
217
224
this . haveOwnPropsChanged = true
225
+ this . props = nextProps ;
226
+
227
+ if ( ! pure || ! this . renderedElement || this . doDispatchPropsDependOnOwnProps ) {
228
+ this . updateDispatchPropsIfNeeded ( )
229
+ this . updateStatePropsIfNeeded ( )
230
+ }
231
+ this . haveMergedPropsChanged = this . updateMergedPropsIfNeeded ( ) ;
232
+ console . log ( 'component updated via props' )
218
233
}
219
234
}
220
235
@@ -259,7 +274,12 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
259
274
}
260
275
261
276
this . hasStoreStateChanged = true
262
- this . setState ( { storeState } )
277
+ this . setState ( ( previousState , currentProps ) => {
278
+ this . props = currentProps ;
279
+ this . updateDispatchPropsIfNeeded ( ) ;
280
+ this . updateStatePropsIfNeeded ( ) ;
281
+ this . haveMergedPropsChanged = this . updateMergedPropsIfNeeded ( ) ;
282
+ } )
263
283
}
264
284
265
285
getWrappedInstance ( ) {
@@ -272,59 +292,9 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
272
292
}
273
293
274
294
render ( ) {
275
- const {
276
- haveOwnPropsChanged,
277
- hasStoreStateChanged,
278
- haveStatePropsBeenPrecalculated,
279
- statePropsPrecalculationError,
280
- renderedElement
281
- } = this
282
-
283
- this . haveOwnPropsChanged = false
284
- this . hasStoreStateChanged = false
285
- this . haveStatePropsBeenPrecalculated = false
286
- this . statePropsPrecalculationError = null
287
-
288
- if ( statePropsPrecalculationError ) {
289
- throw statePropsPrecalculationError
290
- }
291
-
292
- let shouldUpdateStateProps = true
293
- let shouldUpdateDispatchProps = true
294
- if ( pure && renderedElement ) {
295
- shouldUpdateStateProps = hasStoreStateChanged || (
296
- haveOwnPropsChanged && this . doStatePropsDependOnOwnProps
297
- )
298
- shouldUpdateDispatchProps =
299
- haveOwnPropsChanged && this . doDispatchPropsDependOnOwnProps
295
+ if ( ! this . haveMergedPropsChanged && this . renderedElement ) {
296
+ return this . renderedElement
300
297
}
301
-
302
- let haveStatePropsChanged = false
303
- let haveDispatchPropsChanged = false
304
- if ( haveStatePropsBeenPrecalculated ) {
305
- haveStatePropsChanged = true
306
- } else if ( shouldUpdateStateProps ) {
307
- haveStatePropsChanged = this . updateStatePropsIfNeeded ( )
308
- }
309
- if ( shouldUpdateDispatchProps ) {
310
- haveDispatchPropsChanged = this . updateDispatchPropsIfNeeded ( )
311
- }
312
-
313
- let haveMergedPropsChanged = true
314
- if (
315
- haveStatePropsChanged ||
316
- haveDispatchPropsChanged ||
317
- haveOwnPropsChanged
318
- ) {
319
- haveMergedPropsChanged = this . updateMergedPropsIfNeeded ( )
320
- } else {
321
- haveMergedPropsChanged = false
322
- }
323
-
324
- if ( ! haveMergedPropsChanged && renderedElement ) {
325
- return renderedElement
326
- }
327
-
328
298
if ( withRef ) {
329
299
this . renderedElement = createElement ( WrappedComponent , {
330
300
...this . mergedProps ,
0 commit comments