A not-quite-drop-in replacement for the Html.Lazy module from the
elm-lang/html package.
The only difference between this and the lazy from elm-lang/html is that the
caller must call toUnstyled inside the function being passed to lazy.
For example:
import Html.Styled as Html exposing (Html)
import Html.Styled.Lazy exposing (lazy)
import VirtualDom
view : Model -> Html Msg
view model =
lazy viewCount model.count
viewCount : Int -> VirtualDom.Node msg
viewCount count =
span [ css [ textDecoration underline ] ] [ text (toString count) ]
|> toUnstyled -- toUnstyled must happen inside viewCount!Same as lazy but checks on two arguments.
Same as lazy but checks on three arguments.
A performance optimization that delays the building of virtual DOM nodes. Calling
(view model)will definitely build some virtual DOM, perhaps a lot of it. Calling(lazy view model)delays the call until later. During diffing, we can check to see ifmodelis referentially equal to the previous value used, and if so, we just stop. No need to build up the tree structure and diff it, we know if the input toviewis the same, the output must be the same!