Skip to content

Commit

Permalink
♻️ reduce 내 spread syntax 삭제
Browse files Browse the repository at this point in the history
- 만약 사용할 배열이 커진다면 spread syntax의 경우 새 객체를 매번 생성하기 때문에 성능상 문제가 있을 수 있을 듯.
  • Loading branch information
padosum committed Mar 24, 2023
1 parent 6f97249 commit d130c9e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/store/getters.ts
@@ -1,3 +1,4 @@
import { AsyncLocalStorage } from "async_hooks";
import type { RootState } from "./state";

export const getters = {
Expand Down Expand Up @@ -31,9 +32,11 @@ export const getters = {
const tags = state.postItems.reduce((acc: Tag, { tags }) => {
if (typeof tags !== "undefined") {
tags.forEach((tag) => {
acc = acc[tag]
? { ...acc, [tag]: acc[tag] + 1 }
: { ...acc, [tag]: 1 };
if (acc[tag]) {
acc[tag] += 1;
} else {
acc[tag] = 1;
}
});
}
return acc;
Expand Down

0 comments on commit d130c9e

Please sign in to comment.