Skip to content

Commit

Permalink
Simplify intermediate functions
Browse files Browse the repository at this point in the history
Instead of iterating on object entries which returns two-tuples (which
would result in difficult and redundant typing), iterate on object keys.
Also inline the functions.
  • Loading branch information
victorlin committed Jun 4, 2024
1 parent 5186c63 commit 2aeb155
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions static-site/src/components/ListResources/useDataFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@ export function useDataFetch(sourceId, versioned, defaultGroupLinks, groupDispla
* resource objects.
*/
function partitionByPathogen(pathVersions, pathPrefix, versioned) {

return Object.entries(pathVersions).reduce(reduceFn, {});

function reduceFn(store, datum) {
const name = datum[0];
return Object.keys(pathVersions).reduce((store, name) => {
const nameParts = name.split('/');
const sortedDates = [...datum[1]].sort();
const sortedDates = [...pathVersions[name]].sort();

let groupName = nameParts[0];

Expand All @@ -88,7 +84,7 @@ function partitionByPathogen(pathVersions, pathPrefix, versioned) {
store[groupName].push(resourceDetails)

return store;
}
}, {});
}


Expand All @@ -97,9 +93,8 @@ function partitionByPathogen(pathVersions, pathPrefix, versioned) {
* into an array of groups.
*/
function groupsFrom(partitions, pathPrefix, defaultGroupLinks, groupDisplayNames) {
return Object.entries(partitions).map(makeGroup)

function makeGroup([groupName, resources]) {
return Object.keys(partitions).map(groupName => {
const resources = partitions[groupName];
const groupInfo = {
groupName: groupName,
nResources: resources.length,
Expand All @@ -115,7 +110,7 @@ function groupsFrom(partitions, pathPrefix, defaultGroupLinks, groupDisplayNames
groupInfo.groupDisplayName = groupDisplayNames[groupName];
}
return groupInfo;
}
})
}


Expand Down

0 comments on commit 2aeb155

Please sign in to comment.