Преглед изворни кода

Made ContextualBalloon plugin synchronous.

Aleksander Nowodzinski пре 8 година
родитељ
комит
e066458e37

+ 6 - 13
packages/ckeditor5-ui/src/panel/balloon/contextualballoon.js

@@ -60,7 +60,7 @@ export default class ContextualBalloon extends Plugin {
 		this.editor.ui.focusTracker.add( this.view.element );
 
 		// Add balloon panel view to editor `body` collection and wait until view will be ready.
-		return this.editor.ui.view.body.add( this.view );
+		this.editor.ui.view.body.add( this.view );
 	}
 
 	/**
@@ -92,7 +92,6 @@ export default class ContextualBalloon extends Plugin {
 	 * @param {module:ui/view~View} [data.view] Content of the balloon.
 	 * @param {module:utils/dom/position~Options} [data.position] Positioning options.
 	 * @param {String} [data.balloonClassName] Additional css class for {@link #view} added when given view is visible.
-	 * @returns {Promise} A Promise resolved when the child {@link module:ui/view~View#init} is done.
 	 */
 	add( data ) {
 		if ( this.hasView( data.view ) ) {
@@ -112,8 +111,9 @@ export default class ContextualBalloon extends Plugin {
 
 		// Add new view to the stack.
 		this._stack.set( data.view, data );
+
 		// And display it.
-		return this._show( data );
+		this._show( data );
 	}
 
 	/**
@@ -122,7 +122,6 @@ export default class ContextualBalloon extends Plugin {
 	 * When there is no view in the stack then balloon will hide.
 	 *
 	 * @param {module:ui/view~View} view A view to be removed from the balloon.
-	 * @returns {Promise} A Promise resolved when the preceding view is ready.
 	 */
 	remove( view ) {
 		if ( !this.hasView( view ) ) {
@@ -134,9 +133,6 @@ export default class ContextualBalloon extends Plugin {
 			throw new CKEditorError( 'contextualballoon-remove-view-not-exist: Cannot remove configuration of not existing view.' );
 		}
 
-		// A Promise resolved when the preceding view is ready.
-		let promise = Promise.resolve();
-
 		// When visible view is being removed.
 		if ( this.visibleView === view ) {
 			// We need to remove it from the view content.
@@ -151,7 +147,7 @@ export default class ContextualBalloon extends Plugin {
 			// If it is some other view.
 			if ( last ) {
 				// Just show it.
-				promise = this._show( last );
+				this._show( last );
 			} else {
 				// Hide the balloon panel.
 				this.view.hide();
@@ -160,8 +156,6 @@ export default class ContextualBalloon extends Plugin {
 			// Just remove given view from the stack.
 			this._stack.delete( view );
 		}
-
-		return promise;
 	}
 
 	/**
@@ -190,9 +184,8 @@ export default class ContextualBalloon extends Plugin {
 	_show( { view, balloonClassName = '' } ) {
 		this.view.className = balloonClassName;
 
-		return this.view.content.add( view ).then( () => {
-			this.view.pin( this._getBalloonPosition() );
-		} );
+		this.view.content.add( view );
+		this.view.pin( this._getBalloonPosition() );
 	}
 
 	/**

+ 0 - 2
packages/ckeditor5-ui/tests/manual/contextualballoon/contextualballoon.js

@@ -153,8 +153,6 @@ class PluginGeneric extends Plugin {
 
 			return toolbar.fillFromConfig( this.buttons, this.editor.ui.componentFactory );
 		}
-
-		return Promise.resolve();
 	}
 
 	_showPanel() {

+ 16 - 79
packages/ckeditor5-ui/tests/panel/balloon/contextualballoon.js

@@ -10,7 +10,7 @@ import View from '../../../src/view';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 
-/* global document, Event, setTimeout */
+/* global document, Event */
 
 describe( 'ContextualBalloon', () => {
 	let editor, editorElement, balloon, viewA, viewB;
@@ -35,13 +35,12 @@ describe( 'ContextualBalloon', () => {
 			viewB = new View();
 
 			// Add viewA to the pane and init viewB.
-			return Promise.all( [
-				balloon.add( {
-					view: viewA,
-					position: { target: 'fake' }
-				} ),
-				viewB.init(),
-			] );
+			balloon.add( {
+				view: viewA,
+				position: { target: 'fake' }
+			} );
+
+			viewB.init();
 		} );
 	} );
 
@@ -104,33 +103,6 @@ describe( 'ContextualBalloon', () => {
 	} );
 
 	describe( 'add()', () => {
-		it( 'should return promise resolved when view is ready', done => {
-			const clock = sinon.useFakeTimers();
-
-			const view = {
-				init: () => {
-					return new Promise( resolve => {
-						setTimeout( () => {
-							resolve();
-						}, 10 );
-					} );
-				},
-				destroy: () => {}
-			};
-
-			const result = balloon.add( {
-				view,
-				position: { target: 'fake' }
-			} );
-
-			expect( result ).to.instanceof( Promise );
-
-			result.then( done );
-
-			clock.tick( 11 );
-			clock.restore();
-		} );
-
 		it( 'should add view to the stack and display in balloon attached using given position options', () => {
 			expect( balloon.view.content.length ).to.equal( 1 );
 			expect( balloon.view.content.get( 0 ) ).to.deep.equal( viewA );
@@ -162,20 +134,19 @@ describe( 'ContextualBalloon', () => {
 		} );
 
 		it( 'should keep balloon at the same position after adding next view', () => {
-			return balloon.add( {
+			balloon.add( {
 				view: viewB,
 				position: { target: 'other' }
-			} )
-			.then( () => {
-				expect( balloon.view.pin.calledTwice ).to.true;
+			} );
 
-				expect( balloon.view.pin.firstCall.args[ 0 ] ).to.deep.equal( {
-					target: 'fake'
-				} );
+			expect( balloon.view.pin.calledTwice ).to.true;
 
-				expect( balloon.view.pin.secondCall.args[ 0 ] ).to.deep.equal( {
-					target: 'fake'
-				} );
+			expect( balloon.view.pin.firstCall.args[ 0 ] ).to.deep.equal( {
+				target: 'fake'
+			} );
+
+			expect( balloon.view.pin.secondCall.args[ 0 ] ).to.deep.equal( {
+				target: 'fake'
 			} );
 		} );
 
@@ -221,10 +192,6 @@ describe( 'ContextualBalloon', () => {
 	} );
 
 	describe( 'remove()', () => {
-		it( 'should return promise', () => {
-			expect( balloon.remove( viewA ) ).to.instanceof( Promise );
-		} );
-
 		it( 'should remove given view and hide balloon when there is no other view to display', () => {
 			balloon.view.isVisible = true;
 
@@ -245,36 +212,6 @@ describe( 'ContextualBalloon', () => {
 			expect( balloon.visibleView ).to.equal( viewA );
 		} );
 
-		it( 'should wait for init of preceding view when was is not ready', done => {
-			const clock = sinon.useFakeTimers();
-
-			const view = {
-				init: () => {
-					return new Promise( resolve => {
-						setTimeout( () => {
-							resolve();
-						}, 10 );
-					} );
-				},
-				destroy: () => {}
-			};
-
-			balloon.add( {
-				view,
-				position: { target: 'fake' }
-			} );
-
-			balloon.add( {
-				view: viewB,
-				position: { target: 'fake' }
-			} );
-
-			balloon.remove( viewB ).then( done );
-
-			clock.tick( 11 );
-			clock.restore();
-		} );
-
 		it( 'should remove given view from the stack when view is not visible', () => {
 			balloon.add( {
 				view: viewB,