my onCreateLi is an expensive operation. In some cases it will require some additional calls to the server and create dialogs, etc.
So, I have some template function for populating it li, so that it looks like this:
onCreateLi: (node, $li)-> $li.find('.title').html renderTemplate(node)
the renderTemplate will make some AJAX calls to fill a hidden dialog returned by renderTemplate with items from this call.
Something like:
some content here
Dialog content here to be filled dynamically on AJAX return
The problem is that appendNode will remove all nodes and create all of them again on each call:
https://github.com/mbraak/jqTree/blob/dev/tree.jquery.coffee#L688
https://github.com/mbraak/jqTree/blob/dev/tree.jquery.coffee#L683
There is no need for appendNode to behave this way. This should be much less expensive operation and only append a node and eventually toggle the parent node to become a folder if it is the first element.
Even if you want to recreate the parent node, you could detach the children instead, create the parent node, re-attach them and append the new node. This should be much faster, but can also lead to unexpected results (just like the current situation). For example, one might want to attach some data to the ul element ($(ulElement).data 'some', 'thing'). When you remove and recreate the ul that data would be lost.
This is usually not expected. If you're just appending one node, the other nodes should remain intact. In a similar way, if you're removing a node, only that node and their children should be affected. Recreating the entire tree is way too expensive.
Could you please consider reducing the need for calling onCreateLi more than once for each new node?