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

Adjustments to new data#ready event #26

Merged
merged 4 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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