diff --git a/packages/core/src/behavior/behaviorOption.ts b/packages/core/src/behavior/behaviorOption.ts index 47f9d648122..85924c56571 100644 --- a/packages/core/src/behavior/behaviorOption.ts +++ b/packages/core/src/behavior/behaviorOption.ts @@ -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) { @@ -73,6 +74,7 @@ export default { graph.off(event, handler); }); graph.get('canvas').set('draggable', draggable); + document.removeEventListener('visibilitychange', this.handleVisibilityChange); }, get(val: string) { diff --git a/packages/core/src/graph/controller/mode.ts b/packages/core/src/graph/controller/mode.ts index 35ec116b816..748ecfa2299 100644 --- a/packages/core/src/graph/controller/mode.ts +++ b/packages/core/src/graph/controller/mode.ts @@ -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;