小编Stu*_*iek的帖子

Elm with webcomponents - 这是一个错误还是我做错了什么?

问题总结 我在 elm 0.19.1 中使用 webcomponents。目标是让 webcomponent 在 webcomponent 属性“requeststate”发生变化时发出一个事件。事件被发出(我可以在 webcomponent 构造函数的日志中看到),但 elm 没有正确触发“WebcomponentEvent”。问题出在 windows 10 和 ubuntu 16.04、firefox 和 chrome 上。没有测试旧的 elm 版本。

重现步骤:

  • 我在这个最小的 repo 中重现了这个问题:https : //github.com/Derryrover/elm_webcom_bug
  • 编译 elm: elm make src/Main.elm --output elm.js --debug
  • 使用网络服务器(例如“服务”)在本地托管
  • 单击“请求”按钮。这将更改 webcomponent 上的属性“requeststate”。这反过来会触发 webcomponent 上的自定义事件“created”。但是榆树没有收到这个事件..

打开 elm-debugger 或再次单击“请求”按钮将神奇地在 elm 中触发事件。奇怪的。我也做了分支'tom-experiment'。在这个分支中,我从 webcomponent-click 工作中获得了事件,但前提是我直接点击了 webcomponent 本身。

这个问题的重要性 为什么我要通过改变一个属性来触发一个webcomponent上的事件?这种方法的目标也是 JavaScript 互操作。例如,我现在可以使用这个 webcomponent 来创建日期时间或 uuid 或做一些其他的 javascript 魔术。这样我就可以完全解决端口问题。这个问题的解决方案可能会解决整个 Javascript 互操作讨论!

代码

这是我的 Main.elm:

module Main exposing (..)

import Browser
import Html
import Html.Attributes
import …
Run Code Online (Sandbox Code Playgroud)

web-component elm

3
推荐指数
1
解决办法
116
查看次数

标签 统计

elm ×1

web-component ×1