Skip to content

Commit a397801

Browse files
committed
Connect: pass ownProps to areStatesEqual
1 parent fb8cfc0 commit a397801

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/components/connect.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ export interface ConnectOptions<
231231
> {
232232
forwardRef?: boolean
233233
context?: typeof ReactReduxContext
234-
areStatesEqual?: (nextState: State, prevState: State) => boolean
234+
areStatesEqual?: (
235+
nextState: State,
236+
prevState: State,
237+
nextOwnProps: TOwnProps,
238+
prevOwnProps: TOwnProps
239+
) => boolean
235240

236241
areOwnPropsEqual?: (
237242
nextOwnProps: TOwnProps,

src/connect/selectorFactory.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Dispatch, Action } from 'redux'
22
import type { ComponentType } from 'react'
33
import verifySubselectors from './verifySubselectors'
4-
import type { EqualityFn } from '../types'
4+
import type { EqualityFn, ExtendedEqualityFn } from '../types'
55

66
export type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> = (
77
dispatch: Dispatch<Action<unknown>>,
@@ -59,7 +59,7 @@ export type MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> = (
5959
) => TMergedProps
6060

6161
interface PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> {
62-
readonly areStatesEqual: EqualityFn<State>
62+
readonly areStatesEqual: ExtendedEqualityFn<State, TOwnProps>
6363
readonly areStatePropsEqual: EqualityFn<TStateProps>
6464
readonly areOwnPropsEqual: EqualityFn<TOwnProps>
6565
}
@@ -132,7 +132,12 @@ export function pureFinalPropsSelectorFactory<
132132

133133
function handleSubsequentCalls(nextState: State, nextOwnProps: TOwnProps) {
134134
const propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps)
135-
const stateChanged = !areStatesEqual(nextState, state)
135+
const stateChanged = !areStatesEqual(
136+
nextState,
137+
state,
138+
nextOwnProps,
139+
ownProps
140+
)
136141
state = nextState
137142
ownProps = nextOwnProps
138143

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export type FixTypeLater = any
1010

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

13+
export type ExtendedEqualityFn<T, P> = (a: T, b: T, c: P, d: P) => boolean
14+
1315
export type AnyIfEmpty<T extends object> = keyof T extends never ? any : T
1416

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

0 commit comments

Comments
 (0)