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

Allowed overriding existing components when adding new ones to the component factory.

Aleksander Nowodzinski 5 лет назад
Родитель
Сommit
bafb120ff8

+ 0 - 14
packages/ckeditor5-ui/src/componentfactory.js

@@ -77,20 +77,6 @@ export default class ComponentFactory {
 	 * @param {Function} callback The callback that returns the component.
 	 */
 	add( name, callback ) {
-		if ( this.has( name ) ) {
-			/**
-			 * The item already exists in the component factory.
-			 *
-			 * @error componentfactory-item-exists
-			 * @param {String} name The name of the component.
-			 */
-			throw new CKEditorError(
-				'componentfactory-item-exists: The item already exists in the component factory.',
-				this,
-				{ name }
-			);
-		}
-
 		this._components.set( getNormalized( name ), { callback, originalName: name } );
 	}
 

+ 11 - 13
packages/ckeditor5-ui/tests/componentfactory.js

@@ -39,26 +39,24 @@ describe( 'ComponentFactory', () => {
 	} );
 
 	describe( 'add()', () => {
-		it( 'throws when trying to override already registered component', () => {
-			factory.add( 'foo', () => {} );
+		it( 'does not normalize component names', () => {
+			factory.add( 'FoO', () => {} );
 
-			expectToThrowCKEditorError( () => {
-				factory.add( 'foo', () => {} );
-			}, /^componentfactory-item-exists/, editor );
+			expect( Array.from( factory.names() ) ).to.have.members( [ 'FoO' ] );
 		} );
 
-		it( 'throws when trying to override already registered component added with different case', () => {
-			factory.add( 'Foo', () => {} );
+		it( 'should allow overriding already registered components', () => {
+			factory.add( 'foo', () => 'old' );
+			factory.add( 'foo', () => 'new' );
 
-			expectToThrowCKEditorError( () => {
-				factory.add( 'foo', () => {} );
-			}, /^componentfactory-item-exists/, editor );
+			expect( factory.create( 'foo' ) ).to.equal( 'new' );
 		} );
 
-		it( 'does not normalize component names', () => {
-			factory.add( 'FoO', () => {} );
+		it( 'should allow overriding already registered components (same name, different case)', () => {
+			factory.add( 'foo', () => 'old' );
+			factory.add( 'Foo', () => 'new' );
 
-			expect( Array.from( factory.names() ) ).to.have.members( [ 'FoO' ] );
+			expect( factory.create( 'foo' ) ).to.equal( 'new' );
 		} );
 	} );