I find first pattern (sending information upstream) a lot better, becuase it seems to be more versatile. It covers well also scenario where message does not come from view but from command or subscription.
Take for example List of Gif fetchers variation, where RandomGif should be removed from list by its parent if it fails to fetch a gif (in addition to clicking remove button). RandomGif would send the same or similar information upstream on FetchFail and Remove messages, and parent would react in same or similar way on that information. On Wednesday, May 25, 2016 at 12:36:46 PM UTC+2, Peter Damoc wrote: > > There are two basic patterns that I've seen: > > You keep the child oblivious to parent actions and just extend the update > signature to signify that it sends something upstream > > update : Msg -> Model -> (Model, Cmd Msg, Upstream) > > Here is an example of this: > > https://github.com/pdamoc/elm-architecture-tutorial/blob/master/examples/4/Counter.elm > > OR > > you use a Context for a specialized view that talks in the language of the > parent/ancestor > > type alias Context parentMsg = > { toParent : Msg -> parentMsg > , someActionName : parentMsg > ... > } > > viewWithContext : Context parentMsg -> Model -> Html parentMsg > > > e.g. Here is the Counter view: > > type alias Context parentMsg = > { toParent : Msg -> parentMsg > , remove : parentMsg > } > > view : Model -> Html Msg > view model = > div [] > [ button [ onClick Decrement ] [ text "-" ] > , div [ countStyle ] [ text (toString model) ] > , button [ onClick Increment ] [ text "+" ] > ] > > viewWithContext : Context parentMsg -> Model -> Html parentMsg > viewWithContext context model = > div [] > [ App.map context.toParent (view model) > , button [ onClick context.remove ] [ text "X" ] > ] > > and in the parent (CounterList) you do something like > > viewCounter (id, model) = > Counter.viewWithContext (Counter.Context (Modify id) (Remove id) ) > model > > > view model = > div [] (List.map viewCounter model.counters) > > > > > > On Tue, May 24, 2016 at 7:27 PM, TheGryzor123 <[email protected] > <javascript:>> wrote: > >> I created a child component that is supposed to display notifications >> coming from the parent. >> >> I know how to initialize and listen to a child but here I would like to >> tell him to execute actions for me. >> >> What do you suggest me to do? >> >> -- >> 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] <javascript:>. >> 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.
