Skip to content

Commit

Permalink
More concise coding
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 24, 2020
1 parent e8c1501 commit 68a1c85
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/components/Root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ const DEFAULT = {
],
};
const SORT_FUNCS = {
alphabetically: (a, b) => ascending(a.body, b.body)
|| ascending(a.dates.start, b.dates.start),
requestCount: (a, b) => descending(
a.requests.get('all').length / sum(a.elections, (d) => d.seats),
b.requests.get('all').length / sum(b.elections, (d) => d.seats),
),
};
export default {
name: 'Root',
components: {
Expand All @@ -98,24 +107,7 @@ export default {
this.timeFilter === 'all' || d.hasEnded === (this.timeFilter === 'previous'))
&& d.requests.get(this.requestType).length > 0);
let sortFunc;
switch (this.sortBy) {
case 'alphabetically':
sortFunc = (a, b) => ascending(a.body, b.body)
|| ascending(a.dates.start, b.dates.start);
break;
case 'requestCount':
sortFunc = (a, b) => descending(
a.requests.get('all').length / sum(a.elections, (d) => d.seats),
b.requests.get('all').length / sum(b.elections, (d) => d.seats),
);
break;
default:
sortFunc = (a, b) => ascending(a.body, b.body)
|| ascending(a.dates.start, b.dates.start);
}
return data.sort(sortFunc);
return data.sort(SORT_FUNCS[this.sortBy]);
},
groupsMap() {
return rollup(this.groups, (v) => v[0], (d) => d.name);
Expand Down

0 comments on commit 68a1c85

Please sign in to comment.