1
+ import { Dispatch } from 'redux'
2
+
1
3
import verifyPlainObject from '../utils/verifyPlainObject'
2
4
3
- export function wrapMapToPropsConstant ( getConstant ) {
4
- return function initConstantSelector ( dispatch , options ) {
5
+ export type MapToProps = {
6
+ ( stateOrDispatch : any , ownProps ?: any ) : any
7
+ dependsOnOwnProps : boolean
8
+ }
9
+
10
+ export function wrapMapToPropsConstant (
11
+ getConstant : ( dispatch : Dispatch , options : any ) => void
12
+ ) {
13
+ return function initConstantSelector ( dispatch : Dispatch , options : any ) {
5
14
const constant = getConstant ( dispatch , options )
6
15
7
16
function constantSelector ( ) {
@@ -19,9 +28,8 @@ export function wrapMapToPropsConstant(getConstant) {
19
28
// A length of one signals that mapToProps does not depend on props from the parent component.
20
29
// A length of zero is assumed to mean mapToProps is getting args via arguments or ...args and
21
30
// therefore not reporting its length accurately..
22
- export function getDependsOnOwnProps ( mapToProps ) {
23
- return mapToProps . dependsOnOwnProps !== null &&
24
- mapToProps . dependsOnOwnProps !== undefined
31
+ export function getDependsOnOwnProps ( mapToProps : MapToProps ) {
32
+ return mapToProps ?. dependsOnOwnProps
25
33
? Boolean ( mapToProps . dependsOnOwnProps )
26
34
: mapToProps . length !== 1
27
35
}
@@ -38,20 +46,26 @@ export function getDependsOnOwnProps(mapToProps) {
38
46
// * On first call, verifies the first result is a plain object, in order to warn
39
47
// the developer that their mapToProps function is not returning a valid result.
40
48
//
41
- export function wrapMapToPropsFunc ( mapToProps , methodName ) {
42
- return function initProxySelector ( dispatch , { displayName } ) {
43
- const proxy = function mapToPropsProxy ( stateOrDispatch , ownProps ) {
49
+ export function wrapMapToPropsFunc ( mapToProps : MapToProps , methodName : string ) {
50
+ return function initProxySelector (
51
+ dispatch : Dispatch ,
52
+ { displayName } : { displayName : string }
53
+ ) {
54
+ const proxy = function mapToPropsProxy (
55
+ stateOrDispatch : any ,
56
+ ownProps : any
57
+ ) : any {
44
58
return proxy . dependsOnOwnProps
45
59
? proxy . mapToProps ( stateOrDispatch , ownProps )
46
- : proxy . mapToProps ( stateOrDispatch )
60
+ : proxy . mapToProps ( stateOrDispatch , null )
47
61
}
48
62
49
63
// allow detectFactoryAndVerify to get ownProps
50
64
proxy . dependsOnOwnProps = true
51
65
52
66
proxy . mapToProps = function detectFactoryAndVerify (
53
- stateOrDispatch ,
54
- ownProps
67
+ stateOrDispatch : any ,
68
+ ownProps : any
55
69
) {
56
70
proxy . mapToProps = mapToProps
57
71
proxy . dependsOnOwnProps = getDependsOnOwnProps ( mapToProps )
0 commit comments