8
0
Просмотр исходного кода

Aligned Editor Balloon Toolbar package to the synchronous UI API.

Aleksander Nowodzinski 8 лет назад
Родитель
Сommit
0d68da1414

+ 7 - 4
packages/ckeditor5-editor-balloon/src/balloontoolbareditor.js

@@ -52,8 +52,9 @@ export default class BalloonToolbarEditor extends StandardEditor {
 		// It's safe to assume that the model->view conversion will not work after super.destroy().
 		const data = this.getData();
 
-		return this.ui.destroy()
-			.then( () => super.destroy() )
+		this.ui.destroy();
+
+		return super.destroy()
 			.then( () => setDataInElement( this.element, data ) );
 	}
 
@@ -82,8 +83,10 @@ export default class BalloonToolbarEditor extends StandardEditor {
 
 			resolve(
 				editor.initPlugins()
-					.then( () => editor.ui.init() )
-					.then( () => editor.fire( 'uiReady' ) )
+					.then( () => {
+						editor.ui.init();
+						editor.fire( 'uiReady' );
+					} )
 					.then( () => editor.loadDataFromEditorElement() )
 					.then( () => {
 						editor.fire( 'dataReady' );

+ 8 - 12
packages/ckeditor5-editor-balloon/src/balloontoolbareditorui.js

@@ -58,29 +58,25 @@ export default class BalloonToolbarEditorUI {
 
 	/**
 	 * Initializes the UI.
-	 *
-	 * @returns {Promise} A Promise resolved when the initialization process is finished.
 	 */
 	init() {
 		const editor = this.editor;
 		const contextualToolbar = editor.plugins.get( 'ui/contextualtoolbar' );
 
-		return this.view.init().then( () => {
-			enableToolbarKeyboardFocus( {
-				origin: editor.editing.view,
-				originFocusTracker: this.focusTracker,
-				originKeystrokeHandler: editor.keystrokes,
-				toolbar: contextualToolbar.toolbarView
-			} );
+		this.view.init();
+
+		enableToolbarKeyboardFocus( {
+			origin: editor.editing.view,
+			originFocusTracker: this.focusTracker,
+			originKeystrokeHandler: editor.keystrokes,
+			toolbar: contextualToolbar.toolbarView
 		} );
 	}
 
 	/**
 	 * Destroys the UI.
-	 *
-	 * @returns {Promise} A Promise resolved when the destruction process is finished.
 	 */
 	destroy() {
-		return this.view.destroy();
+		this.view.destroy();
 	}
 }

+ 17 - 38
packages/ckeditor5-editor-balloon/tests/balloontoolbareditorui.js

@@ -94,64 +94,43 @@ describe( 'BalloonToolbarEditorUI', () => {
 
 	describe( 'init()', () => {
 		afterEach( () => {
-			return ui.destroy();
-		} );
-
-		it( 'returns a promise', () => {
-			const promise = ui.init().then( () => {
-				expect( promise ).to.be.instanceof( Promise );
-			} );
-
-			return promise;
+			ui.destroy();
 		} );
 
 		it( 'initializes the #view', () => {
 			const spy = sinon.spy( view, 'init' );
 
-			return ui.init().then( () => {
-				sinon.assert.calledOnce( spy );
-			} );
+			ui.init();
+			sinon.assert.calledOnce( spy );
 		} );
 
 		it( 'initializes keyboard navigation between view#toolbar and view#editable', () => {
 			const toolbar = editor.plugins.get( 'ui/contextualtoolbar' );
 			const spy = testUtils.sinon.spy( toolbar.toolbarView, 'focus' );
 
-			return ui.init().then( () => {
-				ui.focusTracker.isFocused = true;
-				toolbar.toolbarView.focusTracker.isFocused = false;
-
-				editor.keystrokes.press( {
-					keyCode: keyCodes.f10,
-					altKey: true,
-					preventDefault: sinon.spy(),
-					stopPropagation: sinon.spy()
-				} );
+			ui.init();
+			ui.focusTracker.isFocused = true;
+			toolbar.toolbarView.focusTracker.isFocused = false;
 
-				sinon.assert.calledOnce( spy );
+			editor.keystrokes.press( {
+				keyCode: keyCodes.f10,
+				altKey: true,
+				preventDefault: sinon.spy(),
+				stopPropagation: sinon.spy()
 			} );
+
+			sinon.assert.calledOnce( spy );
 		} );
 	} );
 
 	describe( 'destroy()', () => {
-		it( 'returns a promise', () => {
-			return ui.init().then( () => {
-				const promise = ui.destroy().then( () => {
-					expect( promise ).to.be.instanceof( Promise );
-				} );
-
-				return promise;
-			} );
-		} );
-
 		it( 'destroys the #view', () => {
 			const spy = sinon.spy( view, 'destroy' );
 
-			return ui.init()
-				.then( () => ui.destroy() )
-				.then( () => {
-					sinon.assert.calledOnce( spy );
-				} );
+			ui.init();
+			ui.destroy();
+
+			sinon.assert.calledOnce( spy );
 		} );
 	} );
 } );

+ 6 - 10
packages/ckeditor5-editor-balloon/tests/balloontoolbareditoruiview.js

@@ -28,22 +28,18 @@ describe( 'BalloonToolbarEditorUIView', () => {
 			it( 'is registered as a child', () => {
 				const spy = sinon.spy( view.editable, 'destroy' );
 
-				return view.init()
-					.then( () => view.destroy() )
-					.then( () => {
-						sinon.assert.calledOnce( spy );
-					} );
+				view.init();
+				view.destroy();
+				sinon.assert.calledOnce( spy );
 			} );
 		} );
 	} );
 
 	describe( 'editableElement', () => {
 		it( 'returns editable\'s view element', () => {
-			return view.init()
-				.then( () => {
-					expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
-				} )
-				.then( () => view.destroy() );
+			view.init();
+			expect( view.editableElement.getAttribute( 'contentEditable' ) ).to.equal( 'true' );
+			view.destroy();
 		} );
 	} );
 } );