Skip to content

Commit

Permalink
Lodash: Remove completely from rich-text package (#44204)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Sep 26, 2022
1 parent ad07008 commit 7829913
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 33 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/rich-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@wordpress/escape-html": "file:../escape-html",
"@wordpress/i18n": "file:../i18n",
"@wordpress/keycodes": "file:../keycodes",
"lodash": "^4.17.21",
"memize": "^1.1.0",
"rememo": "^4.0.0"
},
Expand Down
12 changes: 5 additions & 7 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* External dependencies
*/
import { View, Platform, Dimensions } from 'react-native';
import { get, pickBy } from 'lodash';
import memize from 'memize';
import { colord } from 'colord';

Expand Down Expand Up @@ -228,8 +227,10 @@ export class RichText extends Component {

onFormatChange( record ) {
const { start = 0, end = 0, activeFormats = [] } = record;
const changeHandlers = pickBy( this.props, ( v, key ) =>
key.startsWith( 'format_on_change_functions_' )
const changeHandlers = Object.fromEntries(
Object.entries( this.props ).filter( ( [ key ] ) =>
key.startsWith( 'format_on_change_functions_' )
)
);

Object.values( changeHandlers ).forEach( ( changeHandler ) => {
Expand Down Expand Up @@ -1282,10 +1283,7 @@ export default compose( [
select( 'core/block-editor' );
const parents = getBlockParents( clientId, true );
const parentBlock = parents ? getBlock( parents[ 0 ] ) : undefined;
const parentBlockStyles = get( parentBlock, [
'attributes',
'childrenStyles',
] );
const parentBlockStyles = parentBlock?.attributes?.childrenStyles;

const settings = getSettings();
const baseGlobalStyles = settings?.__experimentalGlobalStylesBaseStyles;
Expand Down
11 changes: 3 additions & 8 deletions packages/rich-text/src/get-active-format.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
/**
* External dependencies
*/

import { find } from 'lodash';

/**
* Internal dependencies
*/

import { getActiveFormats } from './get-active-formats';

/** @typedef {import('./create').RichTextValue} RichTextValue */
Expand All @@ -26,5 +19,7 @@ import { getActiveFormats } from './get-active-formats';
* type, or undefined.
*/
export function getActiveFormat( value, formatType ) {
return find( getActiveFormats( value ), { type: formatType } );
return getActiveFormats( value )?.find(
( { type } ) => type === formatType
);
}
11 changes: 4 additions & 7 deletions packages/rich-text/src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { castArray } from 'lodash';

/**
* Returns an action object used in signalling that format types have been
* added.
Expand All @@ -14,7 +9,9 @@ import { castArray } from 'lodash';
export function addFormatTypes( formatTypes ) {
return {
type: 'ADD_FORMAT_TYPES',
formatTypes: castArray( formatTypes ),
formatTypes: Array.isArray( formatTypes )
? formatTypes
: [ formatTypes ],
};
}

Expand All @@ -28,6 +25,6 @@ export function addFormatTypes( formatTypes ) {
export function removeFormatTypes( names ) {
return {
type: 'REMOVE_FORMAT_TYPES',
names: castArray( names ),
names: Array.isArray( names ) ? names : [ names ],
};
}
11 changes: 5 additions & 6 deletions packages/rich-text/src/store/reducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { omit } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -31,7 +26,11 @@ export function formatTypes( state = {}, action ) {
),
};
case 'REMOVE_FORMAT_TYPES':
return omit( state, action.names );
return Object.fromEntries(
Object.entries( state ).filter(
( [ key ] ) => ! action.names.includes( key )
)
);
}

return state;
Expand Down
5 changes: 2 additions & 3 deletions packages/rich-text/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import createSelector from 'rememo';
import { find } from 'lodash';

/**
* Returns all the available format types.
Expand Down Expand Up @@ -38,7 +37,7 @@ export function getFormatType( state, name ) {
* @return {?Object} Format type.
*/
export function getFormatTypeForBareElement( state, bareElementTagName ) {
return find( getFormatTypes( state ), ( { className, tagName } ) => {
return getFormatTypes( state ).find( ( { className, tagName } ) => {
return className === null && bareElementTagName === tagName;
} );
}
Expand All @@ -52,7 +51,7 @@ export function getFormatTypeForBareElement( state, bareElementTagName ) {
* @return {?Object} Format type.
*/
export function getFormatTypeForClassName( state, elementClassName ) {
return find( getFormatTypes( state ), ( { className } ) => {
return getFormatTypes( state ).find( ( { className } ) => {
if ( className === null ) {
return false;
}
Expand Down

0 comments on commit 7829913

Please sign in to comment.