user6719137
user6719137

Reputation:

Mapping Msg using NoMap in Elm with http request on init

I am building my first Elm application, and i'm structuring it according to theese sources:

How i structure elm apps

NoMap approach with Domain focus

Which means i map my Msg types from my main Types.elm to my child functions. Which looks like this when doing a simple onClick function

onClick (MsgForPieChart <| SelectSlice <| sliceModel.points)

Now i want to fetch some data on init for a view.

I tried following the same approach as for a simple onClick function

getWarAndPeace : Cmd Msg
getWarAndPeace =
    Http.send (MsgForMuseums <| FetchedMuseums) <|
        Http.getString "https://example.com/books/war-and-peace.md"

Where my main type look like this:

type Msg
= MsgForPieChart Atom.PieChart.Types.Msg
| MsgForMuseums Organism.Museums.Types.Msg 
| NoOp

And my child function type looks like this for http requests

type Msg = 
FetchedMuseums (Result Http.Error String)

But no matter what i try i keep getting type errors like this from Http.send or Taskor whatever approach i try

Result Http.Error a -> App.Types.Msg

But it is:

App.Types.Msg

My update functions is structured like:

update : App.Types.Msg -> Organism.Museums.Types.MuseumsModel -> Organism.Museums.Types.MuseumsModel
update msgFor model =
case msgFor of
    MsgForMuseums msg ->
        updateMuseums msg model
    _ ->
        model


updateMuseums : Organism.Museums.Types.Msg -> Organism.Museums.Types.MuseumsModel -> Organism.Museums.Types.MuseumsModel
updateMuseums msg model =
    case msg of
        FetchedMuseums data -> model

So how do i fetch http requests on init for my child function, which is using the NoMap pattern to combine Msg

Upvotes: 0

Views: 129

Answers (1)

user6719137
user6719137

Reputation:

Using Http.send (MsgForMuseums << FetchedMuseums) as suggested by Dogbert did solve the issue

Upvotes: 1

Related Questions