Skip to content
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

Cleanup more code after pure removal #1859

Merged
merged 1 commit into from
Feb 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/components/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ function connect<
const displayName = `Connect(${wrappedComponentName})`

const selectorFactoryOptions: SelectorFactoryOptions<any, any, any, any> = {
pure,
shouldHandleStateChanges,
displayName,
wrappedComponentName,
Expand All @@ -543,11 +542,6 @@ function connect<
areMergedPropsEqual,
}

// If we aren't running in "pure" mode, we don't want to memoize values.
// To avoid conditionally calling hooks, we fall back to a tiny wrapper
// that just executes the given callback immediately.
const usePureOnlyMemo = pure ? useMemo : (callback: () => any) => callback()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this actually changes behavior but ive assumed that to the more preferred one. The alternative is to inline the memoized value - as thay was effectively happening before my changes


function ConnectFunction<TOwnProps>(
props: InternalConnectProps & TOwnProps
) {
Expand Down Expand Up @@ -667,7 +661,7 @@ function connect<
}
}, [])

const actualChildPropsSelector = usePureOnlyMemo(() => {
const actualChildPropsSelector = useMemo(() => {
const selector = () => {
// Tricky logic here:
// - This render may have been triggered by a Redux store update that produced new child props
Expand Down Expand Up @@ -790,7 +784,6 @@ function connect<
return renderedChild
}

// If we're in "pure" mode, ensure our wrapper component only re-renders when incoming props have changed.
const _Connect = React.memo(ConnectFunction)

type ConnectedWrapperComponent = typeof _Connect & {
Expand Down