Browse Source

Removed excess typechecks.

Piotrek Koszuliński 10 years ago
parent
commit
ad7785390d

+ 46 - 107
packages/ckeditor5-engine/src/ui/controller.js

@@ -55,9 +55,10 @@ CKEDITOR.define( [
 
 		/**
 		 * Initializes the controller instance. The process includes:
-		 *  1. Initialization of the child {@link #view}.
-		 *  2. Initialization of child controllers in {@link #collections}.
-		 *  3. Setting {@link #ready} flag `true`.
+		 *
+		 * 1. Initialization of the child {@link #view}.
+		 * 2. Initialization of child controllers in {@link #collections}.
+		 * 3. Setting {@link #ready} flag `true`.
 		 *
 		 * @returns {Promise} A Promise resolved when the initialization process is finished.
 		 */
@@ -79,45 +80,6 @@ CKEDITOR.define( [
 				} );
 		}
 
-		/**
-		 * Initializes the {@link #view} of this controller instance.
-		 *
-		 * @protected
-		 * @returns {Promise} A Promise resolved when initialization process is finished.
-		 */
-		_initView() {
-			let promise = Promise.resolve();
-
-			if ( this.view ) {
-				promise = promise.then( this.view.init.bind( this.view ) );
-			}
-
-			return promise;
-		}
-
-		/**
-		 * Initializes the {@link #collections} of this controller instance.
-		 *
-		 * @protected
-		 * @returns {Promise} A Promise resolved when initialization process is finished.
-		 */
-		_initCollections() {
-			const promises = [];
-			let collection, childController;
-
-			for ( collection of this.collections ) {
-				for ( childController of collection ) {
-					if ( this.view, childController.view ) {
-						this.view.addChild( collection.name, childController.view );
-					}
-
-					promises.push( childController.init() );
-				}
-			}
-
-			return Promise.all( promises );
-		}
-
 		/**
 		 * Adds a child controller to one of the {@link #collections}.
 		 * If this controller instance is ready, the child view will be initialized when added.
@@ -130,35 +92,8 @@ CKEDITOR.define( [
 		 * @returns {Promise} A Promise resolved when the child is added.
 		 */
 		addChild( collectionName, childController, index ) {
-			if ( !collectionName ) {
-				/**
-				 * The name of the collection is required.
-				 *
-				 * @error ui-controller-addchild-badcname
-				 */
-				throw new CKEditorError( 'ui-controller-addchild-badcname' );
-			}
-
 			const collection = this.collections.get( collectionName );
 
-			if ( !collection ) {
-				/**
-				 * There is no collection of given name.
-				 *
-				 * @error ui-controller-addchild-nocol
-				 */
-				throw new CKEditorError( 'ui-controller-addchild-nocol' );
-			}
-
-			if ( !childController ) {
-				/**
-				 * Passed no controller.
-				 *
-				 * @error ui-controller-addchild-no-controller
-				 */
-				throw new CKEditorError( 'ui-controller-addchild-no-controller' );
-			}
-
 			// ChildController.init() returns Promise.
 			let promise = Promise.resolve();
 
@@ -189,35 +124,8 @@ CKEDITOR.define( [
 		 * @returns {Controller} A child controller instance after removal.
 		 */
 		removeChild( collectionName, childController ) {
-			if ( !collectionName ) {
-				/**
-				 * Collection name is required.
-				 *
-				 * @error ui-controller-removechild-badcname
-				 */
-				throw new CKEditorError( 'ui-controller-removechild-badcname' );
-			}
-
 			const collection = this.collections.get( collectionName );
 
-			if ( !collection ) {
-				/**
-				 * There's no collection of given name.
-				 *
-				 * @error ui-controller-removechild-nocol
-				 */
-				throw new CKEditorError( 'ui-controller-removechild-nocol' );
-			}
-
-			if ( !childController ) {
-				/**
-				 * Passed no controller.
-				 *
-				 * @error ui-controller-removechild-no-controller
-				 */
-				throw new CKEditorError( 'ui-controller-removechild-no-controller' );
-			}
-
 			collection.remove( childController );
 
 			if ( this.ready && childController.view ) {
@@ -237,22 +145,14 @@ CKEDITOR.define( [
 		getChild( collectionName, index ) {
 			const collection = this.collections.get( collectionName );
 
-			if ( !collection ) {
-				/**
-				 * There's no collection of such name.
-				 *
-				 * @error ui-controller-getchild-nocol
-				 */
-				throw new CKEditorError( 'ui-controller-getchild-nocol' );
-			}
-
 			return collection.get( index );
 		}
 
 		/**
 		 * Destroys the controller instance. The process includes:
-		 *  1. Destruction of the child {@link #view}.
-		 *  2. Destruction of child controllers in {@link #collections}.
+		 *
+		 * 1. Destruction of the child {@link #view}.
+		 * 2. Destruction of child controllers in {@link #collections}.
 		 *
 		 * @returns {Promise} A Promise resolved when the destruction process is finished.
 		 */
@@ -286,6 +186,45 @@ CKEDITOR.define( [
 
 			return Promise.all( promises );
 		}
+
+		/**
+		 * Initializes the {@link #view} of this controller instance.
+		 *
+		 * @protected
+		 * @returns {Promise} A Promise resolved when initialization process is finished.
+		 */
+		_initView() {
+			let promise = Promise.resolve();
+
+			if ( this.view ) {
+				promise = promise.then( this.view.init.bind( this.view ) );
+			}
+
+			return promise;
+		}
+
+		/**
+		 * Initializes the {@link #collections} of this controller instance.
+		 *
+		 * @protected
+		 * @returns {Promise} A Promise resolved when initialization process is finished.
+		 */
+		_initCollections() {
+			const promises = [];
+			let collection, childController;
+
+			for ( collection of this.collections ) {
+				for ( childController of collection ) {
+					if ( this.view, childController.view ) {
+						this.view.addChild( collection.name, childController.view );
+					}
+
+					promises.push( childController.init() );
+				}
+			}
+
+			return Promise.all( promises );
+		}
 	}
 
 	return Controller;

+ 0 - 70
packages/ckeditor5-engine/tests/ui/controller.js

@@ -105,36 +105,6 @@ describe( 'Controller', () => {
 	describe( 'addChild', () => {
 		beforeEach( defineParentViewClass );
 
-		it( 'should throw when no collection name', () => {
-			const controller = new Controller();
-
-			controller.collections.add( new ControllerCollection( 'x' ) );
-
-			expect( () => {
-				controller.addChild();
-			} ).to.throw( CKEditorError, /ui-controller-addchild-badcname/ );
-		} );
-
-		it( 'should throw when collection of given name does not exist', () => {
-			const controller = new Controller();
-
-			controller.collections.add( new ControllerCollection( 'x' ) );
-
-			expect( () => {
-				controller.addChild( 'y', new Controller() );
-			} ).to.throw( CKEditorError, /ui-controller-addchild-nocol/ );
-		} );
-
-		it( 'should throw when no controller is passed', () => {
-			const controller = new Controller();
-
-			controller.collections.add( new ControllerCollection( 'x' ) );
-
-			expect( () => {
-				controller.addChild( 'x' );
-			} ).to.throw( CKEditorError, /ui-controller-addchild-no-controller/ );
-		} );
-
 		it( 'should add a child controller to given collection and return promise', () => {
 			const parentController = new Controller();
 			const childController = new Controller();
@@ -267,36 +237,6 @@ describe( 'Controller', () => {
 	describe( 'removeChild', () => {
 		beforeEach( defineParentViewClass );
 
-		it( 'should throw when no collection name', () => {
-			const controller = new Controller();
-
-			controller.collections.add( new ControllerCollection( 'x' ) );
-
-			expect( () => {
-				controller.removeChild();
-			} ).to.throw( CKEditorError, /ui-controller-removechild-badcname/ );
-		} );
-
-		it( 'should throw when collection of given name does not exist', () => {
-			const controller = new Controller();
-
-			controller.collections.add( new ControllerCollection( 'x' ) );
-
-			expect( () => {
-				controller.removeChild( 'y' );
-			} ).to.throw( CKEditorError, /ui-controller-removechild-nocol/ );
-		} );
-
-		it( 'should throw when controller or wrong controller is passed', () => {
-			const controller = new Controller();
-
-			controller.collections.add( new ControllerCollection( 'x' ) );
-
-			expect( () => {
-				controller.removeChild( 'x' );
-			} ).to.throw( CKEditorError, /ui-controller-removechild-no-controller/ );
-		} );
-
 		it( 'should remove child controller and return it', () => {
 			const parentController = new Controller();
 			const childController = new Controller();
@@ -335,16 +275,6 @@ describe( 'Controller', () => {
 	describe( 'getChild', () => {
 		beforeEach( defineParentViewClass );
 
-		it( 'should throw when collection of given name does not exist', () => {
-			const controller = new Controller();
-
-			controller.collections.add( new ControllerCollection( 'x' ) );
-
-			expect( () => {
-				controller.getChild( 'y', 0 );
-			} ).to.throw( CKEditorError, /ui-controller-getchild-nocol/ );
-		} );
-
 		it( 'should get child controller by index', () => {
 			const parentController = new Controller();
 			const childController = new Controller();