You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1.0 KiB
26 lines
1.0 KiB
3 years ago
|
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 mapDispatchToPropsFactory<TDispatchProps, TOwnProps>(
|
||
|
mapDispatchToProps:
|
||
|
| MapDispatchToPropsParam<TDispatchProps, TOwnProps>
|
||
|
| undefined
|
||
|
) {
|
||
|
return mapDispatchToProps && typeof mapDispatchToProps === 'object'
|
||
|
? wrapMapToPropsConstant((dispatch: Dispatch<Action<unknown>>) =>
|
||
|
// @ts-ignore
|
||
|
bindActionCreators(mapDispatchToProps, dispatch)
|
||
|
)
|
||
|
: !mapDispatchToProps
|
||
|
? wrapMapToPropsConstant((dispatch: Dispatch<Action<unknown>>) => ({
|
||
|
dispatch,
|
||
|
}))
|
||
|
: typeof mapDispatchToProps === 'function'
|
||
|
? // @ts-ignore
|
||
|
wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps')
|
||
|
: createInvalidArgFactory(mapDispatchToProps, 'mapDispatchToProps')
|
||
|
}
|