import { verifyPlainObject } from '../utils/verifyPlainObject' ; import type { MergeProps } from './types' ; import type { ConsumerContext } from '../types' ; const defaultMergeProps = ( stateProps , contextProps , ownProps ) => { return { ... ownProps , ... stateProps , ... contextProps } ; } ; interface Options { displayName : string ; pure : boolean ; areMergedPropsEqual : ( nextProps : any , props : any ) => boolean ; } function wrapMergePropsFunc ( mergeProps ) { return function initMergePropsProxy ( context , { displayName , pure , areMergedPropsEqual } ) { let hasRunOnce = false ; let mergedProps ; return function mergePropsProxy ( stateProps , contextProps , ownProps ) { const nextMergedProps = mergeProps ( stateProps , contextProps , ownProps ) ; if ( hasRunOnce ) { if ( ! pure || ! areMergedPropsEqual ( nextMergedProps , mergedProps ) ) { mergedProps = nextMergedProps ; } } else { hasRunOnce = true ; mergedProps = nextMergedProps ; if ( process . env . NODE_ENV !== 'production' ) { verifyPlainObject ( mergedProps , displayName , 'mergeProps' ) ; } } return mergedProps ; } ; } ; } export function whenMergePropsIsFunction ( mergeProps ) { return typeof mergeProps === 'function' ? wrapMergePropsFunc ( mergeProps ) : undefined ; } export function whenMergePropsIsOmitted ( mergeProps ) { return ! mergeProps ? ( ) => defaultMergeProps : undefined ; } export const mergePropsFactories = [ whenMergePropsIsFunction , whenMergePropsIsOmitted ] ;