react-redux
Advanced tools
Comparing version 8.0.0-beta.4 to 8.0.0-rc.0
import type { Store } from 'redux'; | ||
import type { DefaultRootState, InferableComponentEnhancer, InferableComponentEnhancerWithProps, ResolveThunks, DispatchProp } from '../types'; | ||
import type { InferableComponentEnhancer, InferableComponentEnhancerWithProps, ResolveThunks, DispatchProp } from '../types'; | ||
import { MapStateToPropsParam, MapDispatchToPropsParam, MergeProps, MapDispatchToPropsNonObject } from '../connect/selectorFactory'; | ||
@@ -17,3 +17,3 @@ import { ReactReduxContext, ReactReduxContextInstance } from './Context'; | ||
export declare type ConnectedProps<TConnector> = TConnector extends InferableComponentEnhancerWithProps<infer TInjectedProps, any> ? unknown extends TInjectedProps ? TConnector extends InferableComponentEnhancer<infer TInjectedProps> ? TInjectedProps : never : TInjectedProps : never; | ||
export interface ConnectOptions<State = DefaultRootState, TStateProps = {}, TOwnProps = {}, TMergedProps = {}> { | ||
export interface ConnectOptions<State = unknown, TStateProps = {}, TOwnProps = {}, TMergedProps = {}> { | ||
forwardRef?: boolean; | ||
@@ -45,3 +45,3 @@ context?: typeof ReactReduxContext; | ||
*/ | ||
export interface Connect<DefaultState = DefaultRootState> { | ||
export interface Connect<DefaultState = unknown> { | ||
(): InferableComponentEnhancer<DispatchProp>; | ||
@@ -77,3 +77,3 @@ /** mapState only */ | ||
} | ||
declare const _default: Connect<DefaultRootState>; | ||
declare const _default: Connect<unknown>; | ||
export default _default; |
@@ -216,3 +216,5 @@ import _extends from "@babel/runtime/helpers/esm/extends"; | ||
WrappedComponent, | ||
// @ts-ignore | ||
initMapStateToProps, | ||
// @ts-ignore | ||
initMapDispatchToProps, | ||
@@ -219,0 +221,0 @@ // @ts-ignore |
import type { Dispatch, Action } from 'redux'; | ||
import type { DefaultRootState, EqualityFn } from '../types'; | ||
export declare type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> = (dispatch: Dispatch<Action>, factoryOptions: TFactoryOptions) => Selector<S, TProps, TOwnProps>; | ||
import type { EqualityFn } from '../types'; | ||
export declare type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> = (dispatch: Dispatch<Action<unknown>>, factoryOptions: TFactoryOptions) => Selector<S, TProps, TOwnProps>; | ||
export declare type Selector<S, TProps, TOwnProps = null> = TOwnProps extends null | undefined ? (state: S) => TProps : (state: S, ownProps: TOwnProps) => TProps; | ||
export declare type MapStateToProps<TStateProps, TOwnProps, State = DefaultRootState> = (state: State, ownProps: TOwnProps) => TStateProps; | ||
export declare type MapStateToPropsFactory<TStateProps, TOwnProps, State = DefaultRootState> = (initialState: State, ownProps: TOwnProps) => MapStateToProps<TStateProps, TOwnProps, State>; | ||
export declare type MapStateToPropsParam<TStateProps, TOwnProps, State = DefaultRootState> = MapStateToPropsFactory<TStateProps, TOwnProps, State> | MapStateToProps<TStateProps, TOwnProps, State> | null | undefined; | ||
export declare type MapDispatchToPropsFunction<TDispatchProps, TOwnProps> = (dispatch: Dispatch<Action>, ownProps: TOwnProps) => TDispatchProps; | ||
export declare type MapStateToProps<TStateProps, TOwnProps, State> = (state: State, ownProps: TOwnProps) => TStateProps; | ||
export declare type MapStateToPropsFactory<TStateProps, TOwnProps, State> = (initialState: State, ownProps: TOwnProps) => MapStateToProps<TStateProps, TOwnProps, State>; | ||
export declare type MapStateToPropsParam<TStateProps, TOwnProps, State> = MapStateToPropsFactory<TStateProps, TOwnProps, State> | MapStateToProps<TStateProps, TOwnProps, State> | null | undefined; | ||
export declare type MapDispatchToPropsFunction<TDispatchProps, TOwnProps> = (dispatch: Dispatch<Action<unknown>>, ownProps: TOwnProps) => TDispatchProps; | ||
export declare type MapDispatchToProps<TDispatchProps, TOwnProps> = MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | TDispatchProps; | ||
export declare type MapDispatchToPropsFactory<TDispatchProps, TOwnProps> = (dispatch: Dispatch<Action>, ownProps: TOwnProps) => MapDispatchToPropsFunction<TDispatchProps, TOwnProps>; | ||
export declare type MapDispatchToPropsFactory<TDispatchProps, TOwnProps> = (dispatch: Dispatch<Action<unknown>>, ownProps: TOwnProps) => MapDispatchToPropsFunction<TDispatchProps, TOwnProps>; | ||
export declare type MapDispatchToPropsParam<TDispatchProps, TOwnProps> = MapDispatchToPropsFactory<TDispatchProps, TOwnProps> | MapDispatchToProps<TDispatchProps, TOwnProps>; | ||
export declare type MapDispatchToPropsNonObject<TDispatchProps, TOwnProps> = MapDispatchToPropsFactory<TDispatchProps, TOwnProps> | MapDispatchToPropsFunction<TDispatchProps, TOwnProps>; | ||
export declare type MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> = (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps) => TMergedProps; | ||
interface PureSelectorFactoryComparisonOptions<TOwnProps, State = DefaultRootState> { | ||
interface PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> { | ||
areStatesEqual: EqualityFn<State>; | ||
areOwnPropsEqual: EqualityFn<TOwnProps>; | ||
areStatePropsEqual: EqualityFn<unknown>; | ||
areStatePropsEqual: EqualityFn<TStateProps>; | ||
displayName: string; | ||
} | ||
export declare function pureFinalPropsSelectorFactory<TStateProps, TOwnProps, TDispatchProps, TMergedProps, State = DefaultRootState>(mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State> & { | ||
dependsOnOwnProps: boolean; | ||
}, mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps> & { | ||
dependsOnOwnProps: boolean; | ||
}, mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>, dispatch: Dispatch, { areStatesEqual, areOwnPropsEqual, areStatePropsEqual, }: PureSelectorFactoryComparisonOptions<TOwnProps, State>): (nextState: State, nextOwnProps: TOwnProps) => TMergedProps; | ||
export interface SelectorFactoryOptions<TStateProps, TOwnProps, TDispatchProps, TMergedProps, State = DefaultRootState> extends PureSelectorFactoryComparisonOptions<TOwnProps, State> { | ||
initMapStateToProps: (dispatch: Dispatch, options: PureSelectorFactoryComparisonOptions<TOwnProps, State>) => MapStateToPropsParam<TStateProps, TOwnProps, State>; | ||
initMapDispatchToProps: (dispatch: Dispatch, options: PureSelectorFactoryComparisonOptions<TOwnProps, State>) => MapDispatchToPropsParam<TDispatchProps, TOwnProps>; | ||
initMergeProps: (dispatch: Dispatch, options: PureSelectorFactoryComparisonOptions<TOwnProps, State>) => MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>; | ||
export declare function pureFinalPropsSelectorFactory<TStateProps, TOwnProps, TDispatchProps, TMergedProps, State>(mapStateToProps: WrappedMapStateToProps<TStateProps, TOwnProps, State>, mapDispatchToProps: WrappedMapDispatchToProps<TDispatchProps, TOwnProps>, mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>, dispatch: Dispatch<Action<unknown>>, { areStatesEqual, areOwnPropsEqual, areStatePropsEqual, }: PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State>): (nextState: State, nextOwnProps: TOwnProps) => TMergedProps; | ||
interface WrappedMapStateToProps<TStateProps, TOwnProps, State> { | ||
(state: State, ownProps: TOwnProps): TStateProps; | ||
readonly dependsOnOwnProps: boolean; | ||
} | ||
export default function finalPropsSelectorFactory<TStateProps, TOwnProps, TDispatchProps, TMergedProps, State = DefaultRootState>(dispatch: Dispatch<Action>, { initMapStateToProps, initMapDispatchToProps, initMergeProps, ...options }: SelectorFactoryOptions<TStateProps, TOwnProps, TDispatchProps, TMergedProps, State>): (nextState: State, nextOwnProps: TOwnProps) => TMergedProps; | ||
interface WrappedMapDispatchToProps<TDispatchProps, TOwnProps> { | ||
(dispatch: Dispatch<Action<unknown>>, ownProps: TOwnProps): TDispatchProps; | ||
readonly dependsOnOwnProps: boolean; | ||
} | ||
export interface SelectorFactoryOptions<TStateProps, TOwnProps, TDispatchProps, TMergedProps, State> extends PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> { | ||
initMapStateToProps: (dispatch: Dispatch, options: PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State>) => WrappedMapStateToProps<TStateProps, TOwnProps, State>; | ||
initMapDispatchToProps: (dispatch: Dispatch, options: PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State>) => WrappedMapDispatchToProps<TDispatchProps, TOwnProps>; | ||
initMergeProps: (dispatch: Dispatch, options: PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State>) => MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>; | ||
} | ||
export default function finalPropsSelectorFactory<TStateProps, TOwnProps, TDispatchProps, TMergedProps, State>(dispatch: Dispatch<Action<unknown>>, { initMapStateToProps, initMapDispatchToProps, initMergeProps, ...options }: SelectorFactoryOptions<TStateProps, TOwnProps, TDispatchProps, TMergedProps, State>): (nextState: State, nextOwnProps: TOwnProps) => TMergedProps; | ||
export {}; |
@@ -18,6 +18,4 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; | ||
state = firstState; | ||
ownProps = firstOwnProps; // @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); // @ts-ignore | ||
ownProps = firstOwnProps; | ||
stateProps = mapStateToProps(state, ownProps); | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
@@ -30,6 +28,4 @@ mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
function handleNewPropsAndNewState() { | ||
// @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
@@ -40,6 +36,4 @@ return mergedProps; | ||
function handleNewProps() { | ||
if (mapStateToProps.dependsOnOwnProps) // @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
@@ -51,4 +45,3 @@ return mergedProps; | ||
const nextStateProps = mapStateToProps(state, ownProps); | ||
const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); // @ts-ignore | ||
const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); | ||
stateProps = nextStateProps; | ||
@@ -55,0 +48,0 @@ if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps); |
@@ -6,3 +6,3 @@ import { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux'; | ||
}; | ||
declare type StateOrDispatch<S = AnyState> = S | Dispatch; | ||
declare type StateOrDispatch<S extends AnyState = AnyState> = S | Dispatch; | ||
declare type AnyProps = { | ||
@@ -9,0 +9,0 @@ [key: string]: any; |
import { Action, AnyAction, Dispatch } from 'redux'; | ||
import { Context } from 'react'; | ||
import { ReactReduxContextValue } from '../components/Context'; | ||
import { RootStateOrAny } from '../types'; | ||
/** | ||
@@ -11,3 +10,3 @@ * Hook factory, which creates a `useDispatch` hook bound to a given context. | ||
*/ | ||
export declare function createDispatchHook<S = RootStateOrAny, A extends Action = AnyAction>(context?: Context<ReactReduxContextValue<S, A>>): <AppDispatch extends Dispatch<A> = Dispatch<A>>() => AppDispatch; | ||
export declare function createDispatchHook<S = unknown, A extends Action = AnyAction>(context?: Context<ReactReduxContextValue<S, A>>): <AppDispatch extends Dispatch<A> = Dispatch<A>>() => AppDispatch; | ||
/** | ||
@@ -14,0 +13,0 @@ * A hook to access the redux `dispatch` function. |
import { ReactReduxContext } from '../components/Context'; | ||
import { useStore as useDefaultStore, createStoreHook } from './useStore'; | ||
/** | ||
@@ -10,2 +9,3 @@ * Hook factory, which creates a `useDispatch` hook bound to a given context. | ||
*/ | ||
export function createDispatchHook(context = ReactReduxContext) { | ||
@@ -12,0 +12,0 @@ const useStore = // @ts-ignore |
/// <reference types="react" /> | ||
import type { DefaultRootState, EqualityFn } from '../types'; | ||
import type { EqualityFn } from '../types'; | ||
import type { uSESWS } from '../utils/useSyncExternalStore'; | ||
@@ -11,3 +11,3 @@ export declare const initializeUseSelector: (fn: uSESWS) => void; | ||
*/ | ||
export declare function createSelectorHook(context?: import("react").Context<import("../components/Context").ReactReduxContextValue<any, import("redux").AnyAction>>): <TState = DefaultRootState, Selected = unknown>(selector: (state: TState) => Selected, equalityFn?: EqualityFn<Selected>) => Selected; | ||
export declare function createSelectorHook(context?: import("react").Context<import("../components/Context").ReactReduxContextValue<any, import("redux").AnyAction>>): <TState = unknown, Selected = unknown>(selector: (state: TState) => Selected, equalityFn?: EqualityFn<Selected>) => Selected; | ||
/** | ||
@@ -36,2 +36,2 @@ * A hook to access the redux store's state. This hook takes a selector function | ||
*/ | ||
export declare const useSelector: <TState = DefaultRootState, Selected = unknown>(selector: (state: TState) => Selected, equalityFn?: EqualityFn<Selected> | undefined) => Selected; | ||
export declare const useSelector: <TState = unknown, Selected = unknown>(selector: (state: TState) => Selected, equalityFn?: EqualityFn<Selected> | undefined) => Selected; |
import { Context } from 'react'; | ||
import { Action as BasicAction, AnyAction, Store } from 'redux'; | ||
import { ReactReduxContextValue } from '../components/Context'; | ||
import { RootStateOrAny } from '../types'; | ||
/** | ||
@@ -11,3 +10,3 @@ * Hook factory, which creates a `useStore` hook bound to a given context. | ||
*/ | ||
export declare function createStoreHook<S = RootStateOrAny, A extends BasicAction = AnyAction>(context?: Context<ReactReduxContextValue<S, A>>): <State = S, Action extends BasicAction<any> = A>() => Store<State, Action>; | ||
export declare function createStoreHook<S = unknown, A extends BasicAction = AnyAction>(context?: Context<ReactReduxContextValue<S, A>>): <State = S, Action extends BasicAction<any> = A>() => Store<State, Action>; | ||
/** | ||
@@ -28,2 +27,2 @@ * A hook to access the redux store. | ||
*/ | ||
export declare const useStore: <State = any, Action extends BasicAction<any> = AnyAction>() => Store<State, Action>; | ||
export declare const useStore: <State = unknown, Action extends BasicAction<any> = AnyAction>() => Store<State, Action>; |
import { useContext } from 'react'; | ||
import { ReactReduxContext } from '../components/Context'; | ||
import { useReduxContext as useDefaultReduxContext } from './useReduxContext'; | ||
/** | ||
@@ -11,2 +10,3 @@ * Hook factory, which creates a `useStore` hook bound to a given context. | ||
*/ | ||
export function createStoreHook(context = ReactReduxContext) { | ||
@@ -13,0 +13,0 @@ const useReduxContext = // @ts-ignore |
@@ -7,12 +7,3 @@ import { ClassAttributes, ComponentClass, ComponentType } from 'react'; | ||
export declare type EqualityFn<T> = (a: T, b: T) => boolean; | ||
/** | ||
* This interface can be augmented by users to add default types for the root state when | ||
* using `react-redux`. | ||
* Use module augmentation to append your own type definition in a your_custom_type.d.ts file. | ||
* https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation | ||
*/ | ||
export interface DefaultRootState { | ||
} | ||
export declare type AnyIfEmpty<T extends object> = keyof T extends never ? any : T; | ||
export declare type RootStateOrAny = AnyIfEmpty<DefaultRootState>; | ||
export declare type DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never; | ||
@@ -19,0 +10,0 @@ export interface DispatchProp<A extends Action = AnyAction> { |
@@ -243,3 +243,5 @@ "use strict"; | ||
WrappedComponent, | ||
// @ts-ignore | ||
initMapStateToProps, | ||
// @ts-ignore | ||
initMapDispatchToProps, | ||
@@ -246,0 +248,0 @@ // @ts-ignore |
@@ -29,6 +29,4 @@ "use strict"; | ||
state = firstState; | ||
ownProps = firstOwnProps; // @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); // @ts-ignore | ||
ownProps = firstOwnProps; | ||
stateProps = mapStateToProps(state, ownProps); | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
@@ -41,6 +39,4 @@ mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
function handleNewPropsAndNewState() { | ||
// @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
@@ -51,6 +47,4 @@ return mergedProps; | ||
function handleNewProps() { | ||
if (mapStateToProps.dependsOnOwnProps) // @ts-ignore | ||
stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) // @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps); | ||
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps); | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps); | ||
@@ -62,4 +56,3 @@ return mergedProps; | ||
const nextStateProps = mapStateToProps(state, ownProps); | ||
const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); // @ts-ignore | ||
const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps); | ||
stateProps = nextStateProps; | ||
@@ -66,0 +59,0 @@ if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps); |
{ | ||
"name": "react-redux", | ||
"version": "8.0.0-beta.4", | ||
"version": "8.0.0-rc.0", | ||
"description": "Official React bindings for Redux", | ||
@@ -46,2 +46,5 @@ "keywords": [ | ||
"peerDependenciesMeta": { | ||
"@types/react": { | ||
"optional": true | ||
}, | ||
"react-dom": { | ||
@@ -85,7 +88,6 @@ "optional": true | ||
"@types/object-assign": "^4.0.30", | ||
"@types/react": "^17.0.43", | ||
"@types/react-dom": "^17.0.14", | ||
"@types/react-is": "^17.0.3", | ||
"@types/react-native": "^0.64.12", | ||
"@types/react-redux": "^7.1.18", | ||
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"@types/react-is": "^17", | ||
"@types/react-native": "^0.67.4", | ||
"@typescript-eslint/eslint-plugin": "^4.28.0", | ||
@@ -92,0 +94,0 @@ "@typescript-eslint/parser": "^4.28.0", |
import type { Dispatch, Action } from 'redux' | ||
import verifySubselectors from './verifySubselectors' | ||
import type { DefaultRootState, EqualityFn } from '../types' | ||
import type { EqualityFn } from '../types' | ||
export type SelectorFactory<S, TProps, TOwnProps, TFactoryOptions> = ( | ||
dispatch: Dispatch<Action>, | ||
dispatch: Dispatch<Action<unknown>>, | ||
factoryOptions: TFactoryOptions | ||
@@ -16,13 +16,8 @@ ) => Selector<S, TProps, TOwnProps> | ||
export type MapStateToProps< | ||
TStateProps, | ||
TOwnProps, | ||
State = DefaultRootState | ||
> = (state: State, ownProps: TOwnProps) => TStateProps | ||
export type MapStateToProps<TStateProps, TOwnProps, State> = ( | ||
state: State, | ||
ownProps: TOwnProps | ||
) => TStateProps | ||
export type MapStateToPropsFactory< | ||
TStateProps, | ||
TOwnProps, | ||
State = DefaultRootState | ||
> = ( | ||
export type MapStateToPropsFactory<TStateProps, TOwnProps, State> = ( | ||
initialState: State, | ||
@@ -32,7 +27,3 @@ ownProps: TOwnProps | ||
export type MapStateToPropsParam< | ||
TStateProps, | ||
TOwnProps, | ||
State = DefaultRootState | ||
> = | ||
export type MapStateToPropsParam<TStateProps, TOwnProps, State> = | ||
| MapStateToPropsFactory<TStateProps, TOwnProps, State> | ||
@@ -44,3 +35,3 @@ | MapStateToProps<TStateProps, TOwnProps, State> | ||
export type MapDispatchToPropsFunction<TDispatchProps, TOwnProps> = ( | ||
dispatch: Dispatch<Action>, | ||
dispatch: Dispatch<Action<unknown>>, | ||
ownProps: TOwnProps | ||
@@ -54,3 +45,3 @@ ) => TDispatchProps | ||
export type MapDispatchToPropsFactory<TDispatchProps, TOwnProps> = ( | ||
dispatch: Dispatch<Action>, | ||
dispatch: Dispatch<Action<unknown>>, | ||
ownProps: TOwnProps | ||
@@ -73,9 +64,6 @@ ) => MapDispatchToPropsFunction<TDispatchProps, TOwnProps> | ||
interface PureSelectorFactoryComparisonOptions< | ||
TOwnProps, | ||
State = DefaultRootState | ||
> { | ||
interface PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> { | ||
areStatesEqual: EqualityFn<State> | ||
areOwnPropsEqual: EqualityFn<TOwnProps> | ||
areStatePropsEqual: EqualityFn<unknown> | ||
areStatePropsEqual: EqualityFn<TStateProps> | ||
displayName: string | ||
@@ -89,12 +77,8 @@ } | ||
TMergedProps, | ||
State = DefaultRootState | ||
State | ||
>( | ||
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State> & { | ||
dependsOnOwnProps: boolean | ||
}, | ||
mapDispatchToProps: MapDispatchToPropsParam<TDispatchProps, TOwnProps> & { | ||
dependsOnOwnProps: boolean | ||
}, | ||
mapStateToProps: WrappedMapStateToProps<TStateProps, TOwnProps, State>, | ||
mapDispatchToProps: WrappedMapDispatchToProps<TDispatchProps, TOwnProps>, | ||
mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>, | ||
dispatch: Dispatch, | ||
dispatch: Dispatch<Action<unknown>>, | ||
{ | ||
@@ -104,3 +88,3 @@ areStatesEqual, | ||
areStatePropsEqual, | ||
}: PureSelectorFactoryComparisonOptions<TOwnProps, State> | ||
}: PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> | ||
) { | ||
@@ -117,6 +101,4 @@ let hasRunAtLeastOnce = false | ||
ownProps = firstOwnProps | ||
// @ts-ignore | ||
stateProps = mapStateToProps!(state, ownProps) | ||
// @ts-ignore | ||
dispatchProps = mapDispatchToProps!(dispatch, ownProps) | ||
stateProps = mapStateToProps(state, ownProps) | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps) | ||
mergedProps = mergeProps(stateProps, dispatchProps, ownProps) | ||
@@ -128,7 +110,5 @@ hasRunAtLeastOnce = true | ||
function handleNewPropsAndNewState() { | ||
// @ts-ignore | ||
stateProps = mapStateToProps!(state, ownProps) | ||
stateProps = mapStateToProps(state, ownProps) | ||
if (mapDispatchToProps!.dependsOnOwnProps) | ||
// @ts-ignore | ||
if (mapDispatchToProps.dependsOnOwnProps) | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps) | ||
@@ -141,8 +121,6 @@ | ||
function handleNewProps() { | ||
if (mapStateToProps!.dependsOnOwnProps) | ||
// @ts-ignore | ||
stateProps = mapStateToProps!(state, ownProps) | ||
if (mapStateToProps.dependsOnOwnProps) | ||
stateProps = mapStateToProps(state, ownProps) | ||
if (mapDispatchToProps.dependsOnOwnProps) | ||
// @ts-ignore | ||
dispatchProps = mapDispatchToProps(dispatch, ownProps) | ||
@@ -157,3 +135,2 @@ | ||
const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps) | ||
// @ts-ignore | ||
stateProps = nextStateProps | ||
@@ -189,2 +166,12 @@ | ||
interface WrappedMapStateToProps<TStateProps, TOwnProps, State> { | ||
(state: State, ownProps: TOwnProps): TStateProps | ||
readonly dependsOnOwnProps: boolean | ||
} | ||
interface WrappedMapDispatchToProps<TDispatchProps, TOwnProps> { | ||
(dispatch: Dispatch<Action<unknown>>, ownProps: TOwnProps): TDispatchProps | ||
readonly dependsOnOwnProps: boolean | ||
} | ||
export interface SelectorFactoryOptions< | ||
@@ -195,15 +182,15 @@ TStateProps, | ||
TMergedProps, | ||
State = DefaultRootState | ||
> extends PureSelectorFactoryComparisonOptions<TOwnProps, State> { | ||
State | ||
> extends PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> { | ||
initMapStateToProps: ( | ||
dispatch: Dispatch, | ||
options: PureSelectorFactoryComparisonOptions<TOwnProps, State> | ||
) => MapStateToPropsParam<TStateProps, TOwnProps, State> | ||
options: PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> | ||
) => WrappedMapStateToProps<TStateProps, TOwnProps, State> | ||
initMapDispatchToProps: ( | ||
dispatch: Dispatch, | ||
options: PureSelectorFactoryComparisonOptions<TOwnProps, State> | ||
) => MapDispatchToPropsParam<TDispatchProps, TOwnProps> | ||
options: PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> | ||
) => WrappedMapDispatchToProps<TDispatchProps, TOwnProps> | ||
initMergeProps: ( | ||
dispatch: Dispatch, | ||
options: PureSelectorFactoryComparisonOptions<TOwnProps, State> | ||
options: PureSelectorFactoryComparisonOptions<TStateProps, TOwnProps, State> | ||
) => MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> | ||
@@ -223,5 +210,5 @@ } | ||
TMergedProps, | ||
State = DefaultRootState | ||
State | ||
>( | ||
dispatch: Dispatch<Action>, | ||
dispatch: Dispatch<Action<unknown>>, | ||
{ | ||
@@ -254,4 +241,3 @@ initMapStateToProps, | ||
State | ||
// @ts-ignore | ||
>(mapStateToProps!, mapDispatchToProps, mergeProps, dispatch, options) | ||
>(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options) | ||
} |
@@ -7,3 +7,3 @@ import { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux' | ||
type AnyState = { [key: string]: any } | ||
type StateOrDispatch<S = AnyState> = S | Dispatch | ||
type StateOrDispatch<S extends AnyState = AnyState> = S | Dispatch | ||
@@ -10,0 +10,0 @@ type AnyProps = { [key: string]: any } |
@@ -9,3 +9,2 @@ import { Action, AnyAction, Dispatch } from 'redux' | ||
import { useStore as useDefaultStore, createStoreHook } from './useStore' | ||
import { RootStateOrAny } from '../types' | ||
@@ -19,3 +18,3 @@ /** | ||
export function createDispatchHook< | ||
S = RootStateOrAny, | ||
S = unknown, | ||
A extends Action = AnyAction | ||
@@ -22,0 +21,0 @@ // @ts-ignore |
@@ -5,3 +5,3 @@ import { useContext, useDebugValue } from 'react' | ||
import { ReactReduxContext } from '../components/Context' | ||
import type { DefaultRootState, EqualityFn } from '../types' | ||
import type { EqualityFn } from '../types' | ||
import type { uSESWS } from '../utils/useSyncExternalStore' | ||
@@ -25,3 +25,3 @@ import { notInitialized } from '../utils/useSyncExternalStore' | ||
context = ReactReduxContext | ||
): <TState = DefaultRootState, Selected = unknown>( | ||
): <TState = unknown, Selected = unknown>( | ||
selector: (state: TState) => Selected, | ||
@@ -28,0 +28,0 @@ equalityFn?: EqualityFn<Selected> |
@@ -8,3 +8,2 @@ import { useContext, Context } from 'react' | ||
import { useReduxContext as useDefaultReduxContext } from './useReduxContext' | ||
import { RootStateOrAny } from '../types' | ||
@@ -18,3 +17,3 @@ /** | ||
export function createStoreHook< | ||
S = RootStateOrAny, | ||
S = unknown, | ||
A extends BasicAction = AnyAction | ||
@@ -21,0 +20,0 @@ // @ts-ignore |
@@ -13,13 +13,3 @@ import { ClassAttributes, ComponentClass, ComponentType } from 'react' | ||
/** | ||
* This interface can be augmented by users to add default types for the root state when | ||
* using `react-redux`. | ||
* Use module augmentation to append your own type definition in a your_custom_type.d.ts file. | ||
* https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation | ||
*/ | ||
// tslint:disable-next-line:no-empty-interface | ||
export interface DefaultRootState {} | ||
export type AnyIfEmpty<T extends object> = keyof T extends never ? any : T | ||
export type RootStateOrAny = AnyIfEmpty<DefaultRootState> | ||
@@ -26,0 +16,0 @@ export type DistributiveOmit<T, K extends keyof T> = T extends unknown |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53
313880
6573