import { ReactNode , FunctionComponent } from 'react' ; import { Enhancer , EnhancerContext , EnhancerList } from './types' ; import { flatten , generateNewVariable , generateHOCFunction , combineEnhancerResults , transformHOCFunction , } from './util' ; interface Generic1 < A > { } interface Generic2 < A , B > { } interface Generic3 < A , B , C > { } type Enhance < T > = ( component : ReactNode ) => FunctionComponent < T > ; export function compose < A , B , C , T extends Generic3 < A , B , C > > ( ... enhancers ) ; export function compose < A , B , T extends Generic2 < A , B > > ( ... enhancers ) ; export function compose < A , T extends Generic1 < A > > ( ... enhancers ) ; export function compose < T > ( ... enhancers ) ; export function compose < T > ( ... enhancers ) { return ( component ) : FunctionComponent < T > => { const context = { component , generateNewVariable : generateNewVariable ( ) , } ; const enhancersArray = flatten < Enhancer > ( enhancers , Infinity ) ; const results = combineEnhancerResults ( enhancersArray . map ( ( enhancer ) => enhancer ( context ) ) ) ; const originalHoc = generateHOCFunction < T > ( results , component ) ; const hoc = transformHOCFunction < T > ( originalHoc , results . componentTransforms ) ; return hoc ; } ; }