import React from 'react' ; import pick from 'lodash/pick' ; import assign from 'lodash/assign' ; import sula from '../core' ; import { RenderPlugin } from '../types/plugin' ; export function registerRenderPlugin < Context = unknown > ( pluginName , extraPropsName ? ) { return function wrapComponent ( Component , needCtxAndConfig ? ) { sula . renderType ( pluginName , ( ctx , config = { } as RenderPlugin ) => { const props = config . props || { } ; let extraProps ; if ( extraPropsName && extraPropsName . length ) { extraProps = pick ( config , extraPropsName ) ; } if ( needCtxAndConfig ) { extraProps = extraProps ? extraProps : { } ; extraProps . ctx = ctx ; extraProps . config = config ; } return React . createElement ( Component , extraProps ? assign ( extraProps , props ) : props ) ; } ) ; } ; }