Skip to content

Commit

Permalink
Don't filter values from arrays (#31780)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlende authored May 14, 2021
1 parent 80a2a1c commit b684490
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/block-editor/src/hooks/utils.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/**
* External dependencies
*/
import { pickBy, isEqual, isObject, identity, mapValues } from 'lodash';
import { pickBy, isEmpty, isObject, identity, mapValues } from 'lodash';

/**
* Removed undefined values from nested object.
* Removed falsy values from nested object.
*
* @param {*} object
* @return {*} Object cleaned from undefined values
* @return {*} Object cleaned from falsy values
*/
export const cleanEmptyObject = ( object ) => {
if ( ! isObject( object ) ) {
if ( ! isObject( object ) || Array.isArray( object ) ) {
return object;
}
const cleanedNestedObjects = pickBy(
mapValues( object, cleanEmptyObject ),
identity
);
return isEqual( cleanedNestedObjects, {} )
? undefined
: cleanedNestedObjects;
return isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects;
};

0 comments on commit b684490

Please sign in to comment.