refactor(behaviors): adjust unbind logic

This commit is contained in:
Aaron 2024-06-05 23:17:07 +08:00
parent 352dffb588
commit 38d690b218

View File

@ -170,14 +170,13 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
* @internal * @internal
*/ */
public update(options: Partial<DragElementOptions>): void { public update(options: Partial<DragElementOptions>): void {
this.unbindEvents();
super.update(options); super.update(options);
this.bindEvents(); this.bindEvents();
} }
private bindEvents() { private bindEvents() {
const { graph } = this.context; const { graph } = this.context;
this.unbindEvents();
this.enableElements.forEach((type) => { this.enableElements.forEach((type) => {
graph.on(`${type}:${CommonEvent.DRAG_START}`, this.onDragStart); graph.on(`${type}:${CommonEvent.DRAG_START}`, this.onDragStart);
graph.on(`${type}:${CommonEvent.DRAG}`, this.onDrag); graph.on(`${type}:${CommonEvent.DRAG}`, this.onDrag);
@ -415,6 +414,8 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
graph.off(`${type}:${CommonEvent.DRAG_START}`, this.onDragStart); graph.off(`${type}:${CommonEvent.DRAG_START}`, this.onDragStart);
graph.off(`${type}:${CommonEvent.DRAG}`, this.onDrag); graph.off(`${type}:${CommonEvent.DRAG}`, this.onDrag);
graph.off(`${type}:${CommonEvent.DRAG_END}`, this.onDragEnd); graph.off(`${type}:${CommonEvent.DRAG_END}`, this.onDragEnd);
graph.off(`${type}:${CommonEvent.POINTER_ENTER}`, this.setCursor);
graph.off(`${type}:${CommonEvent.POINTER_LEAVE}`, this.setCursor);
}); });
graph.off(`combo:${CommonEvent.DROP}`, this.onDrop); graph.off(`combo:${CommonEvent.DROP}`, this.onDrop);