modern-agile-team / modern-kit

@modern-kit은 클라이언트 개발에 유용한 모듈들을 제공하는 오픈소스 라이브러리 입니다.
https://modern-agile-team.github.io/modern-kit/
MIT License
44 stars 8 forks source link

fix(utils): excludeElements 성능 개선을 위해 인터페이스 변경 #273

Closed ssi02014 closed 1 week ago

ssi02014 commented 1 week ago

Overview

cc. @Collection50

excludeElements 성능 개선을 위해 인터페이스 및 내부 로직 변경합니다.

매번 리소스가 큰 JSON.stringify를 하는 것은 불 필요합니다. 필요한 경우 3번째 인자로 iteratee 함수를 넣는 방향으로 변경합니다. 이를 통해, 사용자가 제거 할 요소를 자유롭게결정 할 수 있으며, 성능도 개선 할 수 있습니다.

또한, 이런 변화를 통해 2번째 인자는 앞으로 배열을 넣어줘야 합니다.

원시타입 배열

excludeElements([1, 2, 3, 4, 5, 6], [1, 3]); // [2, 4, 5, 6]

프로퍼티 접근

const people = [
  { name: 'kim', address: { city: 'Seoul' } },
  { name: 'lee', address: { city: 'NewYork' } },
  { name: 'kim', address: { city: 'Seoul' } },
];

excludeElements(
  people,
  [{ name: 'kim', address: { city: 'Seoul' } }],
  (item) => item.name
);
// name으로 판단
// [{ name: 'lee', address: { city: 'NewYork' } }]

JSON.stringify 사용

const array = [
  [3, 'a'],
  [4, 'b'],
  [3, 'a'],
];
const excludedElements = [3, 'a'];

excludeElements(array, [excludedElements], (item) => JSON.stringify(item));
// [[4, 'b']]

PR Checklist

changeset-bot[bot] commented 1 week ago

🦋 Changeset detected

Latest commit: eaa7617899e5b013d4a590993152ca2cbe69172d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ----------------- | ----- | | @modern-kit/utils | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

codecov[bot] commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.82%. Comparing base (2689590) to head (0397ae4).

:exclamation: Current head 0397ae4 differs from pull request most recent head eaa7617

Please upload reports for the commit eaa7617 to get more accurate results.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/modern-agile-team/modern-kit/pull/273/graphs/tree.svg?width=650&height=150&src=pr&token=HSFRRRH8Q3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=modern-agile-team)](https://app.codecov.io/gh/modern-agile-team/modern-kit/pull/273?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=modern-agile-team) ```diff @@ Coverage Diff @@ ## main #273 +/- ## ======================================= Coverage 96.81% 96.82% ======================================= Files 115 115 Lines 1226 1227 +1 Branches 302 303 +1 ======================================= + Hits 1187 1188 +1 Misses 33 33 Partials 6 6 ``` | [Components](https://app.codecov.io/gh/modern-agile-team/modern-kit/pull/273/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=modern-agile-team) | Coverage Δ | | |---|---|---| | [@modern-kit/react](https://app.codecov.io/gh/modern-agile-team/modern-kit/pull/273/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=modern-agile-team) | `94.34% <ø> (ø)` | | | [@modern-kit/utils](https://app.codecov.io/gh/modern-agile-team/modern-kit/pull/273/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=modern-agile-team) | `100.00% <100.00%> (ø)` | |