Here are two examples were key is needed 
https://langrisa.eu/virtual-dom-pitfalls/ . I don't understand the new lazy 
proposal so i can't judge if it would work well in these cases. Why can't 
the compiler just infer where this is needed? Thinking about key is a HARD 
problem for your brain.

On Monday, February 29, 2016 at 7:38:56 PM UTC+1, Evan wrote:
>
> You use Html.Attribute.key 
> <http://package.elm-lang.org/packages/evancz/elm-html/4.0.2/Html-Attributes#key>
>  
> when you have a sequence of items where you may be inserting and removing 
> from the middle. I took this API pretty much directly from the virtual-dom 
> implementation that backs the currently released version of elm-html. I am 
> doing a rewrite for various reasons, and realized that the current API 
> clashes with the laziness optimizations.
>
>
> Problem
>
> If you have a big list, you’d likely want to make each entry lazy. It 
> would suck to have to build 1000 virtual nodes. If you want keys, you need 
> to add them as an attribute, but lazy takes no attributes! This means you 
> need to add an extra DOM node with a key where it has one child that’s lazy.
>
>
> Alternative
>
> I am considering getting rid of Html.Attribute.key entirely and replacing 
> it with this function:
>
> lazyDict
>   : String
>   -> List Attribute
>   -> (a -> Html)
>   -> Dict comparable a
>   -> Html
> lazyDict tagName attributes viewItem items = ...
>
> It is somewhat similar to the normal Html.node 
> <http://package.elm-lang.org/packages/evancz/elm-html/4.0.2/Html#node> 
> function in that it is just about creating virtual DOM nodes, but in this 
> case you give a Dict instead of a List. You might create a news feed like 
> this:
>
> viewNewsFeed : Dict Time Story -> Html
> viewNewsFeed stories =
>   lazyDict "div" [class "news-feed"] viewStory stories
>
> Each entry would also be done lazily, so you only need to create the Html 
> if the dictionary entries are not reference equal.
>
> This means it would be easy to treat the stories as a dictionary in your 
> model. When you want to add something, you add it with a timestamp. If it's 
> sorted by name, you have a (Dict String Person) or whatever.
>
>
> Question
>
> If you have personally used keys for a specific scenario, would this new 
> API cover things as well? Would it be better or worse? Can you elaborate on 
> the details of your case?
>
> *Note:* I am looking for *specific* experience. *If you don't have a 
> concrete example, you are off-topic.* Take it to another thread. If you 
> are reading this and the thread is long, feel free just to respond to my 
> initial question. The goal here is to gather data, not opinions.
>

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