-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7fdad0
commit 19cc9e4
Showing
6 changed files
with
98 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Action, Dispatch } from 'redux' | ||
|
||
export function createInvalidArgFactory(arg: unknown, name: string) { | ||
return ( | ||
dispatch: Dispatch<Action<unknown>>, | ||
options: { readonly wrappedComponentName: string } | ||
) => { | ||
throw new Error( | ||
`Invalid value of type ${typeof arg} for ${name} argument when connecting component ${ | ||
options.wrappedComponentName | ||
}.` | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,25 @@ | ||
import { ActionCreatorsMapObject, Dispatch } from 'redux' | ||
import { FixTypeLater } from '../types' | ||
import type { Action, Dispatch } from 'redux' | ||
import bindActionCreators from '../utils/bindActionCreators' | ||
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps' | ||
import { createInvalidArgFactory } from './invalidArgFactory' | ||
import type { MapDispatchToPropsParam } from './selectorFactory' | ||
|
||
export function whenMapDispatchToPropsIsFunction( | ||
mapDispatchToProps: ActionCreatorsMapObject | FixTypeLater | ||
) { | ||
return typeof mapDispatchToProps === 'function' | ||
? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') | ||
: undefined | ||
} | ||
|
||
export function whenMapDispatchToPropsIsMissing(mapDispatchToProps: undefined) { | ||
return !mapDispatchToProps | ||
? wrapMapToPropsConstant((dispatch: Dispatch) => ({ | ||
dispatch, | ||
})) | ||
: undefined | ||
} | ||
|
||
export function whenMapDispatchToPropsIsObject( | ||
mapDispatchToProps: ActionCreatorsMapObject | ||
export function mapDispatchToPropsFactory<TDispatchProps, TOwnProps>( | ||
mapDispatchToProps: | ||
| MapDispatchToPropsParam<TDispatchProps, TOwnProps> | ||
| undefined | ||
) { | ||
return mapDispatchToProps && typeof mapDispatchToProps === 'object' | ||
? wrapMapToPropsConstant((dispatch: Dispatch) => | ||
? wrapMapToPropsConstant((dispatch: Dispatch<Action<unknown>>) => | ||
// @ts-ignore | ||
bindActionCreators(mapDispatchToProps, dispatch) | ||
) | ||
: undefined | ||
: !mapDispatchToProps | ||
? wrapMapToPropsConstant((dispatch: Dispatch<Action<unknown>>) => ({ | ||
dispatch, | ||
})) | ||
: typeof mapDispatchToProps === 'function' | ||
? // @ts-ignore | ||
wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') | ||
: createInvalidArgFactory(mapDispatchToProps, 'mapDispatchToProps') | ||
} | ||
|
||
export default [ | ||
whenMapDispatchToPropsIsFunction, | ||
whenMapDispatchToPropsIsMissing, | ||
whenMapDispatchToPropsIsObject, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import { | ||
MapToProps, | ||
wrapMapToPropsConstant, | ||
wrapMapToPropsFunc, | ||
} from './wrapMapToProps' | ||
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps' | ||
import { createInvalidArgFactory } from './invalidArgFactory' | ||
import type { MapStateToPropsParam } from './selectorFactory' | ||
|
||
export function whenMapStateToPropsIsFunction(mapStateToProps?: MapToProps) { | ||
return typeof mapStateToProps === 'function' | ||
? wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps') | ||
: undefined | ||
export function mapStateToPropsFactory<TStateProps, TOwnProps, State>( | ||
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State> | ||
) { | ||
return !mapStateToProps | ||
? wrapMapToPropsConstant(() => ({})) | ||
: typeof mapStateToProps === 'function' | ||
? // @ts-ignore | ||
wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps') | ||
: createInvalidArgFactory(mapStateToProps, 'mapStateToProps') | ||
} | ||
|
||
export function whenMapStateToPropsIsMissing(mapStateToProps?: MapToProps) { | ||
return !mapStateToProps ? wrapMapToPropsConstant(() => ({})) : undefined | ||
} | ||
|
||
export default [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters