有没有办法在Elm中定义没有参数的订阅端口?
就像是:
port updateTime : () -> Sub msg
使用此代码,我收到"端口'updateTime'具有无效类型"的错误
随着代码:
port updateTime : (String -> msg) -> Sub msg
它正在工作,但我不需要从javascript函数向Elm发送任何内容.
Cha*_*ert 12
你可以得到的最接近的可能是这样的:创建类似于你的例子的端口,但第一个参数为(() -> msg):
port updateTime : (() -> msg) -> Sub msg
假设你有一个UpdateTime Msg不接受任何参数,
type Msg
    = ...
    | UpdateTime
然后你可以updateTime像这样绑定订阅:
subscriptions : Model -> Sub Msg
subscriptions model =
    updateTime (always UpdateTime)
现在,在javascript方面,你必须null作为唯一的参数传递.
app.ports.updateTime.send(null);
| 归档时间: | 
 | 
| 查看次数: | 621 次 | 
| 最近记录: |