There is a pattern where the parent creates a context for the child and the
child uses the context to lift its language to the language of the parent.

It looks like this:

type alias Context pMsg=
    { toParent : Msg -> pMsg
    , someCmd : Cmd pMsg
    , someOtherCmd : Cmd pMsg
    }

update : Context pMsg -> Msg -> Model -> (Model, Cmd pMsg)
update ctx msg model =
    case msg of
        LocalStuff ->
            model ! [Cmd.map ctx.toParent localCmd]

        SomeCmd ->
            model ![ctx.someCmd]

        SomeOtherCmd ->
            model ![ctx.someOtherCmd]
        ....

In the parent, it's just a matter of using `update` and just passing along
the cmd it produces.

Alternatively you can have just plain pMsg in the context and use succeed
to upgrade them to `Cmd pMsg`:


succeed msg =
    Task.perform identity identity (Task.succeed msg)

type alias Context pMsg=
    { toParent : Msg -> pMsg
    , someMsg : pMsg
    , someOtherMsg : pMsg
    }

update : Context pMsg -> Msg -> Model -> (Model, Cmd pMsg)
update ctx msg model =
    case msg of
        LocalStuff ->
            model ! [Cmd.map ctx.toParent localCmd]

        SomeMsg ->
            model ![succeed ctx.someCmd]

        SomeOtherMsg ->
            model ![succeed ctx.someOtherCmd]
        ....




On Tue, Jul 19, 2016 at 11:21 PM, Nils Eriksson <[email protected]
> wrote:

> Hi i have a top level websocket controller that is supposed to take care
> of all websocket stuff and children make use of it with the help of
> *OutMsg*.
> This is my current solution but i feel like i can not abstract in a good
> way. What i really want would be for the children to be able to say where
> the reply should go
> But i run into a issue where the children has different *Msg* types and
> therefore i have made this kind of ugly hack with a intermediary *Union
> type* that all children can use.
>
> https://gist.github.com/note89/d09dd227a151cac0ef6883fac411276a
>
> Would be great to learn some new concept on how to do this in a better
> way.
> I now want different *Notification types *and its going to get ugly fast.
>
> Tnx !
>
> --
> 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