Skip to content

Commit

Permalink
Block tree reducer: avoid repetitive Map.get (#59672)
Browse files Browse the repository at this point in the history
Co-authored-by: jsnajdr <[email protected]>
Co-authored-by: youknowriad <[email protected]>
  • Loading branch information
3 people authored Mar 7, 2024
1 parent bba8c9a commit 2071a26
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,13 @@ const withBlockTree =
// If there are no replaced blocks, it means we're removing blocks so we need to update their parent.
const parentsOfRemovedBlocks = [];
for ( const clientId of action.clientIds ) {
const parentId = state.parents.get( clientId );
if (
state.parents.get( clientId ) !== undefined &&
( state.parents.get( clientId ) === '' ||
newState.byClientId.get(
state.parents.get( clientId )
) )
parentId !== undefined &&
( parentId === '' ||
newState.byClientId.get( parentId ) )
) {
parentsOfRemovedBlocks.push(
state.parents.get( clientId )
);
parentsOfRemovedBlocks.push( parentId );
}
}
updateParentInnerBlocksInTree(
Expand All @@ -351,16 +348,13 @@ const withBlockTree =
case 'REMOVE_BLOCKS_AUGMENTED_WITH_CHILDREN':
const parentsOfRemovedBlocks = [];
for ( const clientId of action.clientIds ) {
const parentId = state.parents.get( clientId );
if (
state.parents.get( clientId ) !== undefined &&
( state.parents.get( clientId ) === '' ||
newState.byClientId.get(
state.parents.get( clientId )
) )
parentId !== undefined &&
( parentId === '' ||
newState.byClientId.get( parentId ) )
) {
parentsOfRemovedBlocks.push(
state.parents.get( clientId )
);
parentsOfRemovedBlocks.push( parentId );
}
}
newState.tree = new Map( newState.tree );
Expand Down

0 comments on commit 2071a26

Please sign in to comment.