elm-architecture

Sequence Http.get in Elm

我的梦境 提交于 2019-12-14 03:46:23
问题 Below I have a button that attempts to load remote content ... import Post exposing (Post) import Html exposing (..) import Html.Events exposing (..) import Http import Json.Decode as Decode type alias Model = { posts : List Post } type Msg = Search String | PostsReceived (Result Http.Error (List Post)) update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of Search s -> let cmd = (Decode.list Post.decode) |> Http.get ("/posts?author=" ++ s) |> Http.send PostsReceived in (

Elm - Turn Msg into Cmd Msg

ぃ、小莉子 提交于 2019-12-05 00:17:48
I'm trying to modify a simple app from the elm-lang tutorial to first update the model, then trigger another update. 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) This fails in the compiler because the NewTopic branch: The 3rd branch has this type: ( { gifUrl : String, topic : String }, Cmd Msg ) But the 4th is: ( { gifUrl : String, topic : String }, Msg ) So my Msg needs to be type Cmd