重新选择一个很大的开关

时间:2018-10-02 12:16:44

标签: javascript node.js refactoring

我目前正在重构代码JS,但是我阻止了一个我无法简化的开关,有人会对这个问题有意见吗?

对于仿真来说,这是一个检测功能名称的问题,如果有对应关系,则进入添加特定于该功能的代码后的阶段

            let getCodeFunctionOfLibrary = (functionName) => {
                try {
                    switch (functionName) {
                        case libCalcul.calculFieldSubstract.name:
                        case libCalcul.calculFieldDevide.name:
                        case libCalcul.calculFieldMultiply.name:
                        case libCalcul.calculFieldSubstract.name:
                        case libCalcul.calculFieldSum.name:
                            getLibraryFunctionCode(libCalcul.calculFieldDevide, libCalcul.calculFieldMultiply, libCalcul.calculFieldSubstract, libCalcul.calculFieldSum);
                            break;

                        case libComparValue.compareValue.name:
                            getLibraryFunctionCode(libComparValue.compareValue);
                            break;

                        case libCreatSVG.createSvgElement.name:
                            getLibraryFunctionCode(libCreatSVG.createSvgElement);
                            break;

                        case libDate.calculDateSubstract.name:
                        case libDate.calculDateSum.name:
                        case libDate.compareDate.name:
                            getLibraryFunctionCode(libDate.calculDateSubstract,
                                libDate.calculDateSum,
                                libDate.compareDate);
                            break;

                        case libDateToValue.transformDateToFieldValue.name:
                        case transformFieldToDate.name:
                            getLibraryFunctionCode(libDateToValue.transformDateToFieldValue,
                                libValueToDate.transformFieldToDate);
                            break;

                        case libDisable.disableField.name:
                            getLibraryFunctionCode(libDisable.disableField,
                                libDisable.disableBooleanField,
                                libDisable.disableDateField,
                                libDisable.disableFileField,
                                libDisable.disableTextareaField,
                                libDisable.disableCustomField);
                            break;

                        case libPopupLink.popupLink.name:
                            getLibraryFunctionCode(libPopupLink.popupLink);
                            break;

                        case libPreFill.preFillField.name:
                            getLibraryFunctionCode(libPreFill.preFillField);
                            break;

                        case libRemoveOption.removeOption.name:
                            getLibraryFunctionCode(libRemoveOption.removeOption);
                            break;

                        case libSecuFrench.controlFrenchSocialSecurityNumber.name:
                            getLibraryFunctionCode(libSecuFrench.controlFrenchSocialSecurityNumber);
                            break;

                        case libSelectSurveyAnswer.selectSurveyAnswer.name:
                            getLibraryFunctionCode(libSelectSurveyAnswer.selectSurveyAnswer);
                            break;

                        case libStartSurvey.addStarSurveyClass.name:
                            getLibraryFunctionCode(libStartSurvey.addStarSurveyClass);
                            break;

                        case libUnauthorizadeCharacters.unauthorizedCharacter.name:
                            getLibraryFunctionCode(libUnauthorizadeCharacters.unauthorizedCharacter);
                            break;

                        default:
                            getLibraryFunctionCode();
                    }

                } catch (error) {
                    console.log(error.message);
                }
            };

0 个答案:

没有答案