Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
🤫 @phenomic/core: minor factorisation for db sort callback
Browse files Browse the repository at this point in the history
  • Loading branch information
MoOx committed May 2, 2018
1 parent fc729aa commit efb2e8f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const nullSub = "__null__";
const emptyDatabase: PhenomicDBRegistry = {};
let database: PhenomicDBRegistry = emptyDatabase;

const orderById = (a, b) => (b.id > a.id ? -1 : 1);

function sortBy(sort = "date") {
return (a, b) => {
a = a.data[sort];
Expand Down Expand Up @@ -52,7 +54,7 @@ function putToSublevel(
database = {
...database,
[subname]: [...sub.filter(item => item.id !== value.id), value].sort(
(a, b) => (b.id > a.id ? -1 : 1)
orderById
)
};
}
Expand All @@ -71,7 +73,7 @@ function updateToSublevel(
[subname]: [
...sub.filter(item => item.id !== value.id),
merge({}, sub.find(item => item.id === value.id) || {}, value)
].sort((a, b) => (b.id > a.id ? -1 : 1))
].sort(orderById)
};
}

Expand Down

0 comments on commit efb2e8f

Please sign in to comment.