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

Commit f4e496d

Browse files
author
Piotr Jasiun
authored
Merge pull request #14 from ckeditor/t/13
Fix: Added missing return to the data initialization step. Closes #13.
2 parents 5bdc338 + 1bb57bd commit f4e496d

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/decouplededitor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export default class DecoupledEditor extends Editor {
196196
editor.fire( 'uiReady' );
197197
} )
198198
.then( () => {
199-
editor.data.init( editor.element ? getDataFromElement( editor.element ) : elementOrData );
199+
return editor.data.init( editor.element ? getDataFromElement( editor.element ) : elementOrData );
200200
} )
201201
.then( () => {
202202
editor.fire( 'dataReady' );

tests/decouplededitor.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* For licensing, see LICENSE.md.
44
*/
55

6-
/* globals document */
6+
/* globals document, setTimeout */
77

88
import DecoupledEditorUI from '../src/decouplededitorui';
99
import DecoupledEditorUIView from '../src/decouplededitoruiview';
@@ -57,6 +57,39 @@ describe( 'DecoupledEditor', () => {
5757
} );
5858

5959
describe( 'create()', () => {
60+
it( 'should properly handled async data initialization', done => {
61+
const spy = sinon.spy();
62+
let resolver;
63+
64+
class AsyncDataInit extends Plugin {
65+
init() {
66+
this.editor.on( 'dataReady', () => spy( 'dataReady' ) );
67+
68+
this.editor.data.on( 'init', evt => {
69+
evt.stop();
70+
evt.return = new Promise( resolve => {
71+
resolver = () => {
72+
spy( 'asyncInit' );
73+
resolve();
74+
};
75+
} );
76+
}, { priority: 'high' } );
77+
}
78+
}
79+
80+
DecoupledEditor.create( '<p>foo bar</p>', {
81+
plugins: [ Paragraph, Bold, AsyncDataInit ]
82+
} ).then( editor => {
83+
sinon.assert.calledWith( spy.firstCall, 'asyncInit' );
84+
sinon.assert.calledWith( spy.secondCall, 'dataReady' );
85+
86+
editor.destroy().then( done );
87+
} );
88+
89+
// Resolve init promise in next cycle to hold data initialization.
90+
setTimeout( () => resolver() );
91+
} );
92+
6093
describe( 'editor with data', () => {
6194
test( () => editorData );
6295
} );

0 commit comments

Comments
 (0)