Selaa lähdekoodia

Made ButtonView synchronous.

Aleksander Nowodzinski 8 vuotta sitten
vanhempi
commit
49f705a352

+ 2 - 4
packages/ckeditor5-ui/src/button/buttonview.js

@@ -207,8 +207,6 @@ export default class ButtonView extends View {
 	 * @inheritDoc
 	 */
 	init() {
-		let promise = Promise.resolve();
-
 		if ( this.icon && !this.iconView ) {
 			const iconView = this.iconView = new IconView();
 
@@ -217,10 +215,10 @@ export default class ButtonView extends View {
 			this.element.insertBefore( iconView.element, this.element.firstChild );
 
 			// Make sure the icon view will be destroyed along with button.
-			promise = promise.then( () => this.addChildren( iconView ) );
+			this.addChildren( iconView );
 		}
 
-		return promise.then( () => super.init() );
+		super.init();
 	}
 
 	/**

+ 12 - 14
packages/ckeditor5-ui/tests/button/buttonview.js

@@ -225,29 +225,27 @@ describe( 'ButtonView', () => {
 			view = new ButtonView( locale );
 			view.icon = 'foo';
 
-			return view.init().then( () => {
-				expect( view.element.childNodes ).to.have.length( 2 );
-				expect( view.element.childNodes[ 0 ] ).to.equal( view.iconView.element );
+			view.init();
+			expect( view.element.childNodes ).to.have.length( 2 );
+			expect( view.element.childNodes[ 0 ] ).to.equal( view.iconView.element );
 
-				expect( view.iconView ).to.instanceOf( IconView );
-				expect( view.iconView.content ).to.equal( 'foo' );
+			expect( view.iconView ).to.instanceOf( IconView );
+			expect( view.iconView.content ).to.equal( 'foo' );
 
-				view.icon = 'bar';
-				expect( view.iconView.content ).to.equal( 'bar' );
-			} );
+			view.icon = 'bar';
+			expect( view.iconView.content ).to.equal( 'bar' );
 		} );
 
 		it( 'is destroyed with the view', () => {
 			view = new ButtonView( locale );
 			view.icon = 'foo';
 
-			return view.init().then( () => {
-				const spy = sinon.spy( view.iconView, 'destroy' );
+			view.init();
 
-				return view.destroy().then( () => {
-					sinon.assert.calledOnce( spy );
-				} );
-			} );
+			const spy = sinon.spy( view.iconView, 'destroy' );
+
+			view.destroy();
+			sinon.assert.calledOnce( spy );
 		} );
 	} );