Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lodash: Remove _.mapValues() from core-data package #49724

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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