-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Lodash: Remove _.isEmpty()
from site editor
#50917
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,8 +1,3 @@ | ||||
/** | ||||
* External dependencies | ||||
*/ | ||||
import { isEmpty } from 'lodash'; | ||||
|
||||
/** | ||||
* WordPress dependencies | ||||
*/ | ||||
|
@@ -14,7 +9,7 @@ const { Fill: ToolsMoreMenuGroup, Slot } = createSlotFill( | |||
|
||||
ToolsMoreMenuGroup.Slot = ( { fillProps } ) => ( | ||||
<Slot fillProps={ fillProps }> | ||||
{ ( fills ) => ! isEmpty( fills ) && fills } | ||||
{ ( fills ) => fills && fills.length > 0 } | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can actually remove the |
||||
</Slot> | ||||
); | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isEmpty } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
@@ -30,6 +25,10 @@ import EditorCanvasContainer from '../editor-canvas-container'; | |
const { ExperimentalBlockEditorProvider, useGlobalStylesOutputWithConfig } = | ||
unlock( blockEditorPrivateApis ); | ||
|
||
function isObjectEmpty( object ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used 4 times, so it can't hurt to have it as an inline helper function. |
||
return ! object || Object.keys( object ).length === 0; | ||
} | ||
|
||
function Revisions( { onClose, userConfig, blocks } ) { | ||
const { baseConfig } = useSelect( | ||
( select ) => ( { | ||
|
@@ -42,7 +41,7 @@ function Revisions( { onClose, userConfig, blocks } ) { | |
); | ||
|
||
const mergedConfig = useMemo( () => { | ||
if ( ! isEmpty( userConfig ) && ! isEmpty( baseConfig ) ) { | ||
if ( ! isObjectEmpty( userConfig ) && ! isObjectEmpty( baseConfig ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both |
||
return mergeBaseAndUserConfigs( baseConfig, userConfig ); | ||
} | ||
return {}; | ||
|
@@ -65,7 +64,7 @@ function Revisions( { onClose, userConfig, blocks } ) { | |
const [ globalStyles ] = useGlobalStylesOutputWithConfig( mergedConfig ); | ||
|
||
const editorStyles = | ||
! isEmpty( globalStyles ) && ! isEmpty( userConfig ) | ||
! isObjectEmpty( globalStyles ) && ! isObjectEmpty( userConfig ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both |
||
? globalStyles | ||
: settings.styles; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userConfig
is already used as a potentially nullish object, which is why we're adding the extra checks.