@@ -89,7 +89,30 @@ export default function createConnect(React) {
89
89
} ;
90
90
91
91
shouldComponentUpdate ( nextProps , nextState ) {
92
- return ! pure || ! shallowEqual ( this . state . props , nextState . props ) ;
92
+ if ( ! pure ) {
93
+ this . updateState ( nextProps ) ;
94
+ return true ;
95
+ }
96
+
97
+ const storeChanged = nextState . storeState !== this . state . storeState ;
98
+ const propsChanged = ! shallowEqual ( nextProps , this . props ) ;
99
+ let mapStateProducedChange = false ;
100
+ let dispatchPropsChanged = false ;
101
+
102
+ if ( storeChanged || ( propsChanged && shouldUpdateStateProps ) ) {
103
+ mapStateProducedChange = this . updateStateProps ( nextProps ) ;
104
+ }
105
+
106
+ if ( propsChanged && shouldUpdateDispatchProps ) {
107
+ dispatchPropsChanged = this . updateDispatchProps ( nextProps ) ;
108
+ }
109
+
110
+ if ( propsChanged || mapStateProducedChange || dispatchPropsChanged ) {
111
+ this . updateState ( nextProps ) ;
112
+ return true ;
113
+ } else {
114
+ return false ;
115
+ }
93
116
}
94
117
95
118
constructor ( props , context ) {
@@ -106,9 +129,8 @@ export default function createConnect(React) {
106
129
107
130
this . stateProps = computeStateProps ( this . store , props ) ;
108
131
this . dispatchProps = computeDispatchProps ( this . store , props ) ;
109
- this . state = {
110
- props : this . computeNextState ( )
111
- } ;
132
+ this . state = { storeState : null } ;
133
+ this . updateState ( ) ;
112
134
}
113
135
114
136
computeNextState ( props = this . props ) {
@@ -140,12 +162,7 @@ export default function createConnect(React) {
140
162
}
141
163
142
164
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
- }
165
+ this . nextState = this . computeNextState ( props ) ;
149
166
}
150
167
151
168
isSubscribed ( ) {
@@ -170,20 +187,6 @@ export default function createConnect(React) {
170
187
this . trySubscribe ( ) ;
171
188
}
172
189
173
- componentWillReceiveProps ( nextProps ) {
174
- if ( ! shallowEqual ( nextProps , this . props ) ) {
175
- if ( shouldUpdateStateProps ) {
176
- this . updateStateProps ( nextProps ) ;
177
- }
178
-
179
- if ( shouldUpdateDispatchProps ) {
180
- this . updateDispatchProps ( nextProps ) ;
181
- }
182
-
183
- this . updateState ( nextProps ) ;
184
- }
185
- }
186
-
187
190
componentWillUnmount ( ) {
188
191
this . tryUnsubscribe ( ) ;
189
192
}
@@ -193,9 +196,7 @@ export default function createConnect(React) {
193
196
return ;
194
197
}
195
198
196
- if ( this . updateStateProps ( ) ) {
197
- this . updateState ( ) ;
198
- }
199
+ this . setState ( { storeState : this . store . getState ( ) } ) ;
199
200
}
200
201
201
202
getWrappedInstance ( ) {
@@ -205,7 +206,7 @@ export default function createConnect(React) {
205
206
render ( ) {
206
207
return (
207
208
< WrappedComponent ref = 'wrappedInstance'
208
- { ...this . state . props } />
209
+ { ...this . nextState } />
209
210
) ;
210
211
}
211
212
}
0 commit comments