Skip to content

Commit

Permalink
Lodash: Remove completely from annotations package (WordPress#41856)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Jun 22, 2022
1 parent ca3f229 commit a243966
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 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/annotations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@wordpress/hooks": "file:../hooks",
"@wordpress/i18n": "file:../i18n",
"@wordpress/rich-text": "file:../rich-text",
"lodash": "^4.17.21",
"rememo": "^4.0.0",
"uuid": "^8.3.0"
},
Expand Down
22 changes: 17 additions & 5 deletions packages/annotations/src/store/reducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { mapValues } from 'lodash';

/**
* Filters an array based on the predicate, but keeps the reference the same if
* the array hasn't changed.
Expand All @@ -20,6 +15,23 @@ function filterWithReference( collection, predicate ) {
: filteredCollection;
}

/**
* Creates a new object with the same keys, but with `callback()` called as
* a transformer function on each of the values.
*
* @param {Object} obj The object to transform.
* @param {Function} callback The function to transform each object value.
* @return {Array} Transformed object.
*/
const mapValues = ( obj, callback ) =>
Object.entries( obj ).reduce(
( acc, [ key, value ] ) => ( {
...acc,
[ key ]: callback( value ),
} ),
{}
);

/**
* Verifies whether the given annotations is a valid annotation.
*
Expand Down
5 changes: 1 addition & 4 deletions packages/annotations/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 { flatMap } from 'lodash';

/**
* Shared reference to an empty array for cases where it is important to avoid
Expand Down Expand Up @@ -79,7 +78,5 @@ export const __experimentalGetAnnotationsForRichText = createSelector(
* @return {Array} All annotations currently applied.
*/
export function __experimentalGetAnnotations( state ) {
return flatMap( state, ( annotations ) => {
return annotations;
} );
return Object.values( state ).flat();
}

0 comments on commit a243966

Please sign in to comment.