浏览代码

Fix: Name of plugins are optional.

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

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

@@ -41,8 +41,12 @@ export default class PluginCollection {
 		this._plugins = new Map();
 
 		// Save available plugins.
-		for ( const plugin of availablePlugins ) {
-			this._availablePlugins.set( plugin.pluginName, plugin );
+		for ( const PluginConstructor of availablePlugins ) {
+			this._availablePlugins.set( PluginConstructor, PluginConstructor );
+
+			if ( PluginConstructor.pluginName ) {
+				this._availablePlugins.set( PluginConstructor.pluginName, PluginConstructor );
+			}
 		}
 	}
 
@@ -83,14 +87,14 @@ export default class PluginCollection {
 		const loading = new Set();
 		const loaded = [];
 
-		// Plugins which should be remove can be the constructors or plugin names.
-		// We need to unify this because we are supporting loading plugins by names or plugin constructors.
+		// Plugins that will be removed can be the constructors or names.
+		// We need to unify this because we are supporting loading plugins using both types.
 		removePlugins = removePlugins.reduce( ( arr, PluginConstructorOrName ) => {
 			arr.push( PluginConstructorOrName );
 
 			if ( typeof PluginConstructorOrName === 'string' ) {
 				arr.push( getPluginConstructor( PluginConstructorOrName ) );
-			} else {
+			} else if ( PluginConstructorOrName.pluginName ) {
 				arr.push( PluginConstructorOrName.pluginName );
 			}
 

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

@@ -31,10 +31,6 @@ before( () => {
 	PluginJ = createPlugin( 'J' );
 	PluginK = createPlugin( 'K' );
 	PluginX = class extends Plugin {
-		static get pluginName() {
-			return 'X';
-		}
-
 		constructor( editor ) {
 			super( editor );