I need constantly updated device sizes across various children (pages).
The approach I found working is to handle updates of the device size with one Msg in the update
of the parent (main) and modify the children model directly from there:
SetScreenSize newSize ->
let
mailingModel =
model.mailingModel
updatedModel =
{ mailingModel
| deviceSize = Element.classifyDevice newSize
}
in
( { model | mailingModel = updatedModel }, Cmd.none )
I see the downside that the update function of the children is no longer is the only function updating the childrens model and that mapping one parent message per child is no longer enough to make them work together.
Also I heard Evan say that there is no shortcut to updating a nested value because it usually hints to a bad design decision.
An alternative would be to add a updateDeviceSize
msg to every single child and wire it up in the parent. That would be significantly more code and would also require the the knowledge that mapping one parent message to each child is not enough.
What do you think of this approach?
Are there other alternatives?