choonkeat/html-data/4.0.0

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.

  • when generating String, e.g. through toTextHtml, there is no lazy effect; the first argument function is run each time
  • when generating Html.Html msg, i.e. through toElmHtml, we hand off the 2nd argument to Html.Lazy

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

lazy : (a -> Html msg) -> (a -> Html msg) -> a -> Html msg
lazy2 : (a -> b -> Html msg) -> (a -> b -> Html msg) -> a -> b -> Html msg
lazy3 : (a -> b -> c -> Html msg) -> (a -> b -> c -> Html msg) -> a -> b -> c -> Html msg
(a -> b -> c -> d -> Html msg)
-> (a -> b -> c -> d -> Html msg)
-> a
-> b
-> c
-> d
-> Html msg
(a -> b -> c -> d -> e -> Html msg)
-> (a -> b -> c -> d -> e -> Html msg)
-> a
-> b
-> c
-> d
-> e
-> Html msg
(a -> b -> c -> d -> e -> f -> Html msg)
-> (a -> b -> c -> d -> e -> f -> Html msg)
-> a
-> b
-> c
-> d
-> e
-> f
-> Html msg
(a -> b -> c -> d -> e -> f -> g -> Html msg)
-> (a -> b -> c -> d -> e -> f -> g -> Html msg)
-> a
-> b
-> c
-> d
-> e
-> f
-> g
-> Html msg
(a -> b -> c -> d -> e -> f -> g -> h -> Html msg)
-> (a -> b -> c -> d -> e -> f -> g -> h -> Html msg)
-> a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> Html msg