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

Commit 46d9243

Browse files
author
Piotr Jasiun
authored
Merge pull request #1646 from ckeditor/t/ckeditor5/1477
Other: Introduced `editor.data#ready` event. BREAKING CHANGE: The `editor#dataReady` event was removed. The `editor.data#ready` event has been introduced and should be used instead.
2 parents df8a777 + 039af53 commit 46d9243

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/controller/datacontroller.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ export default class DataController {
103103
this.upcastDispatcher.on( 'documentFragment', convertToModelFragment(), { priority: 'lowest' } );
104104

105105
this.decorate( 'init' );
106+
107+
// Fire `ready` event when initialisation has completed. Such low level listener gives possibility
108+
// to plug into initialisation pipeline without interrupting the initialisation flow.
109+
this.on( 'init', () => {
110+
this.fire( 'ready' );
111+
}, { priority: 'lowest' } );
106112
}
107113

108114
/**
@@ -373,7 +379,17 @@ export default class DataController {
373379
}
374380

375381
/**
376-
* Event fired by decorated {@link #init} method.
382+
* Event fired once data initialisation has finished.
383+
*
384+
* @event ready
385+
*/
386+
387+
/**
388+
* Event fired after {@link #init init() method} has been run. It can be {@link #listenTo listened to} to adjust/modify
389+
* the initialisation flow. However, if the `init` event is stopped or prevented, the {@link #event:ready ready event}
390+
* should be fired manually.
391+
*
392+
* The `init` event is fired by decorated {@link #init} method.
377393
* See {@link module:utils/observablemixin~ObservableMixin.decorate} for more information and samples.
378394
*
379395
* @event init

tests/controller/datacontroller.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ describe( 'DataController', () => {
160160
sinon.assert.calledWithExactly( spy, sinon.match.any, [ 'foo bar' ] );
161161
} );
162162

163+
it( 'should fire ready event after init', () => {
164+
const spy = sinon.spy();
165+
166+
data.on( 'ready', spy );
167+
168+
data.init( 'foo bar' );
169+
170+
sinon.assert.called( spy );
171+
} );
172+
163173
it( 'should throw an error when document data is already initialized', () => {
164174
data.init( '<p>Foo</p>' );
165175

0 commit comments

Comments
 (0)