Skip to content

Commit

Permalink
Use spread instead of lodash.assign, do not promote mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jul 12, 2023
1 parent 95fe249 commit 64f088f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions docs/reference-guides/filters/block-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ function addListBlockClassName( settings, name ) {
return settings;
}

return lodash.assign( {}, settings, {
supports: lodash.assign( {}, settings.supports, {
return {
...settings,
supports: {
...settings.supports,
className: true,
} ),
} );
},
};
}

wp.hooks.addFilter(
Expand Down Expand Up @@ -126,7 +128,10 @@ Adding a background by default to all blocks.

```js
function addBackgroundColorStyle( props ) {
return lodash.assign( props, { style: { backgroundColor: 'red' } } );
return {
...props,
style: { backgroundColor: 'red' },
};
}

wp.hooks.addFilter(
Expand Down Expand Up @@ -276,9 +281,10 @@ var withClientIdClassName = wp.compose.createHigherOrderComponent( function (
BlockListBlock
) {
return function ( props ) {
var newProps = lodash.assign( {}, props, {
var newProps = {
...props,
className: 'block-' + props.clientId,
} );
};

return el( BlockListBlock, newProps );
};
Expand Down

0 comments on commit 64f088f

Please sign in to comment.