Skip to content

Commit

Permalink
mapValues: use fromEntries, avoid re-creating object in each reducer …
Browse files Browse the repository at this point in the history
…call (WordPress#51159)
  • Loading branch information
jsnajdr authored and sethrubenstein committed Jul 13, 2023
1 parent 5629d6e commit b1ff47c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/data/src/redux-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ const trimUndefinedValues = ( array ) => {
* @return {Array} Transformed object.
*/
const mapValues = ( obj, callback ) =>
Object.entries( obj ?? {} ).reduce(
( acc, [ key, value ] ) => ( {
...acc,
[ key ]: callback( value, key ),
} ),
{}
Object.fromEntries(
Object.entries( obj ?? {} ).map( ( [ key, value ] ) => [
key,
callback( value, key ),
] )
);

// Convert Map objects to plain objects
Expand Down

0 comments on commit b1ff47c

Please sign in to comment.