Interesting stuff.
Ricardo Araújo

update : Msg -> Model -> Model
update msg model =
{ model |
user = updateUser msg model.user
, posts = updatePosts msg model.posts

I was thinking about this for a while, but it has a serious problem: compiler will no longer warn you when you miss the msg case, because both update functions are ended with _ -> model

I was thinking about something else: splitting the main Msg into UserMsg … and PostsMsg … and main update looks now like this:

update : Msg -> Model -> Model
update msg model =
case msg of
UserMsg a -> { model
| user = updateUser a model
PostMsg a -> { model
| posts = updatePosts msg model

The trick is the sub-update functions receive a top-level Model and they must return a top-level Msg. This let you access, e.g. user data when updating posts and also let’s you return a Cmd Msg, so you can invoke actions like change a route (which would be covered withing other update).

I have not try it yet, will try investigate it soon.

Show your support

Clapping shows how much you appreciated Witold Szczerba’s story.