diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index 76972a950deb1..d8f76e00fc71d 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { get, isEmpty } from 'lodash'; - /** * WordPress dependencies */ @@ -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 ), ] ), @@ -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 ), @@ -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 ), ] ), @@ -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 @@ -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(