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

Merge pull request #26 from ckeditor/t/ckeditor5/1477

Other: Adjustments to new editor initialisation events.
BREAKING CHANGE: The `editor#dataReady` event was removed. The `editor.data#ready` event has been introduced and should be used instead.
BREAKING CHANGE: The `editor#pluginsReady` event was removed. Use plugin `afterInit()` method instead.
Piotr Jasiun 7 лет назад
Родитель
Сommit
05e977f450

+ 1 - 4
packages/ckeditor5-editor-decoupled/src/decouplededitor.js

@@ -197,10 +197,7 @@ export default class DecoupledEditor extends Editor {
 
 						return editor.data.init( initialData );
 					} )
-					.then( () => {
-						editor.fire( 'dataReady' );
-						editor.fire( 'ready' );
-					} )
+					.then( () => editor.fire( 'ready' ) )
 					.then( () => editor )
 			);
 		} );

+ 11 - 28
packages/ckeditor5-editor-decoupled/tests/decouplededitor.js

@@ -70,13 +70,15 @@ describe( 'DecoupledEditor', () => {
 
 			class AsyncDataInit extends Plugin {
 				init() {
-					this.editor.on( 'dataReady', () => spy( 'dataReady' ) );
+					this.editor.data.on( 'ready', () => spy( 'ready' ) );
 
 					this.editor.data.on( 'init', evt => {
 						evt.stop();
 						evt.return = new Promise( resolve => {
 							resolver = () => {
 								spy( 'asyncInit' );
+								// Since we stop `init` event, `data#ready` needs to be fired manually.
+								this.editor.data.fire( 'ready' );
 								resolve();
 							};
 						} );
@@ -88,7 +90,7 @@ describe( 'DecoupledEditor', () => {
 				plugins: [ Paragraph, Bold, AsyncDataInit ]
 			} ).then( editor => {
 				sinon.assert.calledWith( spy.firstCall, 'asyncInit' );
-				sinon.assert.calledWith( spy.secondCall, 'dataReady' );
+				sinon.assert.calledWith( spy.secondCall, 'ready' );
 
 				editor.destroy().then( done );
 			} );
@@ -187,14 +189,13 @@ describe( 'DecoupledEditor', () => {
 					const fired = [];
 
 					function spy( evt ) {
-						fired.push( evt.name );
+						fired.push( `${ evt.name }-${ evt.source.constructor.name.toLowerCase() }` );
 					}
 
 					class EventWatcher extends Plugin {
 						init() {
-							this.editor.on( 'pluginsReady', spy );
 							this.editor.ui.on( 'ready', spy );
-							this.editor.on( 'dataReady', spy );
+							this.editor.data.on( 'ready', spy );
 							this.editor.on( 'ready', spy );
 						}
 					}
@@ -204,29 +205,11 @@ describe( 'DecoupledEditor', () => {
 							plugins: [ EventWatcher ]
 						} )
 						.then( newEditor => {
-							expect( fired ).to.deep.equal( [ 'pluginsReady', 'ready', 'dataReady', 'ready' ] );
-
-							return newEditor.destroy();
-						} );
-				} );
-
-				it( 'fires dataReady once data is loaded', () => {
-					let data;
-
-					class EventWatcher extends Plugin {
-						init() {
-							this.editor.on( 'dataReady', () => {
-								data = this.editor.getData();
-							} );
-						}
-					}
-
-					return DecoupledEditor
-						.create( getElementOrData(), {
-							plugins: [ EventWatcher, Paragraph, Bold ]
-						} )
-						.then( newEditor => {
-							expect( data ).to.equal( '<p><strong>foo</strong> bar</p>' );
+							expect( fired ).to.deep.equal( [
+								'ready-decouplededitorui',
+								'ready-datacontroller',
+								'ready-decouplededitor'
+							] );
 
 							return newEditor.destroy();
 						} );

+ 0 - 1
packages/ckeditor5-editor-decoupled/tests/decouplededitorui.js

@@ -209,7 +209,6 @@ class VirtualDecoupledTestEditor extends VirtualTestEditor {
 				editor.initPlugins()
 					.then( () => {
 						editor.ui.init();
-						editor.fire( 'dataReady' );
 						editor.fire( 'ready' );
 					} )
 					.then( () => editor )