Explorar el Código

Fix destructuring views.

Maciej Gołaszewski hace 7 años
padre
commit
7c4fcd01c1

+ 1 - 0
packages/ckeditor5-ui/docs/_snippets/examples/bootstrap-ui-inner.js

@@ -176,6 +176,7 @@ class BootstrapEditorUI {
 
 	destroy() {
 		this.view.editable.destroy();
+		this.view.destroy();
 	}
 
 	// This method activates Bold, Italic, Underline, Undo and Redo buttons in the toolbar.

+ 4 - 0
packages/ckeditor5-ui/src/template.js

@@ -210,6 +210,10 @@ export default class Template {
 		this._revertTemplateFromNode( node, this._revertData );
 	}
 
+	destroy() {
+		this.stopListening();
+	}
+
 	/**
 	 * Returns an iterator which traverses the template in search of {@link module:ui/view~View}
 	 * instances and returns them one by one.

+ 5 - 2
packages/ckeditor5-ui/src/toolbar/balloon/balloontoolbar.js

@@ -254,9 +254,12 @@ export default class BalloonToolbar extends Plugin {
 	 * @inheritDoc
 	 */
 	destroy() {
-		this._fireSelectionChangeDebounced.cancel();
-		this.stopListening();
 		super.destroy();
+
+		this.stopListening();
+		this._fireSelectionChangeDebounced.cancel();
+		this.toolbarView.destroy();
+		this.focusTracker.destroy();
 	}
 
 	/**

+ 8 - 0
packages/ckeditor5-ui/src/view.js

@@ -92,6 +92,7 @@ export default class View {
 	 * @param {module:utils/locale~Locale} [locale] The localization services instance.
 	 */
 	constructor( locale ) {
+		// console.log( 'new', this.constructor.name, '()' );
 		/**
 		 * An HTML element of the view. `null` until {@link #render rendered}
 		 * from the {@link #template}.
@@ -493,6 +494,13 @@ export default class View {
 		this.stopListening();
 
 		this._viewCollections.map( c => c.destroy() );
+		this._viewCollections.clear();
+		this._unboundChildren.clear();
+
+		// Template isn't obligatory for views.
+		if ( this.template && this.template._revertData ) {
+			this.template.revert( this.element );
+		}
 	}
 
 	/**

+ 1 - 0
packages/ckeditor5-ui/src/viewcollection.js

@@ -103,6 +103,7 @@ export default class ViewCollection extends Collection {
 	 */
 	destroy() {
 		this.map( view => view.destroy() );
+		this.clear();
 	}
 
 	/**