Browse Source

Feature: Introduced `CommandFactory#names()`. Closes #287.

Piotrek Koszuliński 8 years ago
parent
commit
4bae0c7ee6

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

@@ -42,6 +42,15 @@ export default class ComponentFactory {
 		this._components = new Map();
 	}
 
+	/**
+	 * Returns iterator of component names.
+	 *
+	 * @returns {Iterator.<String>}
+	 */
+	* names() {
+		yield* this._components.keys();
+	}
+
 	/**
 	 * Registers a component factory.
 	 *

+ 2 - 2
packages/ckeditor5-ui/src/toolbar/normalizetoolbarconfig.js

@@ -8,11 +8,11 @@
  */
 
 /**
- * Normalizes the toolbar configuration (`config.toolbar`), which may be defined as an `Array`
+ * Normalizes the toolbar configuration (`config.toolbar`), which may be defined as an `Array`:
  *
  * 		toolbar: [ 'headings', 'bold', 'italic', 'link', 'unlink', ... ]
  *
- * or an `Object`
+ * or an `Object`:
  *
  *		toolbar: {
  *			items: [ 'headings', 'bold', 'italic', 'link', 'unlink', ... ],

+ 1 - 1
packages/ckeditor5-ui/src/toolbar/toolbarview.js

@@ -117,7 +117,7 @@ export default class ToolbarView extends View {
 	 * A utility which expands a plain toolbar configuration into
 	 * {@link module:ui/toolbar/toolbarview~ToolbarView#items} using a given component factory.
 	 *
-	 * @param {Array} config The toolbar config.
+	 * @param {Array.<String>} config The toolbar items config.
 	 * @param {module:ui/componentfactory~ComponentFactory} factory A factory producing toolbar items.
 	 */
 	fillFromConfig( config, factory ) {

+ 17 - 2
packages/ckeditor5-ui/tests/componentfactory.js

@@ -21,7 +21,22 @@ describe( 'ComponentFactory', () => {
 		} );
 	} );
 
-	describe( 'add', () => {
+	describe( 'names()', () => {
+		it( 'returns iterator', () => {
+			const names = factory.names();
+
+			expect( names.next ).to.be.a( 'function' );
+		} );
+
+		it( 'returns iterator of command names', () => {
+			factory.add( 'foo', () => {} );
+			factory.add( 'bar', () => {} );
+
+			expect( Array.from( factory.names() ) ).to.have.members( [ 'foo', 'bar' ] );
+		} );
+	} );
+
+	describe( 'add()', () => {
 		it( 'throws when trying to override already registered component', () => {
 			factory.add( 'foo', () => {} );
 
@@ -31,7 +46,7 @@ describe( 'ComponentFactory', () => {
 		} );
 	} );
 
-	describe( 'create', () => {
+	describe( 'create()', () => {
 		it( 'throws when trying to create a component which has not been registered', () => {
 			expect( () => {
 				factory.create( 'foo' );