( mapToProps: MapToProps, methodName: string, )
| 66 | // the developer that their mapToProps function is not returning a valid result. |
| 67 | // |
| 68 | export function wrapMapToPropsFunc<P extends AnyProps = AnyProps>( |
| 69 | mapToProps: MapToProps, |
| 70 | methodName: string, |
| 71 | ) { |
| 72 | return function initProxySelector( |
| 73 | dispatch: Dispatch, |
| 74 | { displayName }: { displayName: string }, |
| 75 | ) { |
| 76 | const proxy = function mapToPropsProxy( |
| 77 | stateOrDispatch: StateOrDispatch, |
| 78 | ownProps?: P, |
| 79 | ): MapToProps { |
| 80 | return proxy.dependsOnOwnProps |
| 81 | ? proxy.mapToProps(stateOrDispatch, ownProps) |
| 82 | : proxy.mapToProps(stateOrDispatch, undefined) |
| 83 | } |
| 84 | |
| 85 | // allow detectFactoryAndVerify to get ownProps |
| 86 | proxy.dependsOnOwnProps = true |
| 87 | |
| 88 | proxy.mapToProps = function detectFactoryAndVerify( |
| 89 | stateOrDispatch: StateOrDispatch, |
| 90 | ownProps?: P, |
| 91 | ): MapToProps { |
| 92 | proxy.mapToProps = mapToProps |
| 93 | proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps) |
| 94 | let props = proxy(stateOrDispatch, ownProps) |
| 95 | |
| 96 | if (typeof props === 'function') { |
| 97 | proxy.mapToProps = props |
| 98 | proxy.dependsOnOwnProps = getDependsOnOwnProps(props) |
| 99 | props = proxy(stateOrDispatch, ownProps) |
| 100 | } |
| 101 | |
| 102 | if (process.env.NODE_ENV !== 'production') |
| 103 | verifyPlainObject(props, displayName, methodName) |
| 104 | |
| 105 | return props |
| 106 | } |
| 107 | |
| 108 | return proxy |
| 109 | } |
| 110 | } |
no test coverage detected
searching dependent graphs…