zoukankan      html  css  js  c++  java
  • 利用 高阶函数 | 作用域 | 配置初始化脚本的 全局变量

    利用 高阶函数 | 作用域 | 配置初始化脚本的 全局变量

    import context from '@utils/context';
    
    
    const configFileUrl = `http://sgs.com/api`;
    
    const timtOut = proObj => {
      return Promise.race([
        proObj,
        new Promise(resolve => {
          setTimeout(() => {
            resolve({ code: 1001, errMsg: '接口请求超时,时限3秒' });
          }, 3000);
        })
      ]);
    };
    const fetchApiPro = requestPromise({ url: configFileUrl });
    const h_fetchConfigFile = () => {
      let apiData = null;
      fetchApiPro.then(res => (apiData = res));
      return () => apiData;
    };
    
    const output = {
      init() {
        this._getConfigFile = h_fetchConfigFile();
      },
      getPreSaleConfig: async function () {
        const { preSaleListConfig } = this;
        if (preSaleListConfig) {
          return preSaleListConfig;
        }
        let res;
        try {
          res = await timtOut(fetchApiPro);
        } catch (e) {
          res = { code: 1001, errMsg: e };
        }
        return res;
      },
      get preSaleListConfig() {
        return output._getConfigFile();
      }
    };
    export default output;
  • 相关阅读:
    task-clph
    遍历数组的方式
    iOS事件处理之七种手势
    quatz2d使用注意点
    iOS 细碎知识整理
    九宫格算法图示
    mac10.12的Cocopods安装使用
    静态库冲突的解决办法:duplicate symbol
    ceshi
    xmpp4-总览
  • 原文地址:https://www.cnblogs.com/tommymarc/p/12914938.html
Copyright © 2011-2022 走看看