> > A) > Indeed, Lazy just checks for referential equality (is it the same > javascript object) and not "elm equality". This is kind of important to > know! > model !== { model | state = model.state} >
Thanks for this info! It motivated me to give lazy another try (I couldn't make it work for some of my use cases before). Some thoughts: - *Referential Equality* as mentioned in the documentation [1] might be misleading as the actual implementation also treats simple types (Int, Float, String) as equal. This confused me because sometimes lazy worked and sometimes not. Now I understand that it works for basic types and for fields in your model that were not changed at all (referential equality). But it does *not* work for values which are calculated in your view function and are not basic types. It took me quite some time to get that. *Should the documentation be updated?* - *Did it work different in older versions of elm? *Quite early when I was trying to get lazy to work I read a comment on reddit [2] that you can use tuples if you need lazy for more than 3 arguments and came to the conclusion that I can use tuples in general. At least in elm 0.18 this doesn't seem to work anymore, but I am not sure if I did it correctly because in this post, even *rtfeldman* confirmed that tupling up the arguments would work (see [2]) ;-). Note that this post is more than one year old, therefore I wonder if the implementation changed since then? - *Should lazy use normal equality? *I have no idea if this could even be implemented on the level of the Html.Lazy package, but for my use case this would simplify using lazy a lot. I am using *lazy* to optimize rendering svg during animations by using transformations (<g transform="...">) on a parent group element and only changing the child elements if really needed. In my case, the data structure that drives the rendering of the child elements is not directly part of the model but is derived from it. The workaround I am currently using is to add that data structure to the model (to get referential equality and make lazy work), but this has the disadvantage that I now I have *two sources of truth* in my model - the data (used for other parts of the application) and the data structure derived from it. Keeping these two in sync makes the code more complex and less readable. Also I now have to do the calculations in the update code, even though I think it would belong to the view code. - *Example Code *I tried to come up with a simple example of my actual use case [3]. It renders a child element which data is derived from the model (by rounding it) and tries to render it lazily. This doesn't work because the argument of the drawPoint function is a tuple and is not part of the model and therefore never referentially equal (check the console to see that the drawPoint function is called everytime). "Fixing" the example is simple in this case by replacing the tuple with two arguments (see commented code), but in more complex scenarios this is not possible and one have to add the derived data to the model. [1] http://package.elm-lang.org/packages/elm-lang/html/2.0.0/Html-Lazy#lazy [2] https://www.reddit.com/r/elm/comments/3hhlsp/htmllazy_for_any_number_of_arguments/cu7fn9d/ [3] https://gist.github.com/ibirrer/4131b725dccdfba4c44ac62b3b220410 -- 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.