Reputation:
I am building my first Elm application, and i'm structuring it according to theese sources:
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 Task
or 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
Reputation:
Using Http.send (MsgForMuseums << FetchedMuseums)
as suggested by Dogbert did solve the issue
Upvotes: 1