【发布时间】:2017-07-30 21:51:18
【问题描述】:
我正在尝试从elm-lang tutorial 修改一个简单的应用程序,以首先更新模型,然后触发另一个更新。
update msg model =
case msg of
MorePlease ->
(model, getRandomGif model.topic)
NewGif (Ok newUrl) ->
( { model | gifUrl = newUrl }, Cmd.none)
NewGif (Err _) ->
(model, Cmd.none)
-- my addition
NewTopic newTopic ->
({ model | topic = newTopic}, MorePlease)
这在编译器中失败,因为 NewTopic 分支:
The 3rd branch has this type:
( { gifUrl : String, topic : String }, Cmd Msg )
But the 4th is:
( { gifUrl : String, topic : String }, Msg )
所以我的 Msg 需要输入 Cmd Msg。我怎样才能把我的 Msg 变成一个 Cmd Msg?
注意:我知道有一种更简单的方法可以进行此更改,但我试图从根本上理解 Elm
【问题讨论】:
标签: elm elm-architecture