The Mantl UI combines several different kinds of data across a large 
platform-as-a-service-like system. At the top level, I'm handling messages 
for the model/view/update triples and handling routing. This may not be the 
*best 
*architecture, but it's what I came up with as a beginner and I can't think 
of ways to improve it substantially (not that I would anyway… it compiles 
and runs fine and the contract is over.)

The painful bit is 
at 
https://github.com/CiscoCloud/mantl-ui-frontend/blob/master/app/Mantl.elm#L61-L90.
 
To get everything in one place, here's the code:

update : Msg -> Model -> ( Model, Cmd Msg )
update action model =
    case action of
        Refresh ->
            model
                ! [ Cmd.map VersionMsg Version.loadVersion
                  , Cmd.map HealthMsg Health.loadHealth
                  , Cmd.map ServicesMsg Services.loadServices
                  ]

        ServicesMsg sub ->
            let
                ( services, cmd ) =
                    Services.update sub model.services
            in
                { model | services = services } ! [ Cmd.map ServicesMsg cmd 
]

        VersionMsg sub ->
            let
                ( version, cmd ) =
                    Version.update sub model.version
            in
                { model | version = version } ! [ Cmd.map VersionMsg cmd ]

        HealthMsg sub ->
            let
                ( health, cmd ) =
                    Health.update sub model.health
            in
                { model | health = health } ! [ Cmd.map HealthMsg cmd ]

I had tried to make this more generic, and was mostly able to, but couldn't 
because I couldn't figure out record update syntax (spoiler alert: I was a 
newbie and there wasn't one but I even went and looked at the compiler 
source to figure it out.) Of course now I would just make a setter 
function, but the more you know 🌈

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to