-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: react-hot-loader compatibility #1137
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,6 @@ export default function connectAdvanced( | |
const { pure } = connectOptions | ||
|
||
let OuterBaseComponent = Component | ||
let FinalWrappedComponent = WrappedComponent | ||
|
||
if (pure) { | ||
OuterBaseComponent = PureComponent | ||
|
@@ -131,15 +130,25 @@ export default function connectAdvanced( | |
let lastState | ||
let lastDerivedProps | ||
let lastStore | ||
let lastSelectorFactoryOptions | ||
let sourceSelector | ||
|
||
return function selectDerivedProps(state, props, store) { | ||
return function selectDerivedProps( | ||
state, | ||
props, | ||
store, | ||
selectorFactoryOptions | ||
) { | ||
if (pure && lastProps === props && lastState === state) { | ||
return lastDerivedProps | ||
} | ||
|
||
if (store !== lastStore) { | ||
if ( | ||
store !== lastStore || | ||
lastSelectorFactoryOptions !== selectorFactoryOptions | ||
) { | ||
lastStore = store | ||
lastSelectorFactoryOptions = selectorFactoryOptions | ||
sourceSelector = selectorFactory( | ||
store.dispatch, | ||
selectorFactoryOptions | ||
|
@@ -157,14 +166,23 @@ export default function connectAdvanced( | |
} | ||
|
||
function makeChildElementSelector() { | ||
let lastChildProps, lastForwardRef, lastChildElement | ||
let lastChildProps, lastForwardRef, lastChildElement, lastComponent | ||
|
||
return function selectChildElement(childProps, forwardRef) { | ||
if (childProps !== lastChildProps || forwardRef !== lastForwardRef) { | ||
return function selectChildElement( | ||
WrappedComponent, | ||
childProps, | ||
forwardRef | ||
) { | ||
if ( | ||
childProps !== lastChildProps || | ||
forwardRef !== lastForwardRef || | ||
lastComponent !== WrappedComponent | ||
) { | ||
lastChildProps = childProps | ||
lastForwardRef = forwardRef | ||
lastComponent = WrappedComponent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. component could change. Don't use component from a local scope. |
||
lastChildElement = ( | ||
<FinalWrappedComponent {...childProps} ref={forwardRef} /> | ||
<WrappedComponent {...childProps} ref={forwardRef} /> | ||
) | ||
} | ||
|
||
|
@@ -182,7 +200,14 @@ export default function connectAdvanced( | |
) | ||
this.selectDerivedProps = makeDerivedPropsSelector() | ||
this.selectChildElement = makeChildElementSelector() | ||
this.renderWrappedComponent = this.renderWrappedComponent.bind(this) | ||
this.indirectRenderWrappedComponent = this.indirectRenderWrappedComponent.bind( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. constructor could not be updated on hot-load. |
||
this | ||
) | ||
} | ||
|
||
indirectRenderWrappedComponent(value) { | ||
// calling renderWrappedComponent on prototype from indirectRenderWrappedComponent bound to `this` | ||
return this.renderWrappedComponent(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the main trick - redirect to hot-reloadable prototype level. |
||
} | ||
|
||
renderWrappedComponent(value) { | ||
|
@@ -206,18 +231,23 @@ export default function connectAdvanced( | |
let derivedProps = this.selectDerivedProps( | ||
storeState, | ||
wrapperProps, | ||
store | ||
store, | ||
selectorFactoryOptions | ||
) | ||
|
||
return this.selectChildElement(derivedProps, forwardedRef) | ||
return this.selectChildElement( | ||
WrappedComponent, | ||
derivedProps, | ||
forwardedRef | ||
) | ||
} | ||
|
||
render() { | ||
const ContextToUse = this.props.context || Context | ||
|
||
return ( | ||
<ContextToUse.Consumer> | ||
{this.renderWrappedComponent} | ||
{this.indirectRenderWrappedComponent} | ||
</ContextToUse.Consumer> | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
factory could change, not only store