Understanding how the lazy function works?

Continuing the discussion of this previous topic Deep copy or shallow copy? - #8 by lydell

I would like to understand why, in the following code, the lazy function viewSubTree works despite the facts that a structure created on the fly is passed to the lazy function (the variable tree)

-- A tree structure
type Tree n
    = Tree
        { node : n
        , children : List (Tree n)
        }

-- convert a dict to a tree structure
buildTree :  NodesDict -> Tree Node
[...]


-- A function that display a tree selector
viewSelectorTree : (Node -> msg) -> GqlData (Dict string Node) -> Html msg
viewSelectorTree onTargetClick  odata =
    case odata of
        Success data ->
            let
                tree =
                    buildTree  data
            in
            div [ id "tree-selector", class "menu" ] [ Lazy.lazy2 viewSubTree onTargetClick tree ]

        _ ->
            div [ class "spinner" ] []

Understanding why this works could hopefully help us predict when a lazy function will be defeated and when it won’t, I believe.

Can you clarify what you mean by " the lazy function viewSubTree works"? Are you sure it doesn’t re-render on every update? As far as I can tell, you won’t get any performance improvements from that.

Ok, I double checked, and in fact, it re-render on each update indeed.

My apologies for the mistake, another event affected the number of renderings, which misled me…:confused:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.