import always from '@tinkoff/utils/function/always' ; import mapObject from '@tinkoff/utils/object/map' ; import { verifyPlainObject } from '../utils/verifyPlainObject' ; import { verifyFunction } from '../utils/verifyFunction' ; import type { ConsumerContext } from '../types' ; export interface Options { displayName : string ; } export function wrapMapToPropsConstant ( getConstant ) { return function initConstantSelector ( context , options ) { const constantSelector = always ( getConstant ( context , options ) ) ; ( constantSelector as any ) . dependsOnOwnProps = false ; return constantSelector ; } ; } export function getDependsOnOwnProps ( mapToProps ) { return mapToProps . dependsOnOwnProps !== null && mapToProps . dependsOnOwnProps !== undefined ? Boolean ( mapToProps . dependsOnOwnProps ) : mapToProps . length !== 1 ; } export function wrapMapToPropsFunc ( mapToProps , methodName ) { return function initProxySelector ( context , { displayName } ) { const proxy = ( stateOrContext , ownProps ) => proxy . dependsOnOwnProps ? proxy . mapToProps ( stateOrContext , ownProps ) : proxy . mapToProps ( stateOrContext , undefined ) ; proxy . dependsOnOwnProps = true ; proxy . mapToProps = function detectFactoryAndVerify ( stateOrContext , ownProps ) { proxy . mapToProps = mapToProps ; proxy . dependsOnOwnProps = getDependsOnOwnProps ( mapToProps ) ; let props = proxy ( stateOrContext , ownProps ) ; if ( typeof props === 'function' ) { proxy . mapToProps = props ; proxy . dependsOnOwnProps = getDependsOnOwnProps ( props ) ; props = proxy ( stateOrContext , ownProps ) ; } if ( process . env . NODE_ENV !== 'production' ) { verifyPlainObject ( props , displayName , methodName ) ; } return props ; } ; return proxy ; } ; } export function wrapMapToPropsObject ( actionsObject ) { function getConstant ( { executeAction } , { displayName } ) { return mapObject ( ( action , actionName ) => { if ( process . env . NODE_ENV !== 'production' ) { verifyFunction ( action , displayName , actionName ) ; } return ( params ) => executeAction ( action , params ) ; } , actionsObject ) ; } return wrapMapToPropsConstant ( getConstant ) ; }