Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 12, 2021
1 parent cfdb908 commit 6e6febd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/combination/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// - The order of dimensions when printing:
// - combinationName in previews, `dev` and error messages
// - combinationTitle in reporters
export const DIMENSIONS = [
const DIMENSIONS_ARRAY = [
{
// Name used as property internally and when saving
propName: 'task',
Expand All @@ -29,3 +29,14 @@ export const DIMENSIONS = [
createdByUser: true,
},
]

// Turn dimensions array into an object
const getDimensions = function () {
return Object.fromEntries(DIMENSIONS_ARRAY.map(getDimensionPair))
}

const getDimensionPair = function (dimension) {
return [dimension.propName, dimension]
}

export const DIMENSIONS = getDimensions()
6 changes: 3 additions & 3 deletions src/combination/ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const isNotDuplicate = function ({ dimension, id }, index, combinationIds) {

// Retrieve each dimension's id of a given combination
export const getCombinationIds = function ({ dimensions }) {
return DIMENSIONS.map((dimension) => ({
dimension,
id: dimensions[dimension.propName].id,
return Object.entries(dimensions).map(([propName, { id }]) => ({
id,
dimension: DIMENSIONS[propName],
}))
}

0 comments on commit 6e6febd

Please sign in to comment.