Skip to content

Commit

Permalink
Lodash: Remove from blocks store reducer (#50471)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed May 10, 2023
1 parent 4c1c15d commit 1db3d30
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { get, isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -123,13 +118,11 @@ export function blockStyles( state = {}, action ) {
).map( ( [ name, blockType ] ) => [
name,
getUniqueItemsByName( [
...get( blockType, [ 'styles' ], [] ).map(
( style ) => ( {
...style,
source: 'block',
} )
),
...get( state, [ blockType.name ], [] ).filter(
...( blockType.styles ?? [] ).map( ( style ) => ( {
...style,
source: 'block',
} ) ),
...( state[ blockType.name ] ?? [] ).filter(
( { source } ) => 'block' !== source
),
] ),
Expand All @@ -140,17 +133,15 @@ export function blockStyles( state = {}, action ) {
return {
...state,
[ action.blockName ]: getUniqueItemsByName( [
...get( state, [ action.blockName ], [] ),
...( state[ action.blockName ] ?? [] ),
...action.styles,
] ),
};
case 'REMOVE_BLOCK_STYLES':
return {
...state,
[ action.blockName ]: get(
state,
[ action.blockName ],
[]
[ action.blockName ]: (
state[ action.blockName ] ?? []
).filter(
( style ) => action.styleNames.indexOf( style.name ) === -1
),
Expand Down Expand Up @@ -180,13 +171,13 @@ export function blockVariations( state = {}, action ) {
return [
name,
getUniqueItemsByName( [
...get( blockType, [ 'variations' ], [] ).map(
...( blockType.variations ?? [] ).map(
( variation ) => ( {
...variation,
source: 'block',
} )
),
...get( state, [ blockType.name ], [] ).filter(
...( state[ blockType.name ] ?? [] ).filter(
( { source } ) => 'block' !== source
),
] ),
Expand All @@ -198,17 +189,15 @@ export function blockVariations( state = {}, action ) {
return {
...state,
[ action.blockName ]: getUniqueItemsByName( [
...get( state, [ action.blockName ], [] ),
...( state[ action.blockName ] ?? [] ),
...action.variations,
] ),
};
case 'REMOVE_BLOCK_VARIATIONS':
return {
...state,
[ action.blockName ]: get(
state,
[ action.blockName ],
[]
[ action.blockName ]: (
state[ action.blockName ] ?? []
).filter(
( variation ) =>
action.variationNames.indexOf( variation.name ) === -1
Expand Down Expand Up @@ -269,7 +258,10 @@ export function categories( state = DEFAULT_CATEGORIES, action ) {
case 'SET_CATEGORIES':
return action.categories || [];
case 'UPDATE_CATEGORY': {
if ( ! action.category || isEmpty( action.category ) ) {
if (
! action.category ||
! Object.keys( action.category ).length
) {
return state;
}
const categoryToChange = state.find(
Expand Down

1 comment on commit 1db3d30

@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 in 1db3d30.
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/4933925324
📝 Reported issues:

Please sign in to comment.