react: typescript system params method optimize

import * as _ from "lodash";
import paramCache from "../common/param-cache"
import RequestPromise from "./axios-service/RequestPromise";

export const fetchSystemParams = () => {
    return RequestPromise({ url: ‘/api/system-parameters‘ })
}
const parameters = paramCache.getItem("system-params")

export const getParam = async (types: string[]) => {
    if (parameters) {
        return mergeSpecailParams(parameters, types)
    } else {
        return fetchSystemParams().then(({ data }) => {
            paramCache.setItem("system-params", data)
            return mergeSpecailParams(data, types)
        })
    }
}

export const getParamKeys = async (type: string) => {
    if (parameters) {
        return setParamKeys(parameters)
    } else {
        return fetchSystemParams().then(({ data }) => {
            paramCache.setItem("system-params", data)
            return setParamKeys(data[type])
        })
    }
}

const setParamKeys = (params: any) => {
    const paramKeys: string[] = [];
    for (const key in params) {
        if (params.hasOwnProperty(key)) {
            paramKeys.push(key)
        }
    }
    return paramKeys
}

export const getParamOptions = async (types: string[]) => {
    if (parameters) {
        return setParamOptions(mergeSpecailParams(parameters, types))
    } else {
        return fetchSystemParams().then(({ data }) => {
            paramCache.setItem("system-params", data)
            return setParamOptions(mergeSpecailParams(data, types))
        })
    }
}

const setParamOptions = (params: any) => {
    const paramOptions: any[] = [];
    _.forIn(params, (value, key) => {
        paramOptions.push({value: key, text: value})
    })
    return paramOptions;

}

const mergeSpecailParams = (parameters: any, types: string[]) => {
    let targetParam = {};
    _.forIn(parameters, (value, key) => {
        if (types.includes(key)) {
            targetParam = { ...targetParam, ...value }
        }
    })
    return targetParam
}

原文地址:https://www.cnblogs.com/Nyan-Workflow-FC/p/11274511.html

时间: 2024-08-02 19:25:03

react: typescript system params method optimize的相关文章

System and method to prioritize large memory page allocation in virtualized systems

The prioritization of large memory page mapping is a function of the access bits in the L1 page table. In a first phase of operation, the number of set access bits in each of the L1 page tables is counted periodically and a current count value is cal

Apparatus, system, and method for automatically minimizing real-time task latency and maximizing non-real time task throughput

An apparatus, system, and method are provided for automatically minimizing Real-Time (RT) task latency and maximizing Non-Real Time (NRT) task throughput. The apparatus may include a task manager, a determination module, and optionally a tracking mod

System and method for assigning a message

A processor of a plurality of processors includes a processor core and a message?manager. The message?manager?is in communication with the processor core. The message?manager?to receive a message from a second processor of the plurality of processors

System and method for dynamically adjusting to CPU performance changes

FIELD OF THE INVENTION The present invention is related to computing systems, and more particularly to a system and method for adjusting to changes in processor performance. BACKGROUND INFORMATION Designers of mobile computing platforms are faced wit

LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method

System.Data.Objects.EntityFunctions和System.Data.Objects.SqlClient.SqlFunctions中的方法进行比较,如下 where System.Data.Objects.SqlClient.SqlFunctions.DateDiff("s",DateTime.Now,u.Time)>0 where System.Data.Objects.EntityFunctions.DiffSeconds(DateTime.Now,

Jexus System.MissingMethodException: Method 'System.Web.Hosting.HostingEnvironment.set_IsHosted' not found 报错的解决

看到大家都尝试Jexus以及dotnetcore,再加上新租了腾讯云的centos linux云服务器,决定要把公司比较简单的提供升级下载的网站部署到linux下试一下. 按照ASP.NET跨平台实践:无需安装Mono的Jexus“独立版” 的方法安装好Jexus . 部署网站,访问网站时下出现错误System.MissingMethodException: Method 'System.Web.Hosting.HostingEnvironment.set_IsHosted' not found

PatentTips - System and method to deprivilege components of a virtual machine monitor

BACKGROUND INFORMATION An embodiment of the present invention relates generally to virtualization platforms and, more specifically, to a system and method to run components of a virtual machine monitor at a reduced privilege level. Various mechanisms

System and method for critical address space protection in a hypervisor environment

A system and method in one embodiment includes modules for detecting an access attempt to a critical?address?space?(CAS) of a guest operating system (OS) that has implemented?address?space?layout?randomization?in a hypervisor environment, identifying

@RequestMapping的params参数 @RequestMapping(params = "method=save")

@RequestMapping的params参数还是挺好用的. 我的需求是这样的,现在有两个列表页面,一个是全部用户的列表页面,一个是某一个用户的列表页面,但是他们的jsp页面是一样的,url路径我也想一样的,单一用户的列表页面我想通过传入用户名来区别. 但是springmvc不能多个方法匹配一个url. @RequestMapping的params参数就很好的就解决了这个问题. 同一个url,只要params不同,sringmvc是会区分匹配的. 示例我的项目中的一段代码: Java代码