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

Commit

Permalink
Introduce data#ready event.
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames committed Jan 23, 2019
1 parent bf86ffa commit 7bbe8c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 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 @@ -372,6 +378,12 @@ export default class DataController {
return true;
}

/**
* Event fired once data initialisation has finished.
*
* @event ready
*/

/**
* Event fired by decorated {@link #init} method.
* See {@link module:utils/observablemixin~ObservableMixin.decorate} for more information and samples.
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

0 comments on commit 7bbe8c6

Please sign in to comment.