I have been looking for ways to use Html.lazy with more than 3 arguments and came across a reddit thread where it was suggested to use a tuple to pass in those arguments. I added this to make my app and found out that it was actually rerendering the function. Here is a link to Ellie: https://ellie-app.com/5yTCWmCp5a1/2
I know this has been fixed in the 3.0.0-beta version of elm-html but does anybody know a way of doing this now?
We tried to use the tuple technique as well, and only later did we find out that it was ineffectual. I think the only way to do this is to restructure your model to use nested record or some other type that will group together fields that may be passed in to view functions. Not a great solution, given that your model structure and your view functions should not be coupled together.
The challenge is that Html.Lazy uses referential equality and hence fails entirely if you construct any of its parameters during the view call because those constructed parameters will not be referentially equal to parameters you constructed the last time.
We’ve got native code that does referentially transparent and functionally pure deduping which helps, but it’s native code and sharing that is discouraged here. It also comes with the tricky part that you need to have a separate deduper for each path you care about for it to be effective. I generally stick it in the model.
Without resorting to native code, what you can do if some of your parameters come from a small space of values —e.g., you need a Boolean parameter — is build module-level functions that prebind those values and then choose amongst those functions in the render. This way, you get the number of arguments that you need to pass to Html.Lazy down.