【问题标题】:Clojurescript - invoking promises from native module correctlyClojurescript - 从本机模块正确调用承诺
【发布时间】:2019-06-16 16:42:44
【问题描述】:

我是 Clojurescript 的新手。我正在尝试在基于 java 的 react native 模块中调用一个函数。所有本机模块都在本机反应中返回承诺,我试图让 ClojureScript 位正确,但在编译期间我从 Node 收到一条消息 "UnhandledPromiseRejectionWarning: Unhandled Promise Rejection..." 。我猜 Node 认为从 Clojurescript 生成的 JS 没有 'reject' 子句。

我的代码如下所示:

(when platform/android?
     (try
       (->
         ((.-isAvailable RNTextDirection)) ;1st native module function
         (.then
           (fn [value]
             (when value
               (->
                 ((.-isRTL RNTextDirection) text)  ;2nd native module function
                 (.then (fn [value] ( (or value (right-to-left-text? text) (assoc :rtl? true))))
                 (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true))))))))
         (.catch (fn [error] ( (right-to-left-text? text) (assoc :rtl? true)))))
       (catch js/Object err ( (right-to-left-text? text) (assoc :rtl? true))))))

谁能帮我理解这里缺少什么?谢谢!

【问题讨论】:

  • 我在没有任何线索的情况下问这个问题:你确定((.-isAvailable RNTextDirection)) 周围的双括号吗?是你想要的 - 它将执行 .-isAvailable 的结果,这对我来说听起来很预言?

标签: node.js react-native react-native-android clojurescript


【解决方案1】:

我没有使用 CLJS 的 React Native,但您 (.catch ...) 这两个承诺链都可能失败,这意味着警告是虚假的。我会更怀疑 Node 如何执行未处理拒绝的检查,而不是 CLJS 编译器没有产生所有的函数调用。可能是 CLJS 运行时的间接层阻止了 Node 意识到潜在的拒绝已被处理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 2014-10-18
    • 1970-01-01
    • 2019-11-20
    • 2017-10-09
    • 2017-06-10
    相关资源
    最近更新 更多