Skip to content

Commit

Permalink
perf: remove visibilitychange event of behavior before destroy (#6326)
Browse files Browse the repository at this point in the history
  • Loading branch information
uhobnil authored Sep 12, 2024
1 parent cfb133f commit 49d2b57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/behavior/behaviorOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export default {
graph.on(event, handler);
});
// To avoid the tabs switching makes the keydown related behaviors disable
document.addEventListener('visibilitychange', () => {
this.handleVisibilityChange = () => {
this.keydown = false;
});
};
document.addEventListener('visibilitychange', this.handleVisibilityChange);
},

unbind(graph: IAbstractGraph) {
Expand All @@ -73,6 +74,7 @@ export default {
graph.off(event, handler);
});
graph.get('canvas').set('draggable', draggable);
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
},

get(val: string) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/graph/controller/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ export default class ModeController {
}

public destroy() {
each(this.currentBehaves, behave => {
if (behave.delegate) behave.delegate.remove();
behave.unbind(this.graph);
});
(this.graph as IAbstractGraph | null) = null;
(this.modes as Modes | null) = null;
(this.currentBehaves as IBehaviorOption[] | null) = null;
Expand Down

0 comments on commit 49d2b57

Please sign in to comment.