If c1 and c2 need to have an effect outside of themselves, send that effect
as data out of update.
The parent can act on that data coming from the children and do the right
thing.

If you need information from the share model in c1 and c2, send it as props
when you call the view.

so... the signatures of the Child component should look like this:

type DataForParent = DoSomeStuff | DoSomeOtherStuff |DoNothing

update : Msg -> Model -> (Model, DataForParent)

and

view : Props -> Model -> Html Msg


of course, if you need to send Cmd upstream, the update wood look like:

update : Msg -> Model -> (Model, Cmd Msg, DataForParent)





On Sat, Jun 4, 2016 at 9:58 PM, surfncode <[email protected]> wrote:

> Hello,
>
> How do you typically architecture child components that have a shared
> model  owned by a higher component in the hierarchy ?
>
> Let say I have component P with a model resembling this
>
> type alias Model = {...,list: List SharedModel}
>
> SharedModel is actually defined in a separated module.
>
> P has two child components c1 and c2 displayed at the same time. Those
> components needs to access to the selected SharedModel in list.
>
> Both the model of c1 and c2 will therefore contain a copy of the selected
> SharedModel
>
> Most of the updates c1 and c2 need to perform on SharedModel are common. I
> was thinking of putting them in the form of utility function in the
> SharedModel module and call them from the parent component P
>
> This somewhat resembles the flux architecture where a central store is
> updated by the react components sharing common actions which then update
> the component views in cascade from the top.
>
> Is that the correct way to do it ?
>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to