Convenient helper functions for working with
Html
A lazy version of contentList. This version takes a list of thunks paired with boolean values. The thunks are only evaluated for items that will be rendered (when their bool is True).
This is useful when the Html nodes are expensive to compute but the conditions are cheap.
For example:
viewAnimals : List Animal -> Html msg
viewAnimals animals =
Html.section [ Attributes.id "animals" ] <|
lazyContentList
[ ( \_ -> expensiveRenderFunction animal1, animal1.visible )
, ( \_ -> expensiveRenderFunction animal2, animal2.visible )
, ( \_ -> expensiveRenderFunction animal3, animal3.visible )
]wrapToSingleNode turns a list of Html nodes into a single node, using the following logic:
nothingdisplay: contentsMore on display: contents here: https://developer.mozilla.org/en-US/docs/Web/CSS/display#contents
nothing is a convenience function for the most idiomatic and common way to render nothing, namely an empty Html.text.
This function works similar to lazyContentList but for Maybe values. It will only render items that have a Just value (of any type) associated with them. It uses lazy2 for memoization of both the function and its parameter.
Example usage:
myView =
maybeContentList
[ ( \text -> Html.text text, Just "this will render" )
, ( \text -> Html.text text, Nothing ) -- this will not render
]
This function makes it easier to conditionally render Html.nodes. The most obvious usecase is similar to that of Attributes.classList, but for content rather than classes. Each entry in the list will be added and removed depending on the boolean value it is paired with.
For example, maybe we want to render a few animals: