@@ -120,7 +120,6 @@ export default function connectAdvanced(
120
120
const { pure } = connectOptions
121
121
122
122
let OuterBaseComponent = Component
123
- let FinalWrappedComponent = WrappedComponent
124
123
125
124
if ( pure ) {
126
125
OuterBaseComponent = PureComponent
@@ -131,15 +130,25 @@ export default function connectAdvanced(
131
130
let lastState
132
131
let lastDerivedProps
133
132
let lastStore
133
+ let lastSelectorFactoryOptions
134
134
let sourceSelector
135
135
136
- return function selectDerivedProps ( state , props , store ) {
136
+ return function selectDerivedProps (
137
+ state ,
138
+ props ,
139
+ store ,
140
+ selectorFactoryOptions
141
+ ) {
137
142
if ( pure && lastProps === props && lastState === state ) {
138
143
return lastDerivedProps
139
144
}
140
145
141
- if ( store !== lastStore ) {
146
+ if (
147
+ store !== lastStore ||
148
+ lastSelectorFactoryOptions !== selectorFactoryOptions
149
+ ) {
142
150
lastStore = store
151
+ lastSelectorFactoryOptions = selectorFactoryOptions
143
152
sourceSelector = selectorFactory (
144
153
store . dispatch ,
145
154
selectorFactoryOptions
@@ -157,14 +166,23 @@ export default function connectAdvanced(
157
166
}
158
167
159
168
function makeChildElementSelector ( ) {
160
- let lastChildProps , lastForwardRef , lastChildElement
169
+ let lastChildProps , lastForwardRef , lastChildElement , lastComponent
161
170
162
- return function selectChildElement ( childProps , forwardRef ) {
163
- if ( childProps !== lastChildProps || forwardRef !== lastForwardRef ) {
171
+ return function selectChildElement (
172
+ WrappedComponent ,
173
+ childProps ,
174
+ forwardRef
175
+ ) {
176
+ if (
177
+ childProps !== lastChildProps ||
178
+ forwardRef !== lastForwardRef ||
179
+ lastComponent !== WrappedComponent
180
+ ) {
164
181
lastChildProps = childProps
165
182
lastForwardRef = forwardRef
183
+ lastComponent = WrappedComponent
166
184
lastChildElement = (
167
- < FinalWrappedComponent { ...childProps } ref = { forwardRef } />
185
+ < WrappedComponent { ...childProps } ref = { forwardRef } />
168
186
)
169
187
}
170
188
@@ -182,7 +200,14 @@ export default function connectAdvanced(
182
200
)
183
201
this . selectDerivedProps = makeDerivedPropsSelector ( )
184
202
this . selectChildElement = makeChildElementSelector ( )
185
- this . renderWrappedComponent = this . renderWrappedComponent . bind ( this )
203
+ this . indirectRenderWrappedComponent = this . indirectRenderWrappedComponent . bind (
204
+ this
205
+ )
206
+ }
207
+
208
+ indirectRenderWrappedComponent ( value ) {
209
+ // calling renderWrappedComponent on prototype from indirectRenderWrappedComponent bound to `this`
210
+ return this . renderWrappedComponent ( value )
186
211
}
187
212
188
213
renderWrappedComponent ( value ) {
@@ -206,18 +231,23 @@ export default function connectAdvanced(
206
231
let derivedProps = this . selectDerivedProps (
207
232
storeState ,
208
233
wrapperProps ,
209
- store
234
+ store ,
235
+ selectorFactoryOptions
210
236
)
211
237
212
- return this . selectChildElement ( derivedProps , forwardedRef )
238
+ return this . selectChildElement (
239
+ WrappedComponent ,
240
+ derivedProps ,
241
+ forwardedRef
242
+ )
213
243
}
214
244
215
245
render ( ) {
216
246
const ContextToUse = this . props . context || Context
217
247
218
248
return (
219
249
< ContextToUse . Consumer >
220
- { this . renderWrappedComponent }
250
+ { this . indirectRenderWrappedComponent }
221
251
</ ContextToUse . Consumer >
222
252
)
223
253
}
0 commit comments