Skip to content

Commit

Permalink
Reverse sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 26, 2021
1 parent 8686fbf commit 2be5747
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/system/footer/shared/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const addSharedSystems = function (systems) {
const propGroups = getPropGroups(propEntries)
const propGroupsA = simplifyPropGroups(propGroups, systems)
const propGroupsB = addTopSystem(propGroupsA)
const propGroupsC = sortSystems(propGroupsB)
const systemsA = finalizeSystems(propGroupsC)
systemsA.forEach(({ dimensions, ...props }) => {
const systemsA = finalizeSystems(propGroupsB)
const systemsB = sortSystems(systemsA)
systemsB.forEach(({ dimensions, ...props }) => {
console.log(props, dimensions)
})
return systemsA
return systemsB
}

// Transform `propGroups` back to `systems`
Expand Down
15 changes: 8 additions & 7 deletions src/system/footer/shared/sort/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import { compareSystems } from './systems.js'

// Sort systems deeply so they are shown in a user-friendly and predictable way
// in the footer
export const sortSystems = function (propGroups) {
export const sortSystems = function (systems) {
// eslint-disable-next-line fp/no-mutating-methods
return propGroups.map(addSortProps).sort(compareSystems).map(removeSortProps)
return systems.map(addSortProps).sort(compareSystems).map(removeSortProps)
}

// Add properties used during sorting so they are only computed once
const addSortProps = function ({ propEntries, dimensionsArray }) {
const addSortProps = function ({ dimensions: dimensionsArray, ...props }) {
const isTopSystem = isTopPropGroup({ dimensionsArray })
const propEntriesA = sortPropEntries(propEntries.map(addPropOrder))
const propEntries = Object.entries(props).map(addPropOrder)
const propEntriesA = sortPropEntries(propEntries)
const dimensionsArrayA = sortDimensionsArray(
dimensionsArray.map(Object.entries),
)
Expand All @@ -26,7 +27,7 @@ const addSortProps = function ({ propEntries, dimensionsArray }) {
}

const removeSortProps = function ({ propEntries, dimensionsArray }) {
const propEntriesA = propEntries.map(removePropOrder)
const dimensionsArrayA = dimensionsArray.map(Object.fromEntries)
return { propEntries: propEntriesA, dimensionsArray: dimensionsArrayA }
const props = Object.fromEntries(propEntries.map(removePropOrder))
const dimensions = dimensionsArray.map(Object.fromEntries)
return { dimensions, ...props }
}
4 changes: 2 additions & 2 deletions src/system/footer/shared/sort/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sortOn from 'sort-on'

// Sort the properties in each system, when it has several.
// Those follow a static order since the property names are known.
export const addPropOrder = function ({ propName, propValue }) {
export const addPropOrder = function ([propName, propValue]) {
const propOrder = PROP_ORDER.indexOf(propName)
return { propName, propValue, propOrder }
}
Expand All @@ -15,5 +15,5 @@ export const sortPropEntries = function (propEntries) {
}

export const removePropOrder = function ({ propName, propValue }) {
return { propName, propValue }
return [propName, propValue]
}

0 comments on commit 2be5747

Please sign in to comment.