Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Feature: Introduced CommandFactory#names(). Closes #287.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Aug 10, 2017
1 parent ac9795b commit 4038da2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/componentfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions src/toolbar/normalizetoolbarconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', ... ],
Expand Down
2 changes: 1 addition & 1 deletion src/toolbar/toolbarview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
19 changes: 17 additions & 2 deletions tests/componentfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {} );

Expand All @@ -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' );
Expand Down

0 comments on commit 4038da2

Please sign in to comment.