Skip to content

Commit

Permalink
Remove DRY and keep the logic inline.
Browse files Browse the repository at this point in the history
  • Loading branch information
desaiuditd committed May 10, 2020
1 parent f8ecaa9 commit 81d4f4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
24 changes: 21 additions & 3 deletions packages/block-library/src/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { common as commonEmbeds, others as otherEmbeds } from './core-embeds';
import { embedContentIcon } from './icons';
import { getEmbedBlockSettings } from './settings';
import transforms, { _mergeTransforms } from './transforms';
import transforms from './transforms';

/**
* WordPress dependencies
Expand All @@ -24,6 +24,24 @@ export const settings = getEmbedBlockSettings( {
transforms,
} );

export const common = commonEmbeds.map( _mergeTransforms );
export const common = commonEmbeds.map( ( embedDefinition ) => {
const embedSettings = getEmbedBlockSettings( embedDefinition.settings );
return {
...embedDefinition,
settings: {
...embedSettings,
transforms,
},
};
} );

export const others = otherEmbeds.map( _mergeTransforms );
export const others = otherEmbeds.map( ( embedDefinition ) => {
const embedSettings = getEmbedBlockSettings( embedDefinition.settings );
return {
...embedDefinition,
settings: {
...embedSettings,
transforms,
},
};
} );
36 changes: 0 additions & 36 deletions packages/block-library/src/embed/transforms.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
/**
* External dependencies
*/
import { concat } from 'lodash';

/**
* WordPress dependencies
*/
import { renderToString } from '@wordpress/element';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { getEmbedBlockSettings } from './settings';

/**
* Default transforms for generic embeds.
*/
Expand Down Expand Up @@ -45,30 +35,4 @@ const transforms = {
],
};

/**
* Merge default transforms with the embed (common/other) specific transforms.
*
* @param {Object} embedDefinition Embed definition.
* @return {Object} Updated Embed definition with all the transforms together.
*/
export const _mergeTransforms = ( embedDefinition ) => {
const embedSettings = getEmbedBlockSettings( embedDefinition.settings );
return {
...embedDefinition,
settings: {
...embedSettings,
transforms: {
from: concat(
transforms?.from ?? [],
embedSettings?.transforms?.from ?? []
).filter( Boolean ),
to: concat(
transforms?.to ?? [],
embedSettings?.transforms?.to ?? []
).filter( Boolean ),
},
},
};
};

export default transforms;

0 comments on commit 81d4f4c

Please sign in to comment.