On Wednesday, August 10, 2016 at 12:05:39 AM UTC+1, Ian Mackenzie wrote:
>
> Have you looked at the modularity section 
> <http://guide.elm-lang.org/architecture/modularity/counter_pair.html> of 
> the Elm guide? It doesn't yet specifically cover nesting components that 
> have subscriptions, but points you to examples 3 and 4 here 
> <https://github.com/evancz/elm-architecture-tutorial/tree/master/nesting>. 
> You should end up with your main body module having something like
>
> type Msg
>     = MyTopLevelMessage Int
>     | SomeOtherTopLevelMessage String
>     | ClockMessage Clock.Msg
>
> so the main module has one message type that wraps all clock-related 
> messages in their own tag (oblivious to whether those clock-related 
> messages are time ticks or anything else). If your clock has subscriptions, 
> your main module might do something like
>
> subscriptions : Model -> Sub Msg
> subscriptions model =
>     Sub.map ClockMessage (Clock.subscriptions model.clock)
>
> to generate a top-level subscription (perhaps batching that with its own 
> subscriptions if necessary). If you can post some of your code we can take 
> a look...
>

Thanks, this is very useful. I could not find a nested example involving a 
subscription. So the ClockMsg is a 'constructor' for the Msg type, that 
basically wraps the Clock.Msg to turn it into the parent Msg type.

Then there is App.map for doing the same thing with Html views, and Cmd.map 
for the update function? 

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