Regarding the outmsg and translating types, you've got 2 options - you can 
either keep the outmsg in the scope of the module, or you can pass the 
outmsg to the update function from the upper level:

*Outmsg in scope of module*

module MyModule exposing(..)

type Msg
    = DoSomething 
    | DoSomethingElse 


type OutMsg
    = None
    | SomethingHappened String


update : Msg -> Model -> ( Model, OutMsg, Cmd Msg )
update msg  model =
    case msg of
        DoSomething ->
            ( model, None, Cmd.none )

        DoSomethingElse ->
            ( model, SomethingHappened "I ate a block of cheese" , Cmd.none 
)



*outmsg in the scope of parent via config*

module MyModule exposing(..)

type Msg
    = DoSomething 
    | DoSomethingElse 


type alias Config msg =
    { onSomethingHappened : String -> msg
    , onNoOp : msg
    }
    
update : Config msg -> Msg -> Model -> ( Model, msg , Cmd Msg )
update config msg  model =
    case msg of
        DoSomething ->
            ( model, config.onNoOp , Cmd.none )

        DoSomethingElse ->
            ( model, config.onSomethingHappened "I ate a block of cheese" , 
Cmd.none )


I'm using Nothing and NoOp in the respective examples - you might want to 
use "Maybe" instead, and return Nothing or Just xxx .

How do I trigger a Cmd on the top-level from the update function of a 
> module? Must be something to do with Cmd.map...?


Wherever you're managing the returned outmsg in the top level, generate the 
Cmd from there. 

On Tuesday, September 20, 2016 at 9:30:12 AM UTC-4, Rupert Smith wrote:
>
> On Sunday, September 18, 2016 at 9:33:14 PM UTC+1, Erik Lott wrote:
>>
>> I'm not sure what the outmessage package is that you linked to, but you 
>> don't need a package to manage this. An outmsg is just a messge that is 
>> returned from the update function, to notify the function caller of 
>> something important that happened internally. If you're new to elm, it's 
>> probably better to wire an OutMsg yourself, just so you know exactly what's 
>> going on with the code. If you haven't yet seen the Sortable Table 
>> Example <https://github.com/evancz/elm-sortable-table>, you should have 
>> a close look at the code. You'll see great examples of the update and view 
>> method returning useful messages.
>>
>
> Yes, I have struggled a bit to figure out how to do that, because I have 
> split the code into module, and the return type of the 'update' function in 
> a module is different to the return type of the 'update' function in the 
> top-level module. How does one translate between those types?
>
> I can see how it is done for a view, using Html.App.map.
>
> How do I trigger a Cmd on the top-level from the update function of a 
> module? Must be something to do with Cmd.map...?
>  
>

-- 
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