Skip to content

Commit

Permalink
Merge pull request #490 from alleyinteractive/hotfix/remove-lodash-dep
Browse files Browse the repository at this point in the history
Hotfix: Remove Lodash as Dependency
  • Loading branch information
efuller authored Nov 29, 2023
2 parents b627cae + ba7fab8 commit c9e18d3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
4 changes: 1 addition & 3 deletions package-lock.json

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

4 changes: 4 additions & 0 deletions packages/block-editor-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const MyComponent = () => {

## Changelog

### 0.4.1

- Remove `lodash` as dependency from `block-editor-tools` package.

### 0.3.8

- Use of `decodeEntities` in `<PostPicker>` component search results.
Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alleyinteractive/block-editor-tools",
"version": "0.4.0",
"version": "0.4.1",
"description": "A set of tools to help build products for the WordPress block editor.",
"main": "./build/index.bundle.min.js",
"types": "./build/index.d.ts",
Expand Down Expand Up @@ -57,7 +57,6 @@
"@wordpress/url": "^3.46.0",
"classnames": "^2.3.2",
"dompurify": "^3.0.6",
"lodash": "^4.17.21",
"papaparse": "^5.4.0",
"prop-types": "^15.8.1",
"react": "18.2.0",
Expand Down
11 changes: 2 additions & 9 deletions packages/block-editor-tools/src/hooks/use-post-meta/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEntityProp } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { cloneDeep } from 'lodash';

/**
* A custom React hook that wraps useEntityProp for working with postmeta. This
Expand Down Expand Up @@ -31,16 +30,10 @@ const usePostMeta = (postType = null, postId = null) => {
: () => console.error(`Error attempting to set post meta for post type ${type}. Does it have support for custom-fields?`); // eslint-disable-line no-console

/**
* Define a wrapper for the setMeta function that performs a recursive clone
* of the meta object to ensure that there are no issues related to updating
* objects or array values within meta keys not triggering React or
* Gutenberg's state management system realizing that there is a change due
* to the fact that sub-items are stored as object references. These bugs are
* extremely difficult to find and correct, so it makes sense to include this
* functionality here as a catch-all on updates.
* Define a wrapper for the setMeta function that spreads the next meta value into a new object.
* @param {object} next - The new value for meta.
*/
const setMetaSafe = (next) => setMeta(cloneDeep(next));
const setMetaSafe = (next) => setMeta({ ...next });

return [meta, setMetaSafe];
};
Expand Down

0 comments on commit c9e18d3

Please sign in to comment.