Skip to content

Commit

Permalink
Connect: pass ownProps to areStatesEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
jspurlin committed Aug 31, 2022
1 parent fb8cfc0 commit a397801
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/components/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ export interface ConnectOptions<
> {
forwardRef?: boolean
context?: typeof ReactReduxContext
areStatesEqual?: (nextState: State, prevState: State) => boolean
areStatesEqual?: (
nextState: State,
prevState: State,
nextOwnProps: TOwnProps,
prevOwnProps: TOwnProps
) => boolean

areOwnPropsEqual?: (
nextOwnProps: TOwnProps,
Expand Down
11 changes: 8 additions & 3 deletions src/connect/selectorFactory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Dispatch, Action } from 'redux'
import type { ComponentType } from 'react'
import verifySubselectors from './verifySubselectors'
import type { EqualityFn } from '../types'
import type { EqualityFn, ExtendedEqualityFn } from '../types'

export type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> = (
dispatch: Dispatch<Action<unknown>>,
Expand Down Expand Up @@ -59,7 +59,7 @@ export type MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> = (
) => TMergedProps

interface PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> {
readonly areStatesEqual: EqualityFn<State>
readonly areStatesEqual: ExtendedEqualityFn<State, TOwnProps>
readonly areStatePropsEqual: EqualityFn<TStateProps>
readonly areOwnPropsEqual: EqualityFn<TOwnProps>
}
Expand Down Expand Up @@ -132,7 +132,12 @@ export function pureFinalPropsSelectorFactory<

function handleSubsequentCalls(nextState: State, nextOwnProps: TOwnProps) {
const propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps)
const stateChanged = !areStatesEqual(nextState, state)
const stateChanged = !areStatesEqual(
nextState,
state,
nextOwnProps,
ownProps
)
state = nextState
ownProps = nextOwnProps

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type FixTypeLater = any

export type EqualityFn<T> = (a: T, b: T) => boolean

export type ExtendedEqualityFn<T, P> = (a: T, b: T, c: P, d: P) => boolean

export type AnyIfEmpty<T extends object> = keyof T extends never ? any : T

export type DistributiveOmit<T, K extends keyof T> = T extends unknown
Expand Down

0 comments on commit a397801

Please sign in to comment.