javascript - Is it possible to add Javascript UI elements to a 100% elm application?
问题描述
I have an elm application that is working fine. It has a navigation bar that we built using standard elm UI functional code. Someone sees my app and says you should be using our standard javascript toolbar UI component. Is it possible to embed a Javascript UI component into a 100% native ELM app?
Note, we already are using ports to call some native JavaScript functions. I am wondering if the same concept can be used to embed UI components but since ELM has it's own internal rendering would this be problematic?
解决方案
我不清楚您所说的“Javascript UI 组件”是什么意思,因为它可以指代许多不同的东西,例如反应组件或角度组件。但是 Elm 确实通过自定义元素支持标准的Web 组件。
这是 Elm 方面的一个不完整示例,它是从开始 Elm借来的(并进行了一些编辑) :
googleMap : List (Attribute a) -> List (Html a) -> Html a
googleMap =
Html.node "google-map"
onGoogleMapDrag : Attribute Msg
onGoogleMapDrag =
coordinatesDecoder
|> Json.Decode.map UpdateCenter
|> on "google-map-drag"
view : Model -> Html Msg
view model =
googleMap
[ attribute "latitude" (toString model.center.latitude)
, attribute "longitude" (toString model.center.longitude)
, attribute "drag-events" "true"
, attribute "zoom" "5"
, onGoogleMapDrag
]
(List.map viewMarker model.markers)
推荐阅读
- spring-boot - 如何模拟导致非法参数异常的 JDBC 数据源对象说需要属性“数据源”?
- matrix - 变换场景坐标而不是相机坐标时的渲染损坏
- java - While 循环语句将除第一个输入之外的所有内容相加?
- mysql - AWS 设置所需的建议
- python - 在 Python 中使用键和值附加到字典中
- wordpress - 从正文中删除类名“页面”
- typescript - 你能在 React Navigation Tab Navigator 中以编程方式生成屏幕吗
- javascript - 为什么汇总无法解析 .d.ts 文件?
- list - 如何在颤振飞镖中使用相同元素初始化列表?
- image - ffmpeg提取无损png帧