Lodash: Remove from @wordpress/editor package#49799
Conversation
| const { editPost } = useDispatch( editorStore ); | ||
|
|
||
| if ( ! isViewable || isEmpty( availableTemplates ) ) { | ||
| if ( ! isViewable || ! Object.entries( availableTemplates ?? {} ).length ) { |
There was a problem hiding this comment.
availableTemplates could potentially be nullish, so we're falling back to an empty object before checking if it's empty. If not nullish, it is always an object.
There was a problem hiding this comment.
Have you considered using Object.keys? It creates a smaller array, so intuitively it should be less wasteful 🙂
Instead of the ?? {} suffix I'd consider writing isViewable || ! availableTemplates || ! Object.keys( ... ).length.
There was a problem hiding this comment.
Both are good suggestions, thanks 👍 Addressed in 2f1bf4d
| ); | ||
|
|
||
| if ( ! isEmpty( nextMeta ) ) { | ||
| if ( Object.entries( nextMeta ).length ) { |
There was a problem hiding this comment.
nextMeta is always an object as defined a few lines above (L71).
| .map( ( [ attributeKey, { meta } ] ) => [ attributeKey, meta ] ) | ||
| ); | ||
| if ( ! isEmpty( metaAttributes ) ) { | ||
| if ( Object.entries( metaAttributes ).length ) { |
There was a problem hiding this comment.
metaAttributes is always an object, as defined a few lines above (L108).
|
Size Change: -6 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
| const { editPost } = useDispatch( editorStore ); | ||
|
|
||
| if ( ! isViewable || isEmpty( availableTemplates ) ) { | ||
| if ( ! isViewable || ! Object.entries( availableTemplates ?? {} ).length ) { |
There was a problem hiding this comment.
Have you considered using Object.keys? It creates a smaller array, so intuitively it should be less wasteful 🙂
Instead of the ?? {} suffix I'd consider writing isViewable || ! availableTemplates || ! Object.keys( ... ).length.
b538784 to
18ae886
Compare
What?
This PR removes the remaining Lodash from the
@wordpress/editorpackage and removes the unused dependency. There were just a few straightforwardisEmpty()usages.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetchpackage haslodashas a dependency #39495How?
We're using
Object.entries( object ).lengthas an alternative, with a nullish coalescing fallback when necessary.Testing Instructions
_.mapValues()from editor package #49654 and verify they still work.