2017-09-28 119 views
0

我想做一些非常不起作用的東西,並在elm中做一個HTTP請求而不處理任何類型的響應。基本上是這樣的:HTTP請求沒有請求在Elm 0.18

testView : Html Msg 
testView = 
    div [] [ 
    button [onClick TestAction] [text "Test Action"] 
    ] 

update : Msg -> Model -> (Model, Cmd Msg) 
update msg model = 
    case msg of 
     ... 
     TestAction -> 
      (model, testActionCmd) 
     ... 

import Http 
import HttpBuilder exposing (..) 
... 
testActionCmd : Cmd Msg 
testActionCmd = 
    ("http://localhost:4000/fakeurl") 
    |> get -- this is a side effect; unrelated to the Msg below 
    Cmd.none -- this is what I want to return 

有沒有辦法做這樣的事情在榆樹?

回答

5

總之,不,你不能這樣做(不是沒有編寫你自己的效果管理器或使用端口)。

「問題」是Http模塊允許您創建Task,然後您需要將其轉換爲Cmd來執行該任務。但要從TaskCmd,您需要提供Msg。見http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Task

所以你需要做的是創建一個Noop消息。