Selaa lähdekoodia

Made the `Watchdog.setDestuctor()` method optional.

Maciej Bukowski 6 vuotta sitten
vanhempi
sitoutus
aea0e5905a

+ 1 - 1
packages/ckeditor5-watchdog/docs/features/watchdog.md

@@ -54,7 +54,7 @@ In other words, your goal is to create a watchdog instance and make the watchdog
 
 
 ### Controlling editor creation and destruction
 ### Controlling editor creation and destruction
 
 
-For more control over the creation and destruction of editor instances, you can use the {@link module:watchdog/watchdog~Watchdog#setCreator `Watchdog#setCreator()`} and {@link module:watchdog/watchdog~Watchdog#setDestructor `Watchdog#setDestructor()`} methods:
+For more control over the creation and destruction of editor instances, you can use the mandatory {@link module:watchdog/watchdog~Watchdog#setCreator `Watchdog#setCreator()`} and the optional {@link module:watchdog/watchdog~Watchdog#setDestructor `Watchdog#setDestructor()`} methods:
 
 
 ```js
 ```js
 // Instantiate the watchdog manually (do not use the for() helper).
 // Instantiate the watchdog manually (do not use the for() helper).

+ 2 - 15
packages/ckeditor5-watchdog/src/watchdog.js

@@ -135,6 +135,7 @@ export default class Watchdog {
 		 * @member {Function} #_destructor
 		 * @member {Function} #_destructor
 		 * @see #setDestructor
 		 * @see #setDestructor
 		 */
 		 */
+		this._destructor = editor => editor.destroy();
 
 
 		/**
 		/**
 		 * The latest saved editor data represented as a root name -> root data object.
 		 * The latest saved editor data represented as a root name -> root data object.
@@ -189,6 +190,7 @@ export default class Watchdog {
 
 
 	/**
 	/**
 	 * Sets the function that is responsible for the editor destruction.
 	 * Sets the function that is responsible for the editor destruction.
+	 * Overrides the default destruction function, which destroys only the editor instance.
 	 * It expects a function that should return a promise or `undefined`.
 	 * It expects a function that should return a promise or `undefined`.
 	 *
 	 *
 	 *		watchdog.setDestructor( editor => editor.destroy() );
 	 *		watchdog.setDestructor( editor => editor.destroy() );
@@ -223,20 +225,6 @@ export default class Watchdog {
 			);
 			);
 		}
 		}
 
 
-		if ( !this._destructor ) {
-			/**
-			 * The watchdog's editor destructor is not defined. Define it by using
-			 * {@link module:watchdog/watchdog~Watchdog#setDestructor `Watchdog#setDestructor()`} or
-			 * the {@link module:watchdog/watchdog~Watchdog.for `Watchdog.for()`} helper.
-			 *
-			 * @error watchdog-destructor-not-defined
-			 */
-			throw new CKEditorError(
-				'watchdog-destructor-not-defined: The watchdog\'s editor destructor is not defined.',
-				null
-			);
-		}
-
 		this._elementOrData = elementOrData;
 		this._elementOrData = elementOrData;
 
 
 		// Clone configuration because it might be shared within multiple watchdog instances. Otherwise,
 		// Clone configuration because it might be shared within multiple watchdog instances. Otherwise,
@@ -473,7 +461,6 @@ export default class Watchdog {
 		const watchdog = new Watchdog( watchdogConfig );
 		const watchdog = new Watchdog( watchdogConfig );
 
 
 		watchdog.setCreator( ( elementOrData, config ) => Editor.create( elementOrData, config ) );
 		watchdog.setCreator( ( elementOrData, config ) => Editor.create( elementOrData, config ) );
-		watchdog.setDestructor( editor => editor.destroy() );
 
 
 		return watchdog;
 		return watchdog;
 	}
 	}