Skip to content

Commit 2071a26

Browse files
jsnajdryouknowriad
andauthored
Block tree reducer: avoid repetitive Map.get (#59672)
Co-authored-by: jsnajdr <[email protected]> Co-authored-by: youknowriad <[email protected]>
1 parent bba8c9a commit 2071a26

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

packages/block-editor/src/store/reducer.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,13 @@ const withBlockTree =
329329
// If there are no replaced blocks, it means we're removing blocks so we need to update their parent.
330330
const parentsOfRemovedBlocks = [];
331331
for ( const clientId of action.clientIds ) {
332+
const parentId = state.parents.get( clientId );
332333
if (
333-
state.parents.get( clientId ) !== undefined &&
334-
( state.parents.get( clientId ) === '' ||
335-
newState.byClientId.get(
336-
state.parents.get( clientId )
337-
) )
334+
parentId !== undefined &&
335+
( parentId === '' ||
336+
newState.byClientId.get( parentId ) )
338337
) {
339-
parentsOfRemovedBlocks.push(
340-
state.parents.get( clientId )
341-
);
338+
parentsOfRemovedBlocks.push( parentId );
342339
}
343340
}
344341
updateParentInnerBlocksInTree(
@@ -351,16 +348,13 @@ const withBlockTree =
351348
case 'REMOVE_BLOCKS_AUGMENTED_WITH_CHILDREN':
352349
const parentsOfRemovedBlocks = [];
353350
for ( const clientId of action.clientIds ) {
351+
const parentId = state.parents.get( clientId );
354352
if (
355-
state.parents.get( clientId ) !== undefined &&
356-
( state.parents.get( clientId ) === '' ||
357-
newState.byClientId.get(
358-
state.parents.get( clientId )
359-
) )
353+
parentId !== undefined &&
354+
( parentId === '' ||
355+
newState.byClientId.get( parentId ) )
360356
) {
361-
parentsOfRemovedBlocks.push(
362-
state.parents.get( clientId )
363-
);
357+
parentsOfRemovedBlocks.push( parentId );
364358
}
365359
}
366360
newState.tree = new Map( newState.tree );

0 commit comments

Comments
 (0)