Ilya
Ilya

Reputation: 1150

Elm project scaling: separating Messages/Updates

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:

enter image description here

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:

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

Answers (1)

Simon H
Simon H

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

Related Questions