Elm - Turn Msg into Cmd Msg

ぃ、小莉子 提交于 2019-12-05 00:17:48

There is really no need to turn Msg into a Cmd Msg. Remember that update is just a function, so you can call it recursively.

Your NewTopic case handler can be simplified to this:

NewTopic newTopic ->
    update MorePlease { model | topic = newTopic}

If you really truly wanted the Elm Architecture to fire off a Cmd for this scenario, you could do a simple map of Cmd.none to your desired Msg:

NewTopic newTopic ->
    ({ model | topic = newTopic}, Cmd.map (always MorePlease) Cmd.none)

(not actually recommended)

Add the following function:

run : msg -> Cmd msg
run m =
    Task.perform (always m) (Task.succeed ())

Your code would then turn into:

NewTopic newTopic ->
      ({ model | topic = newTopic}, run MorePlease)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!