## Tree events

There are many classes of events, published with dojo.event.publish mechanism. Every event has a name and message object, containing more precise information about what happened. You may use events to update your data while tree changes, and to perform additional processing of involved objects.

There is a default naming scheme for an event class. E.g for a tree with widgetId='mytree', event of class afterTreeCreate will be named "mytree/afterTreeCreate". You may provide other names in eventNames property of the tree.

### afterTreeCreate

Event occurs after tree creation is complete. There is an alternative to hook on this action by putting your objects in "listeners" property of the tree. The difference is that listeners are guaranteed to hook before nodes get added, and afterTreeCreate is published after Tree widget is created.

source
  references to tree

### beforeTreeDestroy

Published right before actual Tree#destroy method is called. Useful for cleanups

source
  references to tree

### beforeNodeDestroy

Right before TreeNode#destroy is called. Node is detached after this event fired.

source
  references to node

### afterChangeTree

This event is tightly created with node creation process. It is fired when

- a node is created
- a node moves to another tree widget

oldTree
  references previous tree, null if node has been just created
newTree
  new(current) tree
node
  target node

### afterSetFolder

Fires when a node obtains "folder" state. That may happen when a first child is added to a leaf, or if a node was initially created with isFolder=true

source
  references to node

### afterUnsetFolder

Fires when a node obtains looses "folder" state. That may happen when a last child leaves the node, and Tree.unsetFolderOnEmptyis set, or when unsetFolder is called explicitly.

source
  references to node

### (before|after)Move(From|To)

These events share same arguments and fire when a node is moved. Move process is considered something special. When you move a node, no detach/addChild events get thrown. That allows to tell situations when a node leaves a tree for some time (detached then attached) from situations when a node is simply moved to another location

oldParent
  previous parent
oldTree
  previous tree
oldIndex
  previous index among siblings
newParent
  new parent
newTree
  new tree
newIndex
  new index among siblings
child
  target node

### afterAddChild

Published when a node is attached to parent. This may happen at the end of creation process, or when a node is lazily instantiated from data object.

child
  references to node
index
  index among siblings
parent
  current parent who adopted a child
childWidgetCreated
  flag is set if child was laziliy instantiated. That is: it resided as data object in children array, but user expanded its parent, so node widget came to life.

### afterDetach

Occurs when a node is detached. This may happen in the process of node destruction.

child
  references to node
parent
  references to old parent
index
  references to index among children of old parent

### after(Expand|Collapse)

Fire when a node is expanded/collapsed. Some togglers do nice animation hiding/showing node. This event fires when animation finishes.

source
  target node

### afterSetTitle

When a node is edited, or explicit setTitle method is called, this event helps to inform interested parts about changes.

source
  target node
title
  new node title