sevenLee
2/7/2018 - 6:28 PM

DropDownComponentFactory

import React, {Component} from 'react'
import Loadable from 'react-loadable';

const DropDownComponentFactory = (componentPath='') => (selectedValue, rule) => wrapperComponentProps => {
    let componentName = ''
    const rule1 = (selectedValue) => {
        const strList = selectedValue.split('_')

        return strList.map(str => {
            const lowerCaseStr = str.toLowerCase()
            return str[0] + lowerCaseStr.slice(1)
        }).join('')
    }
    if(selectedValue){
        switch(rule){
            case 'rule1': {
                componentName = rule1(selectedValue)
                break
            }
            default: {
                break
            }
        }
    }

    const makeImport = () => {
        let result

        async function awaitImport(){
            let r
            try{
                console.log('@@@ [awaitImport] componentPath:', componentPath)
                console.log('@@@ [awaitImport] componentName:', componentName)
                r = await import(`./../../../features${componentPath}/${componentName}`)
            }catch(err){
                console.log('err:', err)
                r = Promise.reject(err)
            }
            return r
        }
        result = awaitImport()
        return result
    }

    const LoadableBar = Loadable({
        loader: () => makeImport(),
        loading: () => <div>Loading... </div>
    });

    return class extends Component{
        render() {
            return <LoadableBar {...wrapperComponentProps}/>
        }
    }
}

export default DropDownComponentFactory
const CreditFactory = {
            JackpotWheel,
            JackpotWheel2
        }
        let selectedValue = form.getFieldValue('prizeType')
        const typeMap = {'JACKPOT_WHEEL': 'JackpotWheel', 'JACKPOT_WHEEL2': 'JackpotWheel2'}
        const propsMap = {'JACKPOT_WHEEL': 0, 'JACKPOT_WHEEL2': 1}
        const CreditFactoryItem = CreditFactory[typeMap[selectedValue]]

        const componentPropertyListForCredit = [{
            intl,
            messages,
            actionType,
            creditConfigRows,
            addCredit,
            updateCredit,
            deleteCredit,
            getNodeAndFieldName: (InputRuleDom, fieldName) => this.makeInputDomProperty(InputRuleDom, fieldName),
            subscribeInputRuleContext: (inputRuleContext, fieldName) => this.subscribeInputRuleContext(inputRuleContext, fieldName),
            getRuleErrorAndFieldName: (error, fieldName) => this.makeErrorObj(error, fieldName)
        },{
            here2: 'here2',
            im2: 'im2'
        }]
import React, {Component} from 'react'
// import Loadable from 'react-loadable';
import JackpotWheel from './JackpotWheel'

const DropDownComponentFactory = selectedValue => wrapperComponentProps => {



    return class extends Component{
        render() {
            const factory = {
                JackpotWheel
            }

            const strList = selectedValue.split('_')

            const ComponentName = strList.map(str => {
                const lowerCaseStr = str.toLowerCase()
                return str[0] + lowerCaseStr.slice(1)
            }).join('')

            const FactoryItem = factory[ComponentName]

            return (
                <FactoryItem {...wrapperComponentProps}/>
            )
        }
    }
}

export default DropDownComponentFactory
import React, {Component} from 'react'
import Loadable from 'react-loadable';

const DropDownComponentFactory = (componentPath='') => (selectedValue, rule) => wrapperComponentProps => {
    let componentName = ''
    const rule1 = (selectedValue) => {
        const strList = selectedValue.split('_')

        return strList.map(str => {
            const lowerCaseStr = str.toLowerCase()
            return str[0] + lowerCaseStr.slice(1)
        }).join('')
    }
    if(selectedValue){
        switch(rule){
            case 'rule1': {
                componentName = rule1(selectedValue)
                break
            }
            default: {
                break
            }
        }
    }

    const makeImport = () => {
        let result

        async function awaitImport(){
            let r
            try{
                console.log('@@@ [awaitImport] componentPath:', componentPath)
                console.log('@@@ [awaitImport] componentName:', componentName)
                r = await import(`./../../../features${componentPath}/${componentName}`)
            }catch(err){
                console.log('err:', err)
                r = Promise.reject(err)
            }
            return r
        }
        result = awaitImport()
        return result
    }

    const LoadableBar = Loadable({
        loader: () => makeImport(),
        loading: () => <div>Loading... </div>
    });

    return class extends Component{
        render() {
            return <LoadableBar {...wrapperComponentProps}/>
        }
    }
}

export default DropDownComponentFactory