Skip to content

Commit

Permalink
Lodash: Refactor away from _.mergeWith() (WordPress#51483)
Browse files Browse the repository at this point in the history
* Lodash: Refactor away from _.mergeWith()

* Add back the comment

* Update package-lock.json
  • Loading branch information
tyxla authored and sethrubenstein committed Jul 13, 2023
1 parent 78b4259 commit 337d857
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const restrictedImports = [
'maxBy',
'memoize',
'merge',
'mergeWith',
'negate',
'noop',
'nth',
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
"@wordpress/wordcount": "file:../wordcount",
"classnames": "^2.3.1",
"colord": "^2.9.2",
"deepmerge": "^4.3.0",
"downloadjs": "^1.4.7",
"fast-deep-equal": "^3.1.3",
"is-plain-object": "^5.0.0",
"lodash": "^4.17.21",
"memize": "^2.1.0",
"react-autosize-textarea": "^7.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
import { mergeWith } from 'lodash';
import deepmerge from 'deepmerge';
import { isPlainObject } from 'is-plain-object';

/**
* WordPress dependencies
Expand All @@ -21,17 +22,13 @@ const { GlobalStylesContext, cleanEmptyObject } = unlock(
blockEditorPrivateApis
);

function mergeTreesCustomizer( _, srcValue ) {
// We only pass as arrays the presets,
// in which case we want the new array of values
// to override the old array (no merging).
if ( Array.isArray( srcValue ) ) {
return srcValue;
}
}

export function mergeBaseAndUserConfigs( base, user ) {
return mergeWith( {}, base, user, mergeTreesCustomizer );
return deepmerge( base, user, {
// We only pass as arrays the presets,
// in which case we want the new array of values
// to override the old array (no merging).
isMergeableObject: isPlainObject,
} );
}

function useGlobalStylesUserConfig() {
Expand Down

0 comments on commit 337d857

Please sign in to comment.