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

Changed `get()` and `getState()` to `getItem()` and `getItemState()`.

Maciej Bukowski 6 лет назад
Родитель
Сommit
b971caa8f8

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

@@ -285,10 +285,10 @@ await watchdog.remove( 'editor1' );
 await watchdog.remove( [ 'editor1', 'editor2', ... ] );
 
 // Getting given item instance.
-const editor1 = watchdog.get( 'editor1' );
+const editor1 = watchdog.getItem( 'editor1' );
 
 // Getting given item state.
-const editor1State = watchdog.getState( 'editor1' );
+const editor1State = watchdog.getItemState( 'editor1' );
 
 // Getting the context state.
 const contextState = watchdog.state;

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

@@ -167,12 +167,12 @@ export default class ContextWatchdog extends Watchdog {
 	/**
 	 * Returns the item instance with the given `itemId`.
 	 *
-	 * 	const editor1 = watchdog.get( 'editor1' );
+	 * 	const editor1 = watchdog.getItem( 'editor1' );
 	 *
 	 * @param {String} itemId The item id.
 	 * @returns {*} The item instance or `undefined` if an item with given id has not been found.
 	 */
-	get( itemId ) {
+	getItem( itemId ) {
 		const watchdog = this._getWatchdog( itemId );
 
 		return watchdog._item;
@@ -181,12 +181,12 @@ 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' );
+	 * 	const editor1State = watchdog.getItemState( 'editor1' );
 	 *
 	 * @param {String} itemId Item id.
 	 * @returns {'initializing'|'ready'|'crashed'|'crashedPermanently'|'destroyed'} The state of the item.
 	 */
-	getState( itemId ) {
+	getItemState( itemId ) {
 		const watchdog = this._getWatchdog( itemId );
 
 		return watchdog.state;
@@ -223,7 +223,7 @@ export default class ContextWatchdog extends Watchdog {
 	 *
 	 * And then the instance can be retrieved using the {@link #get} method:
 	 *
-	 * 	const editor1 = watchdog.get( 'editor1' );
+	 * 	const editor1 = watchdog.getItem( 'editor1' );
 	 *
 	 * Note that this method can be called multiple times, but for performance reasons it's better
 	 * to pass all items together.

+ 26 - 26
packages/ckeditor5-watchdog/tests/contextwatchdog.js

@@ -346,7 +346,7 @@ describe( 'ContextWatchdog', () => {
 			await watchdog.destroy();
 		} );
 
-		it( 'should return the created items instances with ContextWatchdog#get( itemId )', async () => {
+		it( 'should return the created items instances with ContextWatchdog#getItem( itemId )', async () => {
 			watchdog = new ContextWatchdog( Context );
 
 			watchdog.create();
@@ -365,16 +365,16 @@ describe( 'ContextWatchdog', () => {
 				config: {}
 			} ] );
 
-			expect( watchdog.get( 'editor1' ) ).to.be.instanceOf( ClassicTestEditor );
-			expect( watchdog.get( 'editor2' ) ).to.be.instanceOf( ClassicTestEditor );
+			expect( watchdog.getItem( 'editor1' ) ).to.be.instanceOf( ClassicTestEditor );
+			expect( watchdog.getItem( 'editor2' ) ).to.be.instanceOf( ClassicTestEditor );
 
 			await watchdog.remove( 'editor1' );
 
 			expect( () => {
-				watchdog.get( 'editor1' );
+				watchdog.getItem( 'editor1' );
 			} ).to.throw( /Item with the given id was not registered: editor1\./ );
 
-			expect( watchdog.get( 'editor2' ) ).to.be.instanceOf( ClassicTestEditor );
+			expect( watchdog.getItem( 'editor2' ) ).to.be.instanceOf( ClassicTestEditor );
 
 			await watchdog.destroy();
 		} );
@@ -404,7 +404,7 @@ describe( 'ContextWatchdog', () => {
 
 				sinon.assert.calledOnce( restartSpy );
 
-				expect( watchdog.getState( 'editor1' ) ).to.equal( 'ready' );
+				expect( watchdog.getItemState( 'editor1' ) ).to.equal( 'ready' );
 				expect( watchdog.context ).to.not.equal( oldContext );
 
 				await watchdog.destroy();
@@ -426,7 +426,7 @@ describe( 'ContextWatchdog', () => {
 				const oldContext = watchdog.context;
 				const restartSpy = sinon.spy();
 
-				const oldEditor = watchdog.get( 'editor1' );
+				const oldEditor = watchdog.getItem( 'editor1' );
 
 				watchdog.on( 'restart', restartSpy );
 
@@ -438,7 +438,7 @@ describe( 'ContextWatchdog', () => {
 
 				expect( watchdog.context ).to.equal( oldContext );
 
-				expect( watchdog.get( 'editor1' ) ).to.not.equal( oldEditor );
+				expect( watchdog.getItem( 'editor1' ) ).to.not.equal( oldEditor );
 
 				await watchdog.destroy();
 			} );
@@ -464,11 +464,11 @@ describe( 'ContextWatchdog', () => {
 
 				const oldContext = watchdog.context;
 
-				const editorWatchdog1 = watchdog._watchdogs.get( 'editor1' );
-				const editorWatchdog2 = watchdog._watchdogs.get( 'editor2' );
+				const editorWatchdog1 = watchdog._getWatchdog( 'editor1' );
+				const editorWatchdog2 = watchdog._getWatchdog( 'editor2' );
 
-				const oldEditor1 = watchdog.get( 'editor1' );
-				const oldEditor2 = watchdog.get( 'editor2' );
+				const oldEditor1 = watchdog.getItem( 'editor1' );
+				const oldEditor2 = watchdog.getItem( 'editor2' );
 
 				const mainWatchdogRestartSpy = sinon.spy();
 				const editorWatchdog1RestartSpy = sinon.spy();
@@ -487,8 +487,8 @@ describe( 'ContextWatchdog', () => {
 				sinon.assert.notCalled( mainWatchdogRestartSpy );
 				sinon.assert.notCalled( editorWatchdog2RestartSpy );
 
-				expect( watchdog.getState( 'editor1' ) ).to.equal( 'ready' );
-				expect( watchdog.getState( 'editor2' ) ).to.equal( 'ready' );
+				expect( watchdog.getItemState( 'editor1' ) ).to.equal( 'ready' );
+				expect( watchdog.getItemState( 'editor2' ) ).to.equal( 'ready' );
 				expect( watchdog.state ).to.equal( 'ready' );
 
 				expect( oldEditor1 ).to.not.equal( editorWatchdog1.editor );
@@ -518,7 +518,7 @@ describe( 'ContextWatchdog', () => {
 					config: {}
 				} ] );
 
-				const editor1 = watchdog.get( 'editor1' );
+				const editor1 = watchdog.getItem( 'editor1' );
 
 				const removePromise = watchdog.remove( 'editor1' );
 
@@ -527,8 +527,8 @@ describe( 'ContextWatchdog', () => {
 				await waitCycle();
 				await removePromise;
 
-				expect( [ ...watchdog._watchdogs.keys() ] ).to.include( 'editor2' );
-				expect( [ ...watchdog._watchdogs.keys() ] ).to.not.include( 'editor1' );
+				expect( Array.from( watchdog._watchdogs.keys() ) ).to.include( 'editor2' );
+				expect( Array.from( watchdog._watchdogs.keys() ) ).to.not.include( 'editor1' );
 
 				await watchdog.destroy();
 			} );
@@ -552,14 +552,14 @@ describe( 'ContextWatchdog', () => {
 					config: {}
 				} ] );
 
-				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );
-				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );
-				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );
-				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );
+				setTimeout( () => throwCKEditorError( 'foo', watchdog.getItem( 'editor1' ) ) );
+				setTimeout( () => throwCKEditorError( 'foo', watchdog.getItem( 'editor1' ) ) );
+				setTimeout( () => throwCKEditorError( 'foo', watchdog.getItem( 'editor1' ) ) );
+				setTimeout( () => throwCKEditorError( 'foo', watchdog.getItem( 'editor1' ) ) );
 
 				await waitCycle();
 
-				expect( watchdog.getState( 'editor1' ) ).to.equal( 'crashedPermanently' );
+				expect( watchdog.getItemState( 'editor1' ) ).to.equal( 'crashedPermanently' );
 				expect( watchdog.state ).to.equal( 'ready' );
 
 				await watchdog.destroy();
@@ -586,11 +586,11 @@ describe( 'ContextWatchdog', () => {
 							return data.itemId === 'editor1';
 						} ) )
 						.callsFake( () => {
-							expect( watchdog.get( 'editor1' ).state ).to.equal( 'crashed' );
+							expect( watchdog.getItemState( 'editor1' ) ).to.equal( 'crashed' );
 						} )
 				);
 
-				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );
+				setTimeout( () => throwCKEditorError( 'foo', watchdog.getItem( 'editor1' ) ) );
 
 				await waitCycle();
 
@@ -620,11 +620,11 @@ describe( 'ContextWatchdog', () => {
 							return data.itemId === 'editor1';
 						} ) )
 						.callsFake( () => {
-							expect( watchdog.get( 'editor1' ).state ).to.equal( 'ready' );
+							expect( watchdog.getItemState( 'editor1' ) ).to.equal( 'ready' );
 						} )
 				);
 
-				setTimeout( () => throwCKEditorError( 'foo', watchdog.get( 'editor1' ) ) );
+				setTimeout( () => throwCKEditorError( 'foo', watchdog.getItem( 'editor1' ) ) );
 
 				await waitCycle();