浏览代码

Simplified part of code which logs about loaded duplicated plugins.

Kamil Piechaczek 8 年之前
父节点
当前提交
f7638055c6
共有 2 个文件被更改,包括 9 次插入43 次删除
  1. 9 27
      packages/ckeditor5-core/src/plugincollection.js
  2. 0 16
      packages/ckeditor5-core/tests/plugincollection.js

+ 9 - 27
packages/ckeditor5-core/src/plugincollection.js

@@ -45,25 +45,11 @@ export default class PluginCollection {
 		 */
 		this._plugins = new Map();
 
-		/**
-		 * Set of plugins' names. Used to detect whether tries to load a plugin with the same name.
-		 *
-		 * @protected
-		 * @type {Set} module:core/plugin~PluginCollection#_loadedPluginNames
-		 */
-		this._loadedPluginNames = new Set();
-
 		for ( const PluginConstructor of availablePlugins ) {
 			this._availablePlugins.set( PluginConstructor, PluginConstructor );
 
-			const pluginName = PluginConstructor.pluginName;
-
-			if ( pluginName ) {
-				if ( this._availablePlugins.has( pluginName ) ) {
-					log.warn( `Plugin "${ pluginName }" is already defined. Skipping.` );
-				} else {
-					this._availablePlugins.set( pluginName, PluginConstructor );
-				}
+			if ( PluginConstructor.pluginName ) {
+				this._availablePlugins.set( PluginConstructor.pluginName, PluginConstructor );
 			}
 		}
 	}
@@ -145,12 +131,6 @@ export default class PluginCollection {
 				return;
 			}
 
-			const pluginName = PluginConstructor.pluginName;
-
-			if ( pluginName && that._loadedPluginNames.has( pluginName ) ) {
-				log.warn( `Plugin "${ pluginName }" is already loaded. You should not load more than one plugin with the same name.` );
-			}
-
 			return instantiatePlugin( PluginConstructor )
 				.catch( err => {
 					/**
@@ -169,10 +149,6 @@ export default class PluginCollection {
 			return new Promise( resolve => {
 				loading.add( PluginConstructor );
 
-				if ( PluginConstructor.pluginName ) {
-					that._loadedPluginNames.add( PluginConstructor.pluginName );
-				}
-
 				if ( PluginConstructor.requires ) {
 					PluginConstructor.requires.forEach( RequiredPluginConstructorOrName => {
 						const RequiredPluginConstructor = getPluginConstructor( RequiredPluginConstructorOrName );
@@ -257,7 +233,13 @@ export default class PluginCollection {
 
 		const pluginName = PluginConstructor.pluginName;
 
-		if ( pluginName && !this._plugins.has( pluginName ) ) {
+		if ( !pluginName ) {
+			return;
+		}
+
+		if ( this._plugins.has( pluginName ) ) {
+			log.warn( `Plugin "${ pluginName }" is already loaded. You should not load more than one plugin with the same name.` );
+		} else {
 			this._plugins.set( pluginName, plugin );
 		}
 	}

+ 0 - 16
packages/ckeditor5-core/tests/plugincollection.js

@@ -73,22 +73,6 @@ describe( 'PluginCollection', () => {
 		PluginFoo.requires = [];
 	} );
 
-	describe( 'constructor()', () => {
-		it( 'logs if passed an array that contains plugins with duplicated names as available plugins', () => {
-			availablePlugins = [ PluginFoo, AnotherPluginFoo ];
-
-			const logSpy = testUtils.sinon.stub( log, 'warn' );
-			const plugins = new PluginCollection( editor, availablePlugins );
-
-			expect( logSpy.firstCall.args[ 0 ] ).to.equal( 'Plugin "Foo" is already defined. Skipping.' );
-
-			expect( plugins._availablePlugins.size ).to.equal( 3 );
-			expect( plugins._availablePlugins.get( 'Foo' ) ).to.equal( PluginFoo );
-			expect( plugins._availablePlugins.get( PluginFoo ) ).to.equal( PluginFoo );
-			expect( plugins._availablePlugins.get( AnotherPluginFoo ) ).to.equal( AnotherPluginFoo );
-		} );
-	} );
-
 	describe( 'load()', () => {
 		it( 'should not fail when trying to load 0 plugins (empty array)', () => {
 			const plugins = new PluginCollection( editor, availablePlugins );