瀏覽代碼

Made ToolbarView synchronous.

Aleksander Nowodzinski 8 年之前
父節點
當前提交
710f211c14

+ 2 - 3
packages/ckeditor5-ui/src/toolbar/sticky/stickytoolbarview.js

@@ -175,9 +175,8 @@ export default class StickyToolbarView extends ToolbarView {
 	 * Destroys the toolbar and removes the {@link #_elementPlaceholder}.
 	 */
 	destroy() {
-		return super.destroy().then( () => {
-			this._elementPlaceholder.remove();
-		} );
+		super.destroy();
+		this._elementPlaceholder.remove();
 	}
 
 	/**

+ 5 - 6
packages/ckeditor5-ui/src/toolbar/toolbarview.js

@@ -103,7 +103,7 @@ export default class ToolbarView extends View {
 		// Start listening for the keystrokes coming from #element.
 		this.keystrokes.listenTo( this.element );
 
-		return super.init();
+		super.init();
 	}
 
 	/**
@@ -119,18 +119,17 @@ export default class ToolbarView extends View {
 	 *
 	 * @param {Array} config The toolbar config.
 	 * @param {module:ui/componentfactory~ComponentFactory} factory A factory producing toolbar items.
-	 * @returns {Promise} A promise resolved when created toolbar items are initialized.
 	 */
 	fillFromConfig( config, factory ) {
 		if ( !config ) {
-			return Promise.resolve();
+			return;
 		}
 
-		return Promise.all( config.map( name => {
+		config.map( name => {
 			const component = name == '|' ? new ToolbarSeparatorView() : factory.create( name );
 
-			return this.items.add( component );
-		} ) );
+			this.items.add( component );
+		} );
 	}
 }
 

+ 5 - 12
packages/ckeditor5-ui/tests/manual/stickytoolbarview/stickytoolbarview.js

@@ -3,29 +3,22 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals console:false */
-
 import testUtils from '../../../tests/_utils/utils';
 import StickyToolbarView from '../../../src/toolbar/sticky/stickytoolbarview';
 
 import '@ckeditor/ckeditor5-theme-lark/theme/theme.scss';
 
-testUtils.createTestUIView( {
+const ui = testUtils.createTestUIView( {
 	top: '.ck-editor__top'
-} )
-.then( ui => {
-	createToolbar( ui.top );
-} )
-.catch( err => {
-	console.error( err.stack );
 } );
 
+createToolbar( ui.top );
+
 function createToolbar( collection ) {
 	const toolbar = new StickyToolbarView();
 
 	toolbar.limiterElement = collection._parentElement.parentNode;
 
-	collection.add( toolbar ).then( () => {
-		toolbar.isActive = true;
-	} );
+	collection.add( toolbar );
+	toolbar.isActive = true;
 }

+ 7 - 16
packages/ckeditor5-ui/tests/toolbar/sticky/stickytoolbarview.js

@@ -174,32 +174,23 @@ describe( 'StickyToolbarView', () => {
 	} );
 
 	describe( 'destroy()', () => {
-		it( 'should return a promise', () => {
-			expect( view.destroy() ).to.be.instanceof( Promise );
-		} );
-
-		it( 'can be called multiple times', done => {
+		it( 'can be called multiple times', () => {
 			expect( () => {
-				view.destroy().then( () => {
-					return view.destroy().then( () => {
-						done();
-					} );
-				} );
+				view.destroy();
+				view.destroy();
 			} ).to.not.throw();
 		} );
 
 		it( 'calls destroy on parent class', () => {
 			const spy = testUtils.sinon.spy( ToolbarView.prototype, 'destroy' );
 
-			return view.destroy().then( () => {
-				expect( spy.calledOnce ).to.be.true;
-			} );
+			view.destroy();
+			expect( spy.calledOnce ).to.be.true;
 		} );
 
 		it( 'removes view._elementPlaceholder from DOM', () => {
-			return view.destroy().then( () => {
-				expect( view._elementPlaceholder.parentNode ).to.be.null;
-			} );
+			view.destroy();
+			expect( view._elementPlaceholder.parentNode ).to.be.null;
 		} );
 	} );
 

+ 17 - 18
packages/ckeditor5-ui/tests/toolbar/toolbarview.js

@@ -21,8 +21,7 @@ describe( 'ToolbarView', () => {
 	beforeEach( () => {
 		locale = {};
 		view = new ToolbarView( locale );
-
-		return view.init();
+		view.init();
 	} );
 
 	describe( 'constructor()', () => {
@@ -82,10 +81,9 @@ describe( 'ToolbarView', () => {
 
 			const spy = sinon.spy( view.keystrokes, 'listenTo' );
 
-			return view.init().then( () => {
-				sinon.assert.calledOnce( spy );
-				sinon.assert.calledWithExactly( spy, view.element );
-			} );
+			view.init();
+			sinon.assert.calledOnce( spy );
+			sinon.assert.calledWithExactly( spy, view.element );
 		} );
 
 		describe( 'activates keyboard navigation for the toolbar', () => {
@@ -232,21 +230,22 @@ describe( 'ToolbarView', () => {
 			factory.add( 'bar', namedFactory( 'bar' ) );
 		} );
 
-		it( 'returns a promise', () => {
-			expect( view.fillFromConfig() ).to.be.instanceOf( Promise );
+		it( 'does not throw when no config is provided', () => {
+			expect( () => {
+				view.fillFromConfig();
+			} ).to.not.throw();
 		} );
 
 		it( 'expands the config into collection', () => {
-			return view.fillFromConfig( [ 'foo', 'bar', '|', 'foo' ], factory )
-				.then( () => {
-					const items = view.items;
-
-					expect( items ).to.have.length( 4 );
-					expect( items.get( 0 ).name ).to.equal( 'foo' );
-					expect( items.get( 1 ).name ).to.equal( 'bar' );
-					expect( items.get( 2 ) ).to.be.instanceOf( ToolbarSeparatorView );
-					expect( items.get( 3 ).name ).to.equal( 'foo' );
-				} );
+			view.fillFromConfig( [ 'foo', 'bar', '|', 'foo' ], factory );
+
+			const items = view.items;
+
+			expect( items ).to.have.length( 4 );
+			expect( items.get( 0 ).name ).to.equal( 'foo' );
+			expect( items.get( 1 ).name ).to.equal( 'bar' );
+			expect( items.get( 2 ) ).to.be.instanceOf( ToolbarSeparatorView );
+			expect( items.get( 3 ).name ).to.equal( 'foo' );
 		} );
 	} );
 } );