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

Rename editor#dataReady event as editor.data#ready #1646

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
18 changes: 17 additions & 1 deletion src/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export default class DataController {
this.upcastDispatcher.on( 'documentFragment', convertToModelFragment(), { priority: 'lowest' } );

this.decorate( 'init' );

// Fire `ready` event when initialisation has completed. Such low level listener gives possibility
// to plug into initialisation pipeline without interrupting the initialisation flow.
this.on( 'init', () => {
this.fire( 'ready' );
}, { priority: 'lowest' } );
}

/**
Expand Down Expand Up @@ -373,7 +379,17 @@ export default class DataController {
}

/**
* Event fired by decorated {@link #init} method.
* Event fired once data initialisation has finished.
*
* @event ready
*/

/**
* Event fired after {@link #init init() method} has been run. It can be {@link #listenTo listened to} to adjust/modify
* the initialisation flow. However, if the `init` event is stopped or prevented, the {@link #event:ready ready event}
* should be fired manually.
*
* The `init` event is fired by decorated {@link #init} method.
* See {@link module:utils/observablemixin~ObservableMixin.decorate} for more information and samples.
*
* @event init
Expand Down
10 changes: 10 additions & 0 deletions tests/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ describe( 'DataController', () => {
sinon.assert.calledWithExactly( spy, sinon.match.any, [ 'foo bar' ] );
} );

it( 'should fire ready event after init', () => {
const spy = sinon.spy();

data.on( 'ready', spy );

data.init( 'foo bar' );

sinon.assert.called( spy );
} );

it( 'should throw an error when document data is already initialized', () => {
data.init( '<p>Foo</p>' );

Expand Down