Procházet zdrojové kódy

Cleaned view listeners in destroy method.

Oskar Wróbel před 8 roky
rodič
revize
2018d0f0e8

+ 11 - 1
packages/ckeditor5-ui/src/panel/balloon/balloonpanelview.js

@@ -188,12 +188,22 @@ export default class BalloonPanelView extends View {
 		// We need to listen on window resize event and update position.
 		this.listenTo( global.window, 'resize', () => this.attachTo( options ) );
 
-		// After all we need to clean up the listener.
+		// After all we need to clean up the listeners.
 		this.once( 'change:isVisible', () => {
 			this.stopListening( global.document, 'scroll' );
 			this.stopListening( global.window, 'resize' );
 		} );
 	}
+
+	/**
+	 * @inheritDoc
+	 */
+	destroy() {
+		this.stopListening( global.document, 'scroll' );
+		this.stopListening( global.window, 'resize' );
+
+		return super.destroy();
+	}
 }
 
 /**

+ 14 - 0
packages/ckeditor5-ui/tests/panel/balloon/balloonpanelview.js

@@ -472,6 +472,20 @@ describe( 'BalloonPanelView', () => {
 			// Still once.
 			expect( attachToSpy.calledOnce ).to.true;
 		} );
+
+		it( 'should stop attaching when the view will be destroyed', () => {
+			view.keepAttachedTo( { target, limiter } );
+
+			expect( attachToSpy.calledOnce ).to.true;
+
+			view.destroy();
+
+			window.dispatchEvent( new Event( 'resize' ) );
+			window.dispatchEvent( new Event( 'scroll' ) );
+
+			// Still once.
+			expect( attachToSpy.calledOnce ).to.true;
+		} );
 	} );
 } );