Support to Element Event
Every element object can be set with one listener, by which related events of elements can be handled, such as change event of element property, child change events and so on. In addition, the element event is generally divided into two steps. The “beforeEvent” is called before event handling. To go back to false, stop event execution. “onEvent” will be called after event execution.
Related properties and methods of event
- #listener - in GraphModel, the listener will be handled by GraphModel in unification, not directly on graph #beforeEvent(evt) - before event handling
- #onEvent(evt) - after event handling
Example
The following is the default code for setting child order. The handling process of internal event can be showed
setChildIndex: function(child, index) {
if(!this._children || !this._children.length){
return false;
}
var oldIndex = this._children.indexOf(child);
if(oldIndex < 0 || oldIndex == index){
return false;
}
var event = new ChildIndexChangeEvent(this, child, oldIndex, index);
if(this.beforeEvent(event) === false){
return false;
}
if(this._children.remove(child)){
this._children.add(child, index);
}
this.onEvent(event);
return true;
}