choonkeat / html-data / HtmlData.Lazy

Almost compatible with Html.Lazy

Ideally we can do

HtmlData.Lazy.lazy viewPrime 200000

But https://juliu.is/performant-elm-html-lazy/

Html.Lazy needs to associate the cached value with a precise function, but specifying an anonymous function forces the runtime to recreate that function every time the view is invoked.

So to use HtmlData.Lazy, we have to declare a composed version of the function that returns `Html.Html msg`, outside of the view function

viewPrime_elmhtml =
    viewPrime >> HtmlData.Extra.toElmHtml

Then pass it in as 2nd argument

HtmlData.Lazy.lazy viewPrime viewPrime_elmhtml 200000

The result is that our function signature here isn't 100% identical to Html.Lazy, but it does work in the correctly.

See the prime numbers section on https://html-data.netlify.app

lazy : (a -> HtmlData.Html msg) -> (a -> Html msg) -> a -> HtmlData.Html msg

lazy2 : (a -> b -> HtmlData.Html msg) -> (a -> b -> Html msg) -> a -> b -> HtmlData.Html msg

lazy3 : (a -> b -> c -> HtmlData.Html msg) -> (a -> b -> c -> Html msg) -> a -> b -> c -> HtmlData.Html msg

lazy4 : (a -> b -> c -> d -> HtmlData.Html msg) -> (a -> b -> c -> d -> Html msg) -> a -> b -> c -> d -> HtmlData.Html msg

lazy5 : (a -> b -> c -> d -> e -> HtmlData.Html msg) -> (a -> b -> c -> d -> e -> Html msg) -> a -> b -> c -> d -> e -> HtmlData.Html msg

lazy6 : (a -> b -> c -> d -> e -> f -> HtmlData.Html msg) -> (a -> b -> c -> d -> e -> f -> Html msg) -> a -> b -> c -> d -> e -> f -> HtmlData.Html msg

lazy7 : (a -> b -> c -> d -> e -> f -> g -> HtmlData.Html msg) -> (a -> b -> c -> d -> e -> f -> g -> Html msg) -> a -> b -> c -> d -> e -> f -> g -> HtmlData.Html msg

lazy8 : (a -> b -> c -> d -> e -> f -> g -> h -> HtmlData.Html msg) -> (a -> b -> c -> d -> e -> f -> g -> h -> Html msg) -> a -> b -> c -> d -> e -> f -> g -> h -> HtmlData.Html msg