Skip to content

Commit

Permalink
fix: clone lists to prevent outdated information
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed May 6, 2020
1 parent 8c88f7d commit e6ee6dc
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const emptyLists = [[], [], [], []];

const byNumber = (a, b) => a > b;
const findForestType = (c) => types.forestType.find((f) => f.code === c);
const getRecommendations = (forestType) => {
const [, lists] = Object.entries(recommendations).find(
(t) => t[0] === forestType,
);
return [...(lists || emptyLists)];
};
const nonresidents = (c) =>
types.treeType.find((t) => t.code === c).nonresident;
const residents = (c) => !types.treeType.find((t) => t.code === c).nonresident;
Expand All @@ -30,18 +36,14 @@ function list(location = {}) {
throw new Error(`${forestType} is not valid`);
}

const [, lists] = Object.entries(recommendations).find(
(t) => t[0] === forestType,
) || [null, emptyLists];
const lists = getRecommendations(forestType);

if (transitionForestType) {
if (findForestType(transitionForestType) === undefined) {
throw new Error(`${transitionForestType} is not valid`);
}

const [, transitionLists] = Object.entries(recommendations).find(
(t) => t[0] === transitionForestType,
) || [null, emptyLists];
const transitionLists = getRecommendations(transitionForestType);

lists[0] = union(
intersection(lists[0], transitionLists[0]),
Expand Down

0 comments on commit e6ee6dc

Please sign in to comment.