简体   繁体   English

为什么React Native运算符在调试和发布版本上表现不同

[英]Why React Native operators behave differently on debug and release builds

Does anyone know why operators behave differently on react native (0.54.2) debug and release builds? 有谁知道为什么操作员在响应本机(0.54.2)调试和发布版本时表现不同?

This works perfectly on debug. 这在调试时效果很好。 If usageTip is something else than empty string and we are loading first time, we enter inside if and show user the usageTip: 如果usageTip不是空字符串,并且是第一次加载,则在if中输入并向用户显示usageTip:

if (this.props.usageTip =! '' && this.props.firstTimeLoading) {
    return (
        <Text style={styles.disclaimerTextStyle}>{this.props.usageTip}</Text>
    );
}

But on release the if line will somehow set imageTip to boolean value true. 但是在发布时,if行将以某种方式将imageTip设置为布尔值true。 What is happening there? 那里发生了什么事?

I found a way to get it working on release also: 我还找到了一种使其在发行版上也能正常工作的方法:

if (this.props.firstTimeLoading && (this.props.usageTip ==! '')) {
        return (
            <Text style={styles.disclaimerTextStyle}>{this.props.usageTip}</Text>
        );
    }

But I am very confused why the first version of my code behaved like that? 但是我很困惑,为什么我的代码的第一个版本表现得如此? It was also very hard to find the problem because release build debugging is not very easy. 也很难找到问题,因为发布版本调试不是很容易。 (At least I don't know any easy way) (至少我不知道任何简单的方法)

When using React Native, you're going to be running your JavaScript code in two environments: 使用React Native时,您将在两种环境中运行JavaScript代码:

  • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. 在大多数情况下,React Native将使用JavaScriptCore(为Safari提供支持的JavaScript引擎)。

  • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. 使用Chrome调试时,所有JavaScript代码都在Chrome本身内运行,并通过WebSockets与本机代码通信。 Chrome uses V8 as its JavaScript engine. Chrome使用V8作为其JavaScript引擎。

While both environments are very similar, you may end up hitting some inconsistencies. 虽然两种环境非常相似,但最终可能会遇到一些不一致之处。 To get More Detail 获得更多细节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM