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

Internal: Updated the usage of UI components which are now driven by synchronous initialization and destruction (see https://github.com/ckeditor/ckeditor5-ui/issues/225).

Piotrek Koszuliński пре 8 година
родитељ
комит
d53dac44b4

+ 6 - 4
packages/ckeditor5-editor-classic/src/classiceditor.js

@@ -55,9 +55,9 @@ export default class ClassicEditor extends StandardEditor {
 	destroy() {
 		this.updateEditorElement();
 		this._elementReplacer.restore();
+		this.ui.destroy();
 
-		return this.ui.destroy()
-			.then( () => super.destroy() );
+		return super.destroy();
 	}
 
 	/**
@@ -86,8 +86,10 @@ export default class ClassicEditor extends StandardEditor {
 			resolve(
 				editor.initPlugins()
 					.then( () => editor._elementReplacer.replace( element, editor.ui.view.element ) )
-					.then( () => editor.ui.init() )
-					.then( () => editor.fire( 'uiReady' ) )
+					.then( () => {
+						editor.ui.init();
+						editor.fire( 'uiReady' );
+					} )
 					.then( () => editor.editing.view.attachDomRoot( editor.ui.view.editableElement ) )
 					.then( () => editor.loadDataFromEditorElement() )
 					.then( () => {

+ 10 - 17
packages/ckeditor5-editor-classic/src/classiceditorui.js

@@ -62,32 +62,25 @@ export default class ClassicEditorUI {
 
 	/**
 	 * Initializes the UI.
-	 *
-	 * @returns {Promise} A Promise resolved when the initialization process is finished.
 	 */
 	init() {
 		const editor = this.editor;
 
-		return this.view.init()
-			.then( () => {
-				return this.view.toolbar.fillFromConfig( editor.config.get( 'toolbar' ), this.componentFactory );
-			} )
-			.then( () => {
-				enableToolbarKeyboardFocus( {
-					origin: editor.editing.view,
-					originFocusTracker: this.focusTracker,
-					originKeystrokeHandler: editor.keystrokes,
-					toolbar: this.view.toolbar
-				} );
-			} );
+		this.view.init();
+		this.view.toolbar.fillFromConfig( editor.config.get( 'toolbar' ), this.componentFactory );
+
+		enableToolbarKeyboardFocus( {
+			origin: editor.editing.view,
+			originFocusTracker: this.focusTracker,
+			originKeystrokeHandler: editor.keystrokes,
+			toolbar: this.view.toolbar
+		} );
 	}
 
 	/**
 	 * Destroys the UI.
-	 *
-	 * @returns {Promise} A Promise resolved when the destruction process is finished.
 	 */
 	destroy() {
-		return this.view.destroy();
+		this.view.destroy();
 	}
 }

+ 18 - 43
packages/ckeditor5-editor-classic/tests/classiceditorui.js

@@ -117,51 +117,38 @@ describe( 'ClassicEditorUI', () => {
 
 	describe( 'init()', () => {
 		afterEach( () => {
-			return ui.destroy();
-		} );
-
-		it( 'returns a promise', () => {
-			document.body.appendChild( view.element );
-
-			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( 'fills view.toolbar#items with editor config', () => {
 			const spy = testUtils.sinon.spy( view.toolbar, 'fillFromConfig' );
 
-			return ui.init().then( () => {
-				sinon.assert.calledWithExactly( spy, editor.config.get( 'toolbar' ), ui.componentFactory );
-			} );
+			ui.init();
+			sinon.assert.calledWithExactly( spy, editor.config.get( 'toolbar' ), ui.componentFactory );
 		} );
 
 		it( 'initializes keyboard navigation between view#toolbar and view#editable', () => {
 			const spy = testUtils.sinon.spy( view.toolbar, 'focus' );
 
-			return ui.init().then( () => {
-				ui.focusTracker.isFocused = true;
-				ui.view.toolbar.focusTracker.isFocused = false;
-
-				editor.keystrokes.press( {
-					keyCode: keyCodes.f10,
-					altKey: true,
-					preventDefault: sinon.spy(),
-					stopPropagation: sinon.spy()
-				} );
+			ui.init();
+			ui.focusTracker.isFocused = true;
+			ui.view.toolbar.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 );
 		} );
 	} );
 
@@ -170,24 +157,12 @@ describe( 'ClassicEditorUI', () => {
 			document.body.appendChild( view.element );
 		} );
 
-		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 );
 		} );
 	} );
 } );

+ 3 - 5
packages/ckeditor5-editor-classic/tests/classiceditoruiview.js

@@ -56,11 +56,9 @@ describe( 'ClassicEditorUIView', () => {
 		it( 'returns editable\'s view element', () => {
 			document.body.appendChild( 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();
 		} );
 	} );
 } );