Sfoglia il codice sorgente

Changed the way of updating Editor#state.

Oskar Wróbel 7 anni fa
parent
commit
a2e21501b3

+ 2 - 2
packages/ckeditor5-core/src/editor/editor.js

@@ -119,6 +119,8 @@ export default class Editor {
 		 * @member {'initializing'|'ready'|'destroyed'} #state
 		 */
 		this.set( 'state', 'initializing' );
+		this.once( 'ready', () => ( this.state = 'ready' ), { priority: 'high' } );
+		this.once( 'destroy', () => ( this.state = 'destroyed' ), { priority: 'high' } );
 
 		/**
 		 * Defines whether this editor is in read-only mode.
@@ -241,7 +243,6 @@ export default class Editor {
 	 * @returns {Promise} A promise that resolves once the editor instance is fully destroyed.
 	 */
 	destroy() {
-		this.state = 'destroyed';
 		this.fire( 'destroy' );
 
 		this.stopListening();
@@ -287,7 +288,6 @@ export default class Editor {
 				editor.initPlugins()
 					.then( () => {
 						editor.fire( 'dataReady' );
-						editor.state = 'ready';
 						editor.fire( 'ready' );
 					} )
 					.then( () => editor )

+ 26 - 0
packages/ckeditor5-core/tests/editor/editor.js

@@ -214,6 +214,32 @@ describe( 'Editor', () => {
 
 			sinon.assert.calledOnce( spy );
 		} );
+
+		it( 'reacts on #ready event', done => {
+			const editor = new Editor();
+
+			expect( editor.state ).to.equal( 'initializing' );
+
+			editor.on( 'ready', () => {
+				expect( editor.state ).to.equal( 'ready' );
+				done();
+			} );
+
+			editor.fire( 'ready' );
+		} );
+
+		it( 'reacts on #destroy event', done => {
+			const editor = new Editor();
+
+			expect( editor.state ).to.equal( 'initializing' );
+
+			editor.on( 'destroy', () => {
+				expect( editor.state ).to.equal( 'destroyed' );
+				done();
+			} );
+
+			editor.fire( 'destroy' );
+		} );
 	} );
 
 	describe( 'isReadOnly', () => {