-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 completely from site editor #52480
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,8 +1,3 @@ | ||||
/** | ||||
* External dependencies | ||||
*/ | ||||
import { get } from 'lodash'; | ||||
|
||||
/** | ||||
* WordPress dependencies | ||||
*/ | ||||
|
@@ -20,6 +15,14 @@ import { blockMeta, post, archive } from '@wordpress/icons'; | |||
* @property {string} name The entity's name. | ||||
*/ | ||||
|
||||
const getValueFromObjectPath = ( object, path ) => { | ||||
let value = object; | ||||
path.split( '.' ).forEach( ( fieldName ) => { | ||||
value = value?.[ fieldName ]; | ||||
} ); | ||||
return value; | ||||
}; | ||||
|
||||
/** | ||||
* Helper util to map records to add a `name` prop from a | ||||
* provided path, in order to handle all entities in the same | ||||
|
@@ -32,7 +35,7 @@ import { blockMeta, post, archive } from '@wordpress/icons'; | |||
export const mapToIHasNameAndId = ( entities, path ) => { | ||||
return ( entities || [] ).map( ( entity ) => ( { | ||||
...entity, | ||||
name: decodeEntities( get( entity, path ) ), | ||||
name: decodeEntities( getValueFromObjectPath( entity, path ) ), | ||||
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.
|
||||
} ) ); | ||||
}; | ||||
|
||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,8 +1,3 @@ | ||||
/** | ||||
* External dependencies | ||||
*/ | ||||
import { get } from 'lodash'; | ||||
|
||||
/** | ||||
* WordPress dependencies | ||||
*/ | ||||
|
@@ -96,6 +91,14 @@ const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = { | |||
|
||||
const SUPPORTED_STYLES = [ 'border', 'color', 'spacing', 'typography' ]; | ||||
|
||||
const getValueFromObjectPath = ( object, path ) => { | ||||
let value = object; | ||||
path.forEach( ( fieldName ) => { | ||||
value = value?.[ fieldName ]; | ||||
} ); | ||||
return value; | ||||
}; | ||||
|
||||
function useChangesToPush( name, attributes ) { | ||||
const supports = useSupportedStyles( name ); | ||||
|
||||
|
@@ -115,7 +118,7 @@ function useChangesToPush( name, attributes ) { | |||
]; | ||||
const value = presetAttributeValue | ||||
? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }` | ||||
: get( attributes.style, path ); | ||||
: getValueFromObjectPath( attributes.style, path ); | ||||
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.
|
||||
return value ? [ { path, value } ] : []; | ||||
} ), | ||||
[ supports, name, attributes ] | ||||
|
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.
One of the last packages to remove the dependency from 🥳