Skip to content

Commit

Permalink
fix(frontend): stop using chain function from lodash-es as it does no…
Browse files Browse the repository at this point in the history
…t support tree shaking
  • Loading branch information
pablolmedorado committed Apr 5, 2022
1 parent c83e6ac commit dcae903
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<script>
import { computed, ref } from "@vue/composition-api";
import { useClipboard } from "@vueuse/core";
import { chain, property, uniqueId } from "lodash-es";
import { countBy, map, pick, uniqueId } from "lodash-es";
import { useMainStore } from "@/stores/main";
import useDialog, { dialogProps } from "@/composables/useDialog";
Expand Down Expand Up @@ -86,21 +86,21 @@ export default {
// Computed
const itemSummary = computed(() => {
return chain(items.value)
.map((item) => chain(item).pick(["bread", "base", "ingredient1", "ingredient2"]).map(property("name")).value())
.countBy()
.map((count, item) => {
const elements = item.split(",");
return {
id: uniqueId("breakfast_"),
bread: elements[0] || "",
base: elements[1] || "",
ingredient1: elements[2] || "",
ingredient2: elements[3] || "",
count,
};
})
.value();
const rawBreakfasts = items.value.map((breakfast) =>
map(pick(breakfast, ["bread", "base", "ingredient1", "ingredient2"]), "name")
);
const breakfastsByCount = countBy(rawBreakfasts);
return map(breakfastsByCount, (count, item) => {
const elements = item.split(",");
return {
id: uniqueId("breakfast_"),
bread: elements[0] || "",
base: elements[1] || "",
ingredient1: elements[2] || "",
ingredient2: elements[3] || "",
count,
};
});
});
const clipboardSummary = computed(() => {
return itemSummary.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<script>
import { computed, ref } from "@vue/composition-api";
import { chain } from "lodash-es";
import { countBy, map } from "lodash-es";
import useDialog, { dialogProps } from "@/composables/useDialog";
Expand Down Expand Up @@ -61,13 +61,11 @@ export default {
// Computed
const holidaysSummary = computed(() => {
return chain(holidays.value)
.countBy((item) => [item.allowance_date, item.expiration_date])
.map((count, item) => {
const dates = item.split(",");
return { allowance_date: dates[0], expiration_date: dates[1], count };
})
.value();
const holidaysByCount = countBy(holidays.value, (item) => [item.allowance_date, item.expiration_date]);
return map(holidaysByCount, (count, item) => {
const dates = item.split(",");
return { allowance_date: dates[0], expiration_date: dates[1], count };
});
});
// Methods
Expand Down

0 comments on commit dcae903

Please sign in to comment.