Skip to content

Commit

Permalink
Use an if instead of a switch in getFormatValue()
Browse files Browse the repository at this point in the history
A `switch` is overkill when there's only one format value that acts
differently.
  • Loading branch information
noisysocks committed Aug 16, 2018
1 parent 06c8f1a commit 7d2ffce
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,18 @@ const { Node, getSelection } = window;
const TINYMCE_ZWSP = '\uFEFF';

export function getFormatValue( formatName, parents ) {
switch ( formatName ) {
case 'link' : {
const anchor = find( parents, ( node ) => node.nodeName === 'A' );
if ( anchor ) {
if ( anchor.hasAttribute( 'data-wp-placeholder' ) ) {
return { isAdding: true };
}
return {
isActive: true,
value: anchor.getAttribute( 'href' ) || '',
target: anchor.getAttribute( 'target' ) || '',
node: anchor,
};
if ( formatName === 'link' ) {
const anchor = find( parents, ( node ) => node.nodeName === 'A' );
if ( anchor ) {
if ( anchor.hasAttribute( 'data-wp-placeholder' ) ) {
return { isAdding: true };
}
return {
isActive: true,
value: anchor.getAttribute( 'href' ) || '',
target: anchor.getAttribute( 'target' ) || '',
node: anchor,
};
}
}

Expand Down

0 comments on commit 7d2ffce

Please sign in to comment.