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

Made ComponentFactory.names() return original componenent name. #377

Merged
merged 1 commit into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/componentfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default class ComponentFactory {
* @returns {Iterable.<String>}
*/
* names() {
yield* this._components.keys();
for ( const value of this._components.values() ) {
yield value.originalName;
}
}

/**
Expand All @@ -87,7 +89,7 @@ export default class ComponentFactory {
);
}

this._components.set( getNormalized( name ), callback );
this._components.set( getNormalized( name ), { callback, originalName: name } );
}

/**
Expand Down Expand Up @@ -115,7 +117,7 @@ export default class ComponentFactory {
);
}

return this._components.get( getNormalized( name ) )( this.editor.locale );
return this._components.get( getNormalized( name ) ).callback( this.editor.locale );
}

/**
Expand Down
8 changes: 7 additions & 1 deletion tests/componentfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe( 'ComponentFactory', () => {
factory.add( 'bar', () => {} );
factory.add( 'Baz', () => {} );

expect( Array.from( factory.names() ) ).to.have.members( [ 'foo', 'bar', 'baz' ] );
expect( Array.from( factory.names() ) ).to.have.members( [ 'foo', 'bar', 'Baz' ] );
} );
} );

Expand All @@ -53,6 +53,12 @@ describe( 'ComponentFactory', () => {
factory.add( 'foo', () => {} );
} ).to.throw( CKEditorError, /^componentfactory-item-exists/ );
} );

it( 'does not normalize component names', () => {
factory.add( 'FoO', () => {} );

expect( Array.from( factory.names() ) ).to.have.members( [ 'FoO' ] );
} );
} );

describe( 'create()', () => {
Expand Down