8
0
Просмотр исходного кода

Swap `restart()` and `create()` methods.

Maciej Bukowski 6 лет назад
Родитель
Сommit
ac72b5b2f6
1 измененных файлов с 36 добавлено и 33 удалено
  1. 36 33
      packages/ckeditor5-watchdog/src/watchdog.js

+ 36 - 33
packages/ckeditor5-watchdog/src/watchdog.js

@@ -75,7 +75,8 @@ export default class Watchdog {
 		this.crashes = [];
 
 		/**
-		 * Crash number limit (default to 3). After the limit is reached the editor is not restarted by the watchdog. This is to prevent an infinite crash loop.
+		 * Crash number limit (default to 3). After the limit is reached the editor is not restarted by the watchdog.
+		 * This is to prevent an infinite crash loop.
 		 *
 		 * @private
 		 * @type {Number}
@@ -186,34 +187,6 @@ export default class Watchdog {
 		this._destructor = destructor;
 	}
 
-	/**
-	 * Restarts the editor instance. This method is also called whenever an editor error occurs.
-	 * It fires the `restart` event.
-	 *
-	 * @fires restart
-	 * @returns {Promise.<module:core/editor/editor~Editor>}
-	 */
-	restart() {
-		this._throttledSave.flush();
-
-		return Promise.resolve()
-			.then( () => this.destroy() )
-			.then( () => {
-				if ( typeof this._elementOrData === 'string' ) {
-					return this.create( this._data, this._config );
-				}
-
-				const updatedConfig = Object.assign( {}, this._config, {
-					initialData: this._data
-				} );
-
-				return this.create( this._elementOrData, updatedConfig );
-			} )
-			.then( () => {
-				this.fire( 'restart' );
-			} );
-	}
-
 	/**
 	 * Creates a watched editor instance using the creator passed to the {@link #setCreator} method or `Watchdog.for` helper.
 	 *
@@ -227,10 +200,11 @@ export default class Watchdog {
 			/**
 			 * @error watchdog-creator-not-defined
 			 *
-			 * The watchdog creator is not defined, define it using `watchdog.setCreator()`.
+			 * The watchdog creator is not defined, define it using `watchdog.setCreator()` or `Watchdog.for` helper.
 			 */
 			throw new CKEditorError(
-				'watchdog-creator-not-defined: The watchdog creator is not defined, define it using `watchdog.setCreator()` or `Watchdog.for` helper.',
+				'watchdog-creator-not-defined: The watchdog creator is not defined, define it using `watchdog.setCreator()` ' +
+				'or `Watchdog.for` helper.',
 				null
 			);
 		}
@@ -239,10 +213,11 @@ export default class Watchdog {
 			/**
 			 * @error watchdog-destructor-not-defined
 			 *
-			 * The watchdog destructor is not defined, define it using `watchdog.setDestructor()`.
+			 * The watchdog destructor is not defined, define it using `watchdog.setDestructor()` or `Watchdog.for` helper.
 			 */
 			throw new CKEditorError(
-				'watchdog-destructor-not-defined: The watchdog destructor is not defined, define it using `watchdog.setDestructor()`',
+				'watchdog-destructor-not-defined: The watchdog destructor is not defined, define it using `watchdog.setDestructor()` ' +
+				'or `Watchdog.for` helper.',
 				null
 			);
 		}
@@ -268,6 +243,34 @@ export default class Watchdog {
 			} );
 	}
 
+	/**
+	 * Restarts the editor instance. This method is also called whenever an editor error occurs.
+	 * It fires the `restart` event.
+	 *
+	 * @fires restart
+	 * @returns {Promise.<module:core/editor/editor~Editor>}
+	 */
+	restart() {
+		this._throttledSave.flush();
+
+		return Promise.resolve()
+			.then( () => this.destroy() )
+			.then( () => {
+				if ( typeof this._elementOrData === 'string' ) {
+					return this.create( this._data, this._config );
+				}
+
+				const updatedConfig = Object.assign( {}, this._config, {
+					initialData: this._data
+				} );
+
+				return this.create( this._elementOrData, updatedConfig );
+			} )
+			.then( () => {
+				this.fire( 'restart' );
+			} );
+	}
+
 	/**
 	 * Destroys the current editor using the destructor passed to {@link #setDestructor} method.
 	 *