Skip to content

[7팀 이지은] Chapter 2-2. 디자인 패턴과 함수형 프로그래밍#52

Open
zlrlo wants to merge 20 commits intohanghae-plus:mainfrom
zlrlo:main
Open

[7팀 이지은] Chapter 2-2. 디자인 패턴과 함수형 프로그래밍#52
zlrlo wants to merge 20 commits intohanghae-plus:mainfrom
zlrlo:main

Conversation

@zlrlo
Copy link

@zlrlo zlrlo commented Apr 24, 2025

과제의 핵심취지

  • React의 hook 이해하기
  • 함수형 프로그래밍에 대한 이해
  • 액션과 순수함수의 분리

과제에서 꼭 알아가길 바라는 점

  • 엔티티를 다루는 상태와 그렇지 않은 상태 - cart, isCartFull vs isShowPopup
  • 엔티티를 다루는 컴포넌트와 훅 - CartItemView, useCart(), useProduct()
  • 엔티티를 다루지 않는 컴포넌트와 훅 - Button, useRoute, useEvent 등
  • 엔티티를 다루는 함수와 그렇지 않은 함수 - calculateCartTotal(cart) vs capaitalize(str)

기본과제

  • Component에서 비즈니스 로직을 분리하기

  • 비즈니스 로직에서 특정 엔티티만 다루는 계산을 분리하기

  • 뷰데이터와 엔티티데이터의 분리에 대한 이해

  • entities -> features -> UI 계층에 대한 이해

  • Component에서 사용되는 Data가 아닌 로직들은 hook으로 옮겨졌나요?

  • 주어진 hook의 책임에 맞도록 코드가 분리가 되었나요?

useCoupon, useProduct hook 코드를 작성하였고, 각각의 hook은 CouponProvider, ProductProvider에서 사용하였습니다.

  • 계산함수는 순수함수로 작성이 되었나요?

entities > cart > lib 경로에 cart entity에 필요한 계산 함수를 작성하였습니다.
getAppliedDiscount, calculateItemTotal, getMaxApplicableDiscount, calculateCartTotal, updateCartItemQuantity

  • 특정 Entitiy만 다루는 함수는 분리되어 있나요?

  • 특정 Entitiy만 다루는 Component와 UI를 다루는 Component는 분리되어 있나요?

  • 데이터 흐름에 맞는 계층구조를 이루고 의존성이 맞게 작성이 되었나요?

최대한 fsd 아키텍처 구조로 만들어보려고 노력했습니다.
의존성은 pages - widgets - features - entities - shared 로 관리하였습니다.

심화과제

  • 재사용 가능한 Custom UI 컴포넌트를 만들어 보기
  • 재사용 가능한 Custom 라이브러리 Hook을 만들어 보기
  • 재사용 가능한 Custom 유틸 함수를 만들어 보기
  • 그래서 엔티티와는 어떤 다른 계층적 특징을 가지는지 이해하기

심화 과제는 진행하지 못했습니다.

  • UI 컴포넌트 계층과 엔티티 컴포넌트의 계층의 성격이 다르다는 것을 이해하고 적용했는가?
  • 엔티티 Hook과 라이브러리 훅과의 계층의 성격이 다르다는 것을 이해하고 적용했는가?
  • 엔티티 순수함수와 유틸리티 함수의 계층의 성격이 다르다는 것을 이해하고 적용했는가?

과제 셀프회고

과제를 하면서 내가 제일 신경 쓴 부분은 무엇인가요?

fsd 아키텍처를 적용해보려고 노력했습니다.

과제를 다시 해보면 더 잘 할 수 있었겠다 아쉬운 점이 있다면 무엇인가요?

리뷰 받고 싶은 내용이나 궁금한 것에 대한 질문 편하게 남겨주세요 :)

리뷰 받고 싶은 내용이나 궁금한 것에 대한 질문

FSD 구조에 맞게 폴더를 구성한 부분에 대해 리뷰해주시면 감사하겠습니다.

Copy link

@keyonnaise keyonnaise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지은님, 구직 활동과 항해를 병행하시느라 정말 정신없이 바쁘셨을 텐데, 그럼에도 불구하고 이렇게 많이 과제를 진행하신 것을 보니 정말 대단하시다는 생각이 듭니다! 우리 취뽀 성공해요!!

Comment on lines +17 to +29
<ProductProvider>
<CouponProvider>
<main className="container mx-auto mt-6">
{isAdmin ? (
<AdminPage />
) : (
<CartProvider>
<CartPage />
</CartProvider>
)}
</main>
</CouponProvider>
</ProductProvider>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오프 코치님께서는 권장하지 않으셨지만, 저는 컨텍스트 헬 문제를 해결하기 위해 다음과 같은 방법을 시도해 보았습니다.

The React Context hell
제가 구현한 코드

관심 있으시면 한번 살펴보시고 의견 나눠주시면 감사하겠습니다!

Comment on lines +29 to +35
<input
type="text"
placeholder="쿠폰 이름"
value={newCoupon.name}
onChange={(e) => setNewCoupon({ ...newCoupon, name: e.target.value })}
className="w-full p-2 border rounded"
/>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러 인풋 요소들에서 동일한 클래스 명들이 반복적으로 사용되고 있어요. 이러한 인풋 요소들을 하나의 공통된 컴포넌트로 만들어 재사용하면 클래스 명을 중복해서 작성하는 수고를 줄이고, 코드의 일관성을 높일 수 있을 것 같습니다!


// 새로운 핸들러 함수 추가
const handleProductNameUpdate = (productId: string, newName: string) => {
if (editingProduct && editingProduct.id === productId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

동일한 조건식이 여러 군데에서 반복적으로 사용되고 있는 것 같습니다. 이 조건식을 상위 스코프에 변수로 저장해두고 사용하면 코드가 훨씬 간결해지고 통일성도 높아질 것 같아요!

Comment on lines +11 to +16
const [newProduct, setNewProduct] = useState<Omit<Product, 'id'>>({
name: '',
price: 0,
stock: 0,
discounts: [],
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

초기값을 상수로 따로 분리하거나, 초기화만을 담당하는 별도의 함수로 관리하면 다른 곳에서 재사용하기도 편리해질 것 같습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants