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

Commit 4038da2

Browse files
committed
Feature: Introduced CommandFactory#names(). Closes #287.
1 parent ac9795b commit 4038da2

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/componentfactory.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ export default class ComponentFactory {
4242
this._components = new Map();
4343
}
4444

45+
/**
46+
* Returns iterator of component names.
47+
*
48+
* @returns {Iterator.<String>}
49+
*/
50+
* names() {
51+
yield* this._components.keys();
52+
}
53+
4554
/**
4655
* Registers a component factory.
4756
*

src/toolbar/normalizetoolbarconfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
*/
99

1010
/**
11-
* Normalizes the toolbar configuration (`config.toolbar`), which may be defined as an `Array`
11+
* Normalizes the toolbar configuration (`config.toolbar`), which may be defined as an `Array`:
1212
*
1313
* toolbar: [ 'headings', 'bold', 'italic', 'link', 'unlink', ... ]
1414
*
15-
* or an `Object`
15+
* or an `Object`:
1616
*
1717
* toolbar: {
1818
* items: [ 'headings', 'bold', 'italic', 'link', 'unlink', ... ],

src/toolbar/toolbarview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class ToolbarView extends View {
117117
* A utility which expands a plain toolbar configuration into
118118
* {@link module:ui/toolbar/toolbarview~ToolbarView#items} using a given component factory.
119119
*
120-
* @param {Array} config The toolbar config.
120+
* @param {Array.<String>} config The toolbar items config.
121121
* @param {module:ui/componentfactory~ComponentFactory} factory A factory producing toolbar items.
122122
*/
123123
fillFromConfig( config, factory ) {

tests/componentfactory.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,22 @@ describe( 'ComponentFactory', () => {
2121
} );
2222
} );
2323

24-
describe( 'add', () => {
24+
describe( 'names()', () => {
25+
it( 'returns iterator', () => {
26+
const names = factory.names();
27+
28+
expect( names.next ).to.be.a( 'function' );
29+
} );
30+
31+
it( 'returns iterator of command names', () => {
32+
factory.add( 'foo', () => {} );
33+
factory.add( 'bar', () => {} );
34+
35+
expect( Array.from( factory.names() ) ).to.have.members( [ 'foo', 'bar' ] );
36+
} );
37+
} );
38+
39+
describe( 'add()', () => {
2540
it( 'throws when trying to override already registered component', () => {
2641
factory.add( 'foo', () => {} );
2742

@@ -31,7 +46,7 @@ describe( 'ComponentFactory', () => {
3146
} );
3247
} );
3348

34-
describe( 'create', () => {
49+
describe( 'create()', () => {
3550
it( 'throws when trying to create a component which has not been registered', () => {
3651
expect( () => {
3752
factory.create( 'foo' );

0 commit comments

Comments
 (0)