Преглед изворни кода

Merge branch 'master' into t/ckeditor5/479

Aleksander Nowodzinski пре 7 година
родитељ
комит
fe0dda40b7

+ 17 - 1
packages/ckeditor5-engine/src/controller/datacontroller.js

@@ -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' } );
 	}
 
 	/**
@@ -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

+ 4 - 4
packages/ckeditor5-engine/src/conversion/conversion.js

@@ -15,7 +15,7 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  * We recommend reading the {@glink framework/guides/architecture/editing-engine Editing engine architecture} guide first to
  * understand the core concepts of the conversion mechanisms.
  *
- * The instance of the conversion manager is available in the
+ * An instance of the conversion manager is available in the
  * {@link module:core/editor/editor~Editor#conversion `editor.conversion`} property
  * and by default has the following groups of dispatchers (i.e. directions of conversion):
  *
@@ -79,11 +79,11 @@ export default class Conversion {
 	register( name, conversionHelpers ) {
 		if ( this._conversionHelpers.has( name ) ) {
 			/**
-			 * Trying to register a group name that was already registered.
+			 * Trying to register a group name that has already been registered.
 			 *
 			 * @error conversion-register-group-exists
 			 */
-			throw new CKEditorError( 'conversion-register-group-exists: Trying to register a group name that was already registered.' );
+			throw new CKEditorError( 'conversion-register-group-exists: Trying to register a group name that has already been registered.' );
 		}
 
 		this._conversionHelpers.set( name, conversionHelpers );
@@ -610,7 +610,7 @@ function* _getUpcastDefinition( model, view, upcastAlso ) {
  */
 export class ConversionHelpers {
 	/**
-	 * Creates `ConversionHelpers` instance.
+	 * Creates a conversion helpers instance.
 	 *
 	 * @param {Array.<module:engine/conversion/downcastdispatcher~DowncastDispatcher|
 	 * module:engine/conversion/upcastdispatcher~UpcastDispatcher>} dispatcher

+ 10 - 0
packages/ckeditor5-engine/tests/controller/datacontroller.js

@@ -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>' );