Reputation: 1150
I am trying to separate files in an Elm project, as keeping everything in global Model, Messages, etc. would be just a mess. Here is how I tried it so far:
So, there are some global files, and then Header has its own files. However I keep getting error, when importing Header.View
into my global View:
The 1st and 2nd entries in this list are different types of values.
Which kind of makes sense:
The 1st entry has this type:
Html Header.Messages.Msg
But the 2nd is:
Html Msg
So, my question is whether all the messages (from all my modules, like Header) needs to be combined somehow in global Messages.elm
? Or there is a better way of doing this?
Upvotes: 2
Views: 212
Reputation: 21005
My advice would be to keep messages and update in 1 file until that feels uncomfortable (for you to decide how many lines of code that means - see Evan's Elm Europe talk for more on the modules flow). When you want to break something out, define a new message in Main
type Msg
= HeaderMsg Header.Msg
| ....
Then use Cmd.map HeaderMsg
in your update function and Html.map HeaderMsg
in your view function to connect up your sub-components
Upvotes: 2