浏览代码

Added more code samples.

Maciej Bukowski 5 年之前
父节点
当前提交
2a60cf73cb

+ 11 - 9
packages/ckeditor5-watchdog/docs/features/watchdog.md

@@ -186,10 +186,12 @@ await watchdog.add( [ {
 } ] );
 ```
 
-The Watchdog will keep the context and editor instances running
-that are added via the {@link module:watchdog/contextwatchdog~ContextWatchdog#add `ContextWatchdog#add` method}. This method can be called multiple times during the `ContextWatchdog` lifetime.
+<info-box>
+	The Watchdog will keep the context and item instances running
+	that are added via the {@link module:watchdog/contextwatchdog~ContextWatchdog#add `ContextWatchdog#add` method}. This method can be called multiple times during the `ContextWatchdog` lifetime.
 
-To destroy one of the editor instances use the {@link module:watchdog/contextwatchdog~ContextWatchdog#remove `ContextWatchdog#remove` method}. This method can be called multiple times during the `ContextWatchdog` lifetime as well.
+	To destroy one of the item instances use the {@link module:watchdog/contextwatchdog~ContextWatchdog#remove `ContextWatchdog#remove` method}. This method can be called multiple times during the `ContextWatchdog` lifetime as well.
+</info-box>
 
 ```js
 await watchdog.remove( [ 'editor1', 'editor2' ] );
@@ -201,7 +203,7 @@ await watchdog.remove( 'editor2' );
 
 <info-box>
 	Examples presents the "synchronous way" of the integration with the context watchdog feature, however it's not needed to wait for the promises returned by the `create()`, `add()` and `remove()` methods. There might be a need
-	to create and destroy editors dynamically with shared context and that's can be easily achieved as all promises operating on the internal API will be chained.
+	to create and destroy items dynamically with shared context and that's can be easily achieved as all promises operating on the internal API will be chained.
 </info-box>
 
 #### Context watchdog API
@@ -231,7 +233,7 @@ watchdog.setDestructor( async context => {
 // Initializing the context watchdog with the context configuration.
 await watchdog.create( contextConfig );
 
-// Adding editor configuration (or an array of editor configurations).
+// Adding item configuration (or an array of item configurations).
 await watchdog.add( {
 	id: 'editor1',
 	type: 'editor',
@@ -241,7 +243,7 @@ await watchdog.add( {
 	destructor: destroyEditor,
 } );
 
-// Removing and destroy given editor.
+// Removing and destroy given item.
 await watchdog.remove( [ 'editor1' ] );
 
 // Getting given item instance.
@@ -254,11 +256,11 @@ const editor1State = watchdog.getState( 'editor1' );
 const contextState = watchdog.state;
 
 // Listening to an event fired when the context watchdog catches the context-related error.
-// Note that the editor errors are not re-fired in the `ContextWatchdog#error`.
+// Note that the item errors are not re-fired in the `ContextWatchdog#error`.
 watchdog.on( 'error', () => {} );
 
 // Listening to an event fired when the context is set back to the `ready` state (after it was in `error` state).
-// Similarly, this event is not thrown for internal editor instances.
+// Similarly, this event is not thrown for internal item restarts.
 watchdog.on( 'restart', () => {} );
 ```
 
@@ -279,7 +281,7 @@ const editorWatchdog = new EditorWatchdog( ClassicEditor, {
 ```
 
 <info-box>
-	Note that the context watchdog passes this configuration to the added editors.
+	Note that the context watchdog passes its configuration to the added editors.
 </info-box>
 
 ## Limitations

+ 18 - 4
packages/ckeditor5-watchdog/src/contextwatchdog.js

@@ -24,11 +24,11 @@ export default class ContextWatchdog extends Watchdog {
 	/**
 	 * The `ContextWatchdog` class constructor.
 	 *
-	 * 	const contextWatchdog = new ContextWatchdog( Context );
+	 * 	const watchdog = new ContextWatchdog( Context );
 	 *
-	 * 	await contextWatchdog.create( contextConfiguration );
+	 * 	await watchdog.create( contextConfiguration );
 	 *
-	 * 	await contextWatchdog.add( watchdogItem );
+	 * 	await watchdog.add( item );
 	 *
 	 * See {@glink features/watchdog the watchdog feature guide} to learn more how to use this feature.
 	 *
@@ -147,6 +147,10 @@ export default class ContextWatchdog extends Watchdog {
 	 * Initializes the context watchdog. Once it's created the watchdog takes care about
 	 * recreating the context and provided items and starts the error handling mechanism.
 	 *
+	 * 	await watchdog.create( {
+	 * 		plugins: []
+	 * 	} );
+	 *
 	 * @param {Object} [contextConfig] Context configuration. See {@link module:core/context~Context}.
 	 * @returns {Promise}
 	 */
@@ -161,7 +165,7 @@ export default class ContextWatchdog extends Watchdog {
 	/**
      * Returns the item instance with the given `itemId`.
 	 *
-	 * 	const editor1 = contextWatchdog.get( 'editor1' );
+	 * 	const editor1 = watchdog.get( 'editor1' );
 	 *
 	 * @param {String} itemId The item id.
 	 * @returns {*} The item instance or `undefined` if an item with given id has not been found.
@@ -175,6 +179,8 @@ export default class ContextWatchdog extends Watchdog {
 	/**
 	 * Gets state of the given item. For the list of available states see {@link #state}.
 	 *
+	 * 	const editor1State = watchdog.getState( 'editor1' );
+	 *
 	 * @param {String} itemId Item id.
 	 * @returns {'initializing'|'ready'|'crashed'|'crashedPermanently'|'destroyed'} The state of the item.
 	 */
@@ -277,6 +283,12 @@ export default class ContextWatchdog extends Watchdog {
 	/**
 	 * Removes and destroys item(s) with given id(s).
 	 *
+	 * 	await watchdog.remove( 'editor1' );
+	 *
+	 * Or
+	 *
+	 * 	await watchdog.remove( [ 'editor1', 'editor2' ] );
+	 *
 	 * @param {Array.<String>|String} itemIdOrItemIds Item id or an array of item ids.
 	 * @returns {Promise}
 	 */
@@ -300,6 +312,8 @@ export default class ContextWatchdog extends Watchdog {
 	 * Destroys the `ContextWatchdog` and all added items.
 	 * Once the `ContextWatchdog` is destroyed new items can not be added.
 	 *
+	 * 	await watchdog.destroy();
+	 *
 	 * @returns {Promise}
 	 */
 	destroy() {