Skip to content

Commit

Permalink
Lodash: Remove _.mapValues() from core-data package (#49724)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Apr 12, 2023
1 parent 3317ba1 commit 566554f
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions packages/core-data/src/queried-data/reducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { mapValues } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -126,8 +121,11 @@ export function items( state = {}, action ) {
};
}
case 'REMOVE_ITEMS':
return mapValues( state, ( contextState ) =>
removeEntitiesById( contextState, action.itemIds )
return Object.fromEntries(
Object.entries( state ).map( ( [ itemId, contextState ] ) => [
itemId,
removeEntitiesById( contextState, action.itemIds ),
] )
);
}
return state;
Expand Down Expand Up @@ -179,8 +177,11 @@ export function itemIsComplete( state = {}, action ) {
};
}
case 'REMOVE_ITEMS':
return mapValues( state, ( contextState ) =>
removeEntitiesById( contextState, action.itemIds )
return Object.fromEntries(
Object.entries( state ).map( ( [ itemId, contextState ] ) => [
itemId,
removeEntitiesById( contextState, action.itemIds ),
] )
);
}

Expand Down Expand Up @@ -254,13 +255,23 @@ const queries = ( state = {}, action ) => {
return result;
}, {} );

return mapValues( state, ( contextQueries ) => {
return mapValues( contextQueries, ( queryItems ) => {
return queryItems.filter( ( queryId ) => {
return ! removedItems[ queryId ];
} );
} );
} );
return Object.fromEntries(
Object.entries( state ).map(
( [ queryGroup, contextQueries ] ) => [
queryGroup,
Object.fromEntries(
Object.entries( contextQueries ).map(
( [ query, queryItems ] ) => [
query,
queryItems.filter(
( queryId ) => ! removedItems[ queryId ]
),
]
)
),
]
)
);
default:
return state;
}
Expand Down

1 comment on commit 566554f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 566554f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4676878576
📝 Reported issues:

Please sign in to comment.