Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Changed the way of updating Editor#state.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Jun 27, 2018
1 parent b3dfcd8 commit 4beced2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -287,7 +288,6 @@ export default class Editor {
editor.initPlugins()
.then( () => {
editor.fire( 'dataReady' );
editor.state = 'ready';
editor.fire( 'ready' );
} )
.then( () => editor )
Expand Down
26 changes: 26 additions & 0 deletions tests/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 4beced2

Please sign in to comment.