Skip to content
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: Refactor away from _.set() in getNodesWithSettings() #52278

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { get, set } from 'lodash';
import { get } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -32,7 +32,7 @@ import { PresetDuotoneFilter } from '../duotone/components';
import { getGapCSSValue } from '../../hooks/gap';
import { store as blockEditorStore } from '../../store';
import { LAYOUT_DEFINITIONS } from '../../layouts/definitions';
import { kebabCase } from '../../utils/object';
import { kebabCase, setImmutably } from '../../utils/object';

// List of block support features that can have their related styles
// generated under their own feature level selector rather than the block's.
Expand Down Expand Up @@ -678,11 +678,11 @@ export const getNodesWithSettings = ( tree, blockSelectors ) => {
}

const pickPresets = ( treeToPickFrom ) => {
const presets = {};
let presets = {};
PRESET_METADATA.forEach( ( { path } ) => {
const value = get( treeToPickFrom, path, false );
if ( value !== false ) {
set( presets, path, value );
presets = setImmutably( presets, path, value );
Copy link
Member Author

@tyxla tyxla Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty straightforward to trace - presets is already declared to be an object, and path is already an array of strings (see PRESET_METADATA declaration).

We needed to add support for arrays in order to properly work with root and nested arrays.

}
} );
return presets;
Expand Down