import React , { ComponentType , FunctionComponent } from 'react' ; import { connect } from 'react-redux' ; import { PhoneContext } from './phoneContext' ; export type connectModuleProps < T > = ( props : T ) => any ; function connectModule < T = any , K = any > ( fn ) { return ( Comp ) => { const WithModule = connect ( ( _ , props ) => fn ( props . phone ) . getUIProps ( props ) , ( _ , props ) => fn ( props . phone ) . getUIFunctions ( props ) ) ( Comp ) ; return ( ( props ) => ( < PhoneContext . Consumer > { ( phone ) => < WithModule phone = { phone } { ... props } />} < /PhoneContext.Consumer>)) as any as FunctionComponent<K>; } ; } export default connectModule ;