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

Commit

Permalink
Docs: Imporved DataController#init error docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Mar 9, 2018
1 parent 7775e00 commit 6c52281
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,20 @@ export default class DataController {
* **Note** This method is {@link module:utils/observablemixin~ObservableMixin#decorate decorated} which is
* used by e.g. collaborative editing plugin that syncs remote data on init.
*
* @fires set
* @fires init
* @param {String} data Input data.
* @param {String} [rootName='main'] Root name.
*/
init( data, rootName = 'main' ) {
if ( this.model.document.version ) {
throw new CKEditorError( 'datacontroller-init-document-data-initialized: Trying to set initial data to initialized document.' );
/**
* Cannot initialize already initialized data. Data should be initialized only once, during
* {@link module:core/editor/editor~Editor} initialization, when there is no content in
* the {@link module:engine/model/document~Document} yet.
*
* @error datacontroller-init-data-already-initialized
*/
throw new CKEditorError( 'datacontroller-init-data-already-initialized: Trying to set initial data to initialized document.' );
}

const modelRoot = this.model.document.getRoot( rootName );
Expand Down
2 changes: 1 addition & 1 deletion tests/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe( 'DataController', () => {
data.init( '<p>Bar</p>' );
} ).to.throw(
CKEditorError,
'datacontroller-init-document-data-initialized: Trying to set initial data to initialized document.'
'datacontroller-init-data-already-initialized: Trying to set initial data to initialized document.'
);
} );

Expand Down

0 comments on commit 6c52281

Please sign in to comment.