Skip to content

Commit

Permalink
Lodash: Remove from block editor reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored and ntsekouras committed Dec 20, 2022
1 parent 86a1c19 commit 5f8c580
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import fastDeepEqual from 'fast-deep-equal/es6';
import { omit, isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -113,7 +112,10 @@ function getFlattenedClientIds( blocks ) {
* @return {Array} Flattened block attributes object.
*/
function getFlattenedBlocksWithoutAttributes( blocks ) {
return flattenBlocks( blocks, ( block ) => omit( block, 'attributes' ) );
return flattenBlocks( blocks, ( block ) => {
const { attributes, ...restBlock } = block;
return restBlock;
} );
}

/**
Expand Down Expand Up @@ -782,8 +784,8 @@ export const blocks = pipe(
}

// Do nothing if only attributes change.
const changes = omit( action.updates, 'attributes' );
if ( isEmpty( changes ) ) {
const { attributes, ...changes } = action.updates;
if ( Object.values( changes ).length === 0 ) {
return state;
}

Expand Down Expand Up @@ -1641,13 +1643,18 @@ export const blockListSettings = ( state = {}, action ) => {
// should correct the state.
case 'REPLACE_BLOCKS':
case 'REMOVE_BLOCKS': {
return omit( state, action.clientIds );
return Object.fromEntries(
Object.entries( state ).filter(
( [ id ] ) => ! action.clientIds.includes( id )
)
);
}
case 'UPDATE_BLOCK_LIST_SETTINGS': {
const { clientId } = action;
if ( ! action.settings ) {
if ( state.hasOwnProperty( clientId ) ) {
return omit( state, clientId );
const { [ clientId ]: removedBlock, ...restBlocks } = state;
return restBlocks;
}

return state;
Expand Down

1 comment on commit 5f8c580

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3739729851
📝 Reported issues:

Please sign in to comment.