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

Commit

Permalink
Merge pull request #26 from ckeditor/t/ckeditor5/1477
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Piotr Jasiun authored Jan 29, 2019
2 parents 2b861b9 + 9c72a3f commit 3bb0e40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
5 changes: 1 addition & 4 deletions src/decouplededitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
);
} );
Expand Down
39 changes: 11 additions & 28 deletions tests/decouplededitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
} );
Expand All @@ -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 );
} );
Expand Down Expand Up @@ -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 );
}
}
Expand All @@ -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();
} );
Expand Down
1 change: 0 additions & 1 deletion tests/decouplededitorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ class VirtualDecoupledTestEditor extends VirtualTestEditor {
editor.initPlugins()
.then( () => {
editor.ui.init();
editor.fire( 'dataReady' );
editor.fire( 'ready' );
} )
.then( () => editor )
Expand Down

0 comments on commit 3bb0e40

Please sign in to comment.