我想做一些非常无用的功能,并在elm中发出HTTP请求而不处理任何类型的响应.基本上是这样的:
testView : Html Msg
testView =
div [] [
button [onClick TestAction] [text "Test Action"]
]
Run Code Online (Sandbox Code Playgroud)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
...
TestAction ->
( model, testActionCmd )
...
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
有没有办法在榆树做这样的事情?
简而言之,不,你将无法做到这一点(不是没有编写自己的效果管理器或使用端口).
"问题"是Http模块允许您创建一个Task然后需要转换为Cmd执行任务的模块.但要从一个Task到一个Cmd你需要提供一个Msg.见http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Task
所以你需要做的是创建一个Noop消息.