[tree] make fewer first-tree calls to the API

When a child doesn't have children, avoid API first-tree calls.
parent 53800640
Pipeline #6150 passed with stages
in 13 minutes and 18 seconds
......@@ -90,9 +90,13 @@ type NSCommon =
, handed :: Handed
, session :: Session )
-- The annoying 'render' here is busting a cycle in the low tech
-- way. This function is only called by functions in this module, so
-- we just have to careful in what we pass.
-- | The annoying 'render' here is busting a cycle in the low tech
-- way. This function is only called by functions in this module, so
-- we just have to careful in what we pass.
-- Without the 'render' function though, we get a 'tree' cpt that
-- depends on a 'renderTreeChildren' component, which itself depends
-- on 'tree'. This results in PS 'CycleInDeclaration' compilation
-- error.
type ChildLoaderProps =
( id :: ID
, render :: R2.Leaf TreeProps
......@@ -109,7 +113,6 @@ type PerformActionProps =
-- | Loads and renders the tree starting at the given root node id.
treeLoader :: R2.Leaf ( key :: String | LoaderProps )
treeLoader = R2.leaf treeLoaderCpt
treeLoaderCpt :: R.Component ( key :: String | LoaderProps )
treeLoaderCpt = R2.hereComponent here "treeLoader" hCpt where
-- treeLoaderCpt :: R.Memo LoaderProps
......@@ -155,7 +158,6 @@ getNodeTreeFirstLevel session nodeId = get session $ GR.TreeFirstLevel (Just nod
tree :: R2.Leaf TreeProps
tree props = R.createElement treeCpt props []
treeCpt :: R.Component TreeProps
treeCpt = here.component "tree" cpt where
cpt p@{ frontends
......@@ -255,8 +257,42 @@ renderTreeChildrenCpt = here.component "renderTreeChildren" cpt where
where
nodeProps = RecordE.pick p :: Record NodeProps
renderChild (NTree (LNode {id: cId}) _) = childLoader props [] where
props = Record.merge nodeProps { id: cId, render, root }
-- | | If a child doesn't have children, avoid normal
-- | 'childLoader' which queries API for first-level data (there
-- | is nothing new here) and render the child immediately.
renderChild tree'@(NTree (LNode {id: cId}) []) = childDummyLoader renderProps []
where
renderProps = Record.merge nodeProps { id: cId, render, root, tree: tree' } :: Record ChildDummyLoaderProps
renderChild (NTree (LNode {id: cId}) _children) = childLoader renderProps []
where
renderProps = Record.merge nodeProps { id: cId, render, root } :: Record ChildLoaderProps
type ChildDummyLoaderProps =
( tree :: FTree
| ChildLoaderProps
)
-- | A "dummy" loader: this is because for nodes without children, we
-- | don't want to make the API call.
childDummyLoader :: R2.Component ChildDummyLoaderProps
childDummyLoader = R.createElement childDummyLoaderCpt
childDummyLoaderCpt :: R.Component ChildDummyLoaderProps
childDummyLoaderCpt = R2.hereComponent here "childDummyLoader" hCpt where
hCpt hp p@{ reloadTree
, render
, root
, tree: tree' } _ = do
{ reloadRoot } <- Store.use
reload <- T.useBox T2.newReload
pure $ paint reload tree'
where
paint reload tree' = render (Record.merge base extra) where
base = nodeProps { reload = reload }
extra = { root, tree: tree' }
nodeProps = RecordE.pick p :: Record NodeProps
childLoader :: R2.Component ChildLoaderProps
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment