 module.exports = class TreeView extends EventEmitter
 
   constructor: (container, @dropCallback) ->
-    @_treeRoot = document.createElement 'ol'
-    @_treeRoot.classList.add 'tree'
-    container.appendChild @_treeRoot
+    @treeRoot = document.createElement 'ol'
+    @treeRoot.classList.add 'tree'
+    container.appendChild @treeRoot
 
     @selectedNodes = []
     @_firstSelectedNode = null
 
-    @_treeRoot.addEventListener 'click', @_onClick
-    @_treeRoot.addEventListener 'dblclick', @_onDoubleClick
-    @_treeRoot.addEventListener 'dragstart', @_onDragStart
-    @_treeRoot.addEventListener 'dragover', @_onDragOver
-    @_treeRoot.addEventListener 'dragleave', @_onDragLeave
-    @_treeRoot.addEventListener 'drop', @_onDrop
+    @treeRoot.addEventListener 'click', @_onClick
+    @treeRoot.addEventListener 'dblclick', @_onDoubleClick
+    @treeRoot.addEventListener 'dragstart', @_onDragStart
+    @treeRoot.addEventListener 'dragover', @_onDragOver
+    @treeRoot.addEventListener 'dragleave', @_onDragLeave
+    @treeRoot.addEventListener 'drop', @_onDrop
 
   clearSelection: ->
     selectedNode.classList.remove 'selected' for selectedNode in @selectedNodes

    event.preventDefault()

  _clearDropClasses: ->
    @_treeRoot.querySelector('.drop-above')?.classList.remove('drop-above')
    @_treeRoot.querySelector('.drop-inside')?.classList.remove('drop-inside')
    @_treeRoot.querySelector('.drop-below')?.classList.remove('drop-below')
    return

  _onDragLeave: (event) =>


    element = event.target
    while element.tagName != 'LI' or (! element.classList.contains('item') and ! element.classList.contains('group'))
      return selectionChanged if element == @treeRoot
      element = element.parentElement

    if @selectedNodes.length > 0 and @selectedNodes[0].parentElement != element.parentElement
