So let me expand my scenario a little bit. Lets assume that the CounterList 
component is very feature heavy. It makes lots of work to layout its 
children, manages drag to sort or whatever fancy stuff you can imagine. Now 
in my app I have many instances of usage of CounterList and I want to apply 
the complex behaviour not only to counters but also to gif and to mixed 
counters with gifs and many many other possible configurations (think in 
hundreds). I don't really want to implement dedicated CounterList, GifList, 
2GifsWith3CountersList and other few hundreds SomethingBlaBlaList.
Is it possible in elm at all? If yes how so?

P.S. It is not imaginary question. I try to port existing application 
implemented in Re-Frame (ClojureScript framework) in which this scenario is 
trivial.

On Tuesday, 17 May 2016 13:33:27 UTC+1, Wil C wrote:
>
> Daniel,
>
> I think normally, you don't. I think the constraint here is that you need 
> to explicitly set the types of each of the sub-components for every 
> component that you make for a page. In the example that you give, you'd 
> actually need to create 4 types of components: TopLevel, Counter, 
> CounterList, and Gif. 
>
> TopLevel component would include CounterList and Gif. And then CounterList 
> would contain Counters. It is CounterList's job to dynamically keep track 
> of the number of Counters. That way, you don't need a generic component to 
> contain an unknown number of things with unknown types. And then if those 
> components need to talk to each other (Like once you add 5 or more 
> counters, you see a funny cat gif), I believe you can send messages through 
> Cmds (in 0.17) or Effects (in <0.17). 
>
> With the hierarchical thinking of laying out components, I found that 
> Thinking 
> in React <https://facebook.github.io/react/docs/thinking-in-react.html> 
> helps. 
>
> If you find that you really need the flexibility of having different 
> components in a container, it's doable. But it comes at a cost. Generally, 
> if you're making a web app of some sort, it's not needed. I cover entity 
> component systems recently in another thread, and it's for games.
>
> https://groups.google.com/forum/#!topic/elm-discuss/c9MhBzVPbr8
>
> Wil
>
> On Tuesday, May 17, 2016 at 5:13:56 AM UTC-7, Daniel Kwiecinski wrote:
>>
>> Hi Elmers,
>>
>>
>> Here is my scenario. Say I have Main.elm which defines main view form my 
>> application. I also have bunch of other components (with their 
>> corresponding model  and message types) say Counter and Gif. 
>> (
>> https://github.com/evancz/elm-architecture-tutorial/blob/master/nesting/Gif.elm
>> )
>> (
>> https://github.com/evancz/elm-architecture-tutorial/blob/master/nesting/Counter.elm
>> )
>> Now I'd like to create new generic component which as a parameter 
>> (initial value of its model?) takes list of any type of component (say two 
>> counters, then one gif and another three counters) and wraps them into some 
>> decorating html.
>> The scenario serves as a illustration of the question, how do I implement 
>> components which can wrap lists of arbitrary component types.
>>
>> --
>> Regards,
>> Daniel
>>
>

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