Skip to content

Commit

Permalink
Use cached selector
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jul 16, 2018
1 parent bada6cc commit dcf20eb
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { flatten, isEmpty, map } from 'lodash';
import { isEmpty, map } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -12,19 +12,22 @@ import { withSelect } from '@wordpress/data';

const { Fill: BlockSettingsMenuPluginsGroup, Slot } = createSlotFill( 'BlockSettingsMenuPluginsGroup' );

const BlockSettingsMenuPluginsGroupSlot = ( { fillProps, selectedBlocks } ) => (
<Slot fillProps={ { ...fillProps, selectedBlocks } } >
{ ( fills ) => ! isEmpty( fills ) && (
<Fragment>
<div className="editor-block-settings-menu__separator" />
{ fills }
</Fragment>
) }
</Slot>
);
const BlockSettingsMenuPluginsGroupSlot = ( { fillProps, selectedBlocks } ) => {
selectedBlocks = map( selectedBlocks, ( block ) => block.name );
return (
<Slot fillProps={ { ...fillProps, selectedBlocks } } >
{ ( fills ) => ! isEmpty( fills ) && (
<Fragment>
<div className="editor-block-settings-menu__separator" />
{ fills }
</Fragment>
) }
</Slot>
);
};

BlockSettingsMenuPluginsGroup.Slot = withSelect( ( select, { fillProps: { uids } } ) => ( {
selectedBlocks: map( flatten( [ uids ] ), ( uid ) => select( 'core/editor' ).getBlockName( uid ) ),
selectedBlocks: select( 'core/editor' ).getBlocksByUID( uids ),
} ) )( BlockSettingsMenuPluginsGroupSlot );

export default BlockSettingsMenuPluginsGroup;

0 comments on commit dcf20eb

Please sign in to comment.