views:

67

answers:

1

http://wwwendt.de/tech/dynatree/index.html

I would like to clarify the following: when addChild is invoked - does the whole tree gets re-rendered or just the nodes modified (added nodes and the nodes that have new children)?

I am getting 2 conflicting pieces of info: http://stackoverflow.com/questions/3026267/lazy-loading-in-dynatree it says that only affected nodes will get re-rendered

http://stackoverflow.com/questions/2241464/dynatree-slow-when-dynamically-loaded-with-100-nodes-unacceptable here it says that it does get re-rendered every time addChild is used

Perhaps, I am missing something?

Which one is it?

+1  A: 

Dynatree stores the nodes in an internal structure. 'Rendering' is the process of creating or updating HTML elements in the DOM to reflect the tree's status. For example the last node in a branch has a special class name, so appending a node requires removing this class from the previous 'last node' and adding it to the new one.

Every time you call .addChild(data), the rendering is triggered. If you pass 100 nodes with one call, the rendering is done only once, so this is always more performant than calling it 100 times with one single node.

Currently (release 0.5.4) addChild uses this pattern:

var prevFlag = tree.enableUpdate(false);
[modify the tree]
tree.enableUpdate(prevFlag);

enableUpdate(true) calls tree.redraw(), so the whole tree is updated. This will change with release 1.0, but even then it will be faster to combine addChild calls.

Another aspect is: when are nodes created in the DOM. Starting with 1.0 creation of HTML elements is deferred until the node becomes visible (expanded) for the first time. So it is possible to load a very large number of nodes into the efficient internal Dynatree data strucure without bloating the DOM.

If it is more user friendly to pre-load the whole tree, or lazy-load single branches on demand depends on server, network and client. So it's always a matter of benchmarking the different scenarios.

mar10
thanks for the info, just one more clarification: when .addChild(nodesToAdd) is called, are the existing nodes being redrawn as well? I understand that (obviously) the nodesToAdd will be rendered, but what about the existing nodes. Do this redraw the whole tree?
gnomixa
I just read your answer and I gather that the answer is Yes:) It seems that every time any nodes changes the tree gets re-drawn. It looks as though var prevFlag = tree.enableUpdate(false);returns 'true' if any nodes have been changed which would mean that the entire tree will get redrawn. Is my understanding correct? thank you again for your time.
gnomixa
enableUpdate(..) returns the previous update mode. This pattern allows to restore the previous state (even in a recursive call hierarchy).Since we don't keep track of modifications, enableUpdate(true) has always to update the whole tree: create new nodes and update class names for existing ones.For v1.0 I might change the implementation of mynode.addChild(childOrChildList) to redraw the mynode branch only.
mar10
I guess what I am wondering is whether enableUpdate(..) can ever return false. Looks like it always returns true. Sorry, I am being so finicky, just want to make sure that I understand you correctly.
gnomixa
enableUpdate(trueOrFalse) will return false, if updating is already disabled. i.e. someone called enableUpdate(false) before.In nested calls this pattern will make sure that only the outer method will call enableUpdate(true). So the tree will be redrawn only once when the call stack unwinds.
mar10
so in the scenario when I invoke node.addChild(children) where a node is a one of the nodes on the existing tree, the entire tree will get re-rendered?
gnomixa