Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make possible get function through get() method in config #15121

Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions packages/ckeditor5-utils/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,16 @@ export default class Config<Cfg> {
* Clones configuration object or value.
*/
function cloneConfig<T>( source: T ): T {
return cloneDeepWith( source, leaveDOMReferences );
return cloneDeepWith( source, leaveItemReferences );
}

/**
* A customized function for cloneDeepWith.
* It will leave references to DOM Elements instead of cloning them.
* In case if it's a DOM Element it will leave references to DOM Elements instead of cloning them.
* If it's a function it will leave reference to actuall function.
*/
function leaveDOMReferences( value: unknown ): unknown {
return isElement( value ) ? value : undefined;
function leaveItemReferences( value: unknown ): unknown {
return isElement( value ) || typeof value === 'function' ? value : undefined;
}

/**
Expand Down
12 changes: 10 additions & 2 deletions packages/ckeditor5-utils/tests/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe( 'Config', () => {
{ bar: 'a' },
{ bar: 'z' }
]
}
},
callback: () => null
} );
} );

Expand Down Expand Up @@ -363,6 +364,11 @@ describe( 'Config', () => {
expect( config.get( 'resize.icon.path' ) ).to.equal( 'xyz' );
} );

it( 'should return a function', () => {
expect( typeof config.get( 'callback' ) ).to.equal( 'function' );
expect( config.get( 'callback' )() ).to.equal( null );
} );

it( 'should retrieve an object of the configuration', () => {
const resize = config.get( 'resize' );

Expand Down Expand Up @@ -482,7 +488,9 @@ describe( 'Config', () => {

describe( 'names()', () => {
it( 'should return an iterator of top level names of the configuration', () => {
expect( Array.from( config.names() ) ).to.be.deep.equal( [ 'creator', 'language', 'resize', 'toolbar', 'options' ] );
expect( Array.from( config.names() ) ).to.be.deep.equal(
[ 'creator', 'language', 'resize', 'toolbar', 'options', 'callback' ]
);
} );
} );
} );