【问题标题】:JS Interop works with DDC but not with Dart2JSJS 互操作适用于 DDC,但不适用于 Dart2JS
【发布时间】:2020-05-21 21:38:27
【问题描述】:

飞镖 2.7 build_runner:1.7.3 build_web_compilers: 2.9.0

我使用包 js 为 GoJS 创建了一个接口:https://github.com/jodinathan/gojs_dart/ 问题是它在 DDC 中完美运行,但在与 Dart2JS 一起使用时会引发异常。

这是一个您可以检查的小型复制品: https://github.com/jodinathan/gojs_dart/tree/master/example/flowchart

错误似乎在 ..bind(GoJSBinding('text').makeTwoWay()) 行中 我认为它找不到 bind() 函数,但是,在 DDC 中它可以。

关于如何解决这个问题的任何想法?

问题出在 dart-sdk 中:https://github.com/dart-lang/sdk/issues/40434

【问题讨论】:

    标签: dart dart2js


    【解决方案1】:

    看起来 dart2js 在所有类上都需要一个外部工厂构造函数,而 dartdevc 不需要。例如,对于今天遇到的第一个错误,你有一个这样的类:

    @JS('Node')
    class GoJSNode extends GoJSPart {}
    

    它应该是这样的:

    @JS('Node')
    class GoJSNode extends GoJSPart {
      external factory GoJSNode();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 2019-06-15
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多