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

On Wednesday, 10 August 2016 01:21:40 UTC+10, Rupert Smith wrote:
>
> On Thursday, August 4, 2016 at 11:30:00 PM UTC+1, Rupert Smith wrote:
>>
>> The next step I think will be to take the navigation bar, and the clock 
>> widget and organize the code in such a way that the widget is a re-usable 
>> component that I can embed in the navigation bar.
>>
>
> Up till now I have mostly messed around with the view - so I can use a 
> functional language to render a view. This is very nice and a lot more 
> powerful than say Handlebars templates. I started using StringTemplate in 
> Java because it claimed to be a functional language that did templating. In 
> fact, it never really lived up to its claim to be a functional language. 
> Elm views do feel like a functional templating language - it is easy to 
> combine the functions that produce output with whatever complex functions 
> you need to structure or calculate the content of the output.
>
> I have followed this guide to structuring the code:
>
>
> http://blog.jenkster.com/2016/04/how-i-structure-elm-apps.html#comment-2634825704
>
> Moderately helpful - at least it made the files smaller, I know which file 
> to open to adjust the model, update function or view and there is not too 
> much text in each. It feels more manageable that way.
>
> But this is definitely getting harder... 
>
> I have embedded the clock as a component within another, which is the main 
> body part of the page. What I am struggling a bit with, is how do I attach 
> the 'subscription' that transforms Time into a Tick that then drives the 
> clock 'update' function back to the top-level subscription needed to build 
> the whole application?
>
> I need a Tick Msg at the top-level to do this? This feels a bit strange, 
> surely there is some way I can attach the clock to the timer without 
> needing to be aware of that from outside of that particular component? That 
> is, just add the clock to my view and let it tick away all by itself...
>

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to