不在远程调试模式下时,React Native 中未定义 ES6 代理?

2023-12-28

我用代理包装导入的 SDK 类,以便最终可以捕获 RequestException,即当没有网络连接来显示错误弹出窗口时。

该应用程序在远程调试模式下运行没有问题,但是,当我禁用它时,出现错误Can't find Variable: Proxy被抛出。我需要以某种方式明确导入它吗?或者是否有另一种方法来包装类,以便我可以捕获它的所有异常?

下面是代理包装器的代码。



import Backend from 'backend-sdk';

import RequestException from 'backend-sdk/src/exceptions/RequestException';

let handler = {
  get: (target, name, receiver) => {
    try {
      return Reflect.get(target, name, receiver);
    } catch (e) {
      if (e instanceof RequestException) {
        console.error(e);
        //TODO Add a toast notification for failed API requests
      } else {
        throw e;
      }
    }
  }
};

export default new Proxy(new Backend(), handler);
  

默认情况下,React Native 中的代理不会被 Polyfill。它可以在 chrome 调试器中工作,因为 React Native 在调试过程中使用 chrome js 引擎,请参阅js环境文档 https://facebook.github.io/react-native/docs/javascript-environment.html。您可以尝试使用代理polyfill https://github.com/GoogleChrome/proxy-polyfill.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

不在远程调试模式下时,React Native 中未定义 ES6 代理? 的相关文章

随机推荐