Hi! I’m not capable of understanding how to send a parametrized message to the update
function when I receive a service response.
I mean, having the next types and functions:
type Message =
ApiCall (Result Error ApiCallResult)
type ApiCallResult =
GetSections (List Section)
api : (Result Error ApiCallResult) -> Model -> (Model, Cmd Message)
api result model = case result of
Ok call -> case call of
GetSections _ -> (model, Cmd.none)
Err _ -> (model, Cmd.none)
update msg model = case msg of
ApiCall result -> api result model
I resolve the service calling like this:
sectionDecoder : D.Decoder Section
getSections : Cmd Message
getSections =
Http.get {
url = "http://127.0.0.1:8000/api/sections/",
expect = H.expectJson (ApiCall GetSections) (Decoder.list sectionDecoder)
}
However, it’s clear that the expect parameter for the Http.get
is wrong. The compiler gives the next error.
The 1st argument to `expectJson` is not what I expect:
45| expect = Http.expectJson (ApiCall GetSections) (Decoder.list sectionDecoder)
^^^^^^^^^^^^^^^^^^^^^^^
This `ApiCall` call produces:
T.Message
But `expectJson` needs the 1st argument to be:
Result H.Error a -> msg
-- TYPE MISMATCH --------------------------------------------------- src/Api.elm
The 1st argument to `ApiCall` is not what I expect:
45| expect = Http.expectJson (ApiCall GetSections) (Decoder.list sectionDecoder)
^^^^^^^^^^^^^
This `GetSections` value is a:
List Section -> ApiCallResult
But `ApiCall` needs the 1st argument to be:
Result Error ApiCallResult
Detected problems in 1 module.
Could you make me understand how to do it? Thanks!