Browse Source

Improved watchdog destruction and watchdog options inheritance.

Maciej Bukowski 5 years ago
parent
commit
72e72a2d69

+ 12 - 3
packages/ckeditor5-watchdog/src/contextwatchdog.js

@@ -25,7 +25,7 @@ export default class ContextWatchdog extends Watchdog {
 	 * The constructor should not be called directly. Use the {@link module:watchdog/contextwatchdog~ContextWatchdog.for} method instead.
 	 *
 	 * @param {Object} [contextConfig] {@link module:core/context~Context} configuration.
-	 * @param {module:watchdog/watchdog~WatchdogConfig} [watchdogConfig] The watchdog plugin configuration.
+	 * @param {module:watchdog/watchdog~WatchdogConfig} [watchdogConfig] The watchdog configuration.
 	 */
 	constructor( contextConfig = {}, watchdogConfig = {} ) {
 		super( watchdogConfig );
@@ -39,6 +39,14 @@ export default class ContextWatchdog extends Watchdog {
 		this._watchdogs = new Map();
 
 		/**
+		 * The watchdog configuration.
+		 *
+		 * @private
+		 * @type {module:watchdog/watchdog~WatchdogConfig}
+		 */
+		this._watchdogConfig = watchdogConfig;
+
+		/**
 		 * The current context instance.
 		 *
 		 * @private
@@ -168,8 +176,7 @@ export default class ContextWatchdog extends Watchdog {
 				}
 
 				if ( item.type === 'editor' ) {
-					// TODO - await EditorWatchdog.createFrom( item, context ) ?
-					watchdog = new EditorWatchdog();
+					watchdog = new EditorWatchdog( this._watchdogConfig );
 					watchdog.setCreator( item.creator );
 					watchdog._setExcludedProperties( this._contextProps );
 
@@ -249,6 +256,8 @@ export default class ContextWatchdog extends Watchdog {
 		return this._actionQueue.enqueue( () => {
 			this.state = 'destroyed';
 
+			super.destroy();
+
 			return this._destroy();
 		} );
 	}

+ 2 - 0
packages/ckeditor5-watchdog/src/editorwatchdog.js

@@ -220,6 +220,8 @@ export default class EditorWatchdog extends Watchdog {
 			.then( () => {
 				this.state = 'destroyed';
 
+				super.destroy();
+
 				return this._destroy();
 			} );
 	}

+ 5 - 0
packages/ckeditor5-watchdog/src/watchdog.js

@@ -165,6 +165,11 @@ export default class Watchdog {
 		this._destructor = destructor;
 	}
 
+	destroy() {
+		this._stopErrorHandling();
+		this.stopListening();
+	}
+
 	/**
 	 * Starts error handling by attaching global error handlers.
 	 *